Skip to content

Commit

Permalink
Merge pull request #111 from cucumber/equality-for-test-cases
Browse files Browse the repository at this point in the history
Implement equality for test cases
  • Loading branch information
danascheider committed Jul 30, 2016
2 parents 8ef0027 + 925b3f3 commit 97bf84a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
12 changes: 12 additions & 0 deletions lib/cucumber/core/test/case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ def feature
source.first
end

def hash
location.hash
end

def eql?(other)
other.hash == hash
end

def ==(other)
eql?(other)
end

private

def compose_around_hooks(visitor, *args, &block)
Expand Down
27 changes: 25 additions & 2 deletions spec/cucumber/core/test/case_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module Test
include Core::Gherkin::Writer

let(:test_case) { Test::Case.new(test_steps, [feature, scenario]) }
let(:feature) { double }
let(:scenario) { double }
let(:feature) { double(location: "features/test.feature:1") }
let(:scenario) { double(location: "features/test.feature:2") }
let(:test_steps) { [double, double] }

context 'describing itself' do
Expand Down Expand Up @@ -233,6 +233,29 @@ module Test
end
end

describe "equality" do
it "is equal to another test case at the same location" do
gherkin = gherkin('features/foo.feature') do
feature do
scenario do
step
end
end
end
test_case_instances = []
receiver = double.as_null_object
allow(receiver).to receive(:test_case) do |test_case|
test_case_instances << test_case
end
2.times { compile([gherkin], receiver) }
expect(test_case_instances.length).to eq 2
expect(test_case_instances.uniq.length).to eq 1
expect(test_case_instances[0]).to be_eql test_case_instances[1]
expect(test_case_instances[0]).to eq test_case_instances[1]
expect(test_case_instances[0]).not_to equal test_case_instances[1]
end
end

end
end
end
Expand Down
7 changes: 4 additions & 3 deletions spec/cucumber/core/test/runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,10 @@ module Cucumber::Core::Test
let(:test_cases) { [first_test_case, last_test_case] }

it 'reports the results correctly for the following test case' do
expect(event_bus).to receive(:test_case_finished).with(last_test_case, anything) do |reported_test_case, result|
expect( result ).to be_passed
end
expect(event_bus).to receive(:test_case_finished) { |reported_test_case, result|
expect(result).to be_failed if reported_test_case.equal?(first_test_case)
expect(result).to be_passed if reported_test_case.equal?(last_test_case)
}.twice

test_cases.each { |c| c.describe_to runner }
end
Expand Down

0 comments on commit 97bf84a

Please sign in to comment.