-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simulate and test the situation when some dependency is required via …
…an entrypoint in symlinked folder
- Loading branch information
1 parent
7869360
commit e1c9e1d
Showing
9 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "vendor/gems/operations/operations" | ||
|
||
class Calculator | ||
def initialize | ||
@adder = Add.new | ||
@subtractor = Subtract.new | ||
@multiplier = Multiply.new | ||
@divider = Divide.new | ||
end | ||
|
||
def add(a, b) | ||
@adder.call(a, b) | ||
end | ||
|
||
def subtract(a, b) | ||
@subtractor.call(a, b) | ||
end | ||
|
||
def multiply(a, b) | ||
@multiplier.call(a, b) | ||
end | ||
|
||
def divide(a, b) | ||
@divider.call(a, b) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class Add | ||
def call(a, b) | ||
a + b | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative "helpers/calculator_logger" | ||
|
||
class Divide | ||
prepend CalculatorLogger | ||
|
||
def call(a, b) | ||
a / b | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
spec/ddcov/calculator_with_symlinks/operations/helpers/calculator_logger.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# frozen_string_literal: true | ||
|
||
module CalculatorLogger | ||
def call(a, b) | ||
res = super | ||
|
||
@log ||= [] | ||
@log << "operation performed" | ||
|
||
res | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class Multiply | ||
def call(a, b) | ||
a * b | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
require_relative "add" | ||
require_relative "divide" | ||
require_relative "multiply" | ||
require_relative "subtract" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class Subtract | ||
def call(a, b) | ||
a - b | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/Users/andrey.marchenko/p/datadog-ci-rb/spec/ddcov/calculator_with_symlinks/operations |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
require "datadog_cov.#{RUBY_VERSION}_#{RUBY_PLATFORM}" | ||
|
||
require_relative "calculator_with_symlinks/calculator" | ||
|
||
RSpec.describe Datadog::CI::ITR::Coverage::DDCov do | ||
def absolute_path(path) | ||
File.expand_path(File.join(__dir__, path)) | ||
end | ||
|
||
subject { described_class.new(root: root) } | ||
|
||
describe "code coverage collection" do | ||
let!(:calculator) { Calculator.new } | ||
|
||
context "when root is the calculator project dir" do | ||
let(:root) { absolute_path("calculator_with_symlinks") } | ||
|
||
it "collects code coverage including Calculator and operations" do | ||
subject.start | ||
|
||
expect(calculator.add(1, 2)).to eq(3) | ||
expect(calculator.subtract(1, 2)).to eq(-1) | ||
|
||
coverage = subject.stop | ||
|
||
expect(coverage.size).to eq(3) | ||
expect(coverage.keys).to include( | ||
absolute_path("calculator_with_symlinks/calculator.rb"), | ||
absolute_path("calculator_with_symlinks/operations/add.rb"), | ||
absolute_path("calculator_with_symlinks/operations/subtract.rb") | ||
) | ||
end | ||
end | ||
end | ||
end |