Skip to content

Commit d1cde31

Browse files
author
Philippe Hanrigou
committed
Fixing collision in example unique ids (RSpec reports)
1 parent d351fc9 commit d1cde31

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

README.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ Features
3838
* `click 'the_button_id', :wait_for => :element, :element => 'new_element_id'`
3939
* `click 'the_button_id', :wait_for => :no_element, :element => 'disappearing_element_id'`
4040
* `click 'the_button_id', :wait_for => :text, :text => 'New Text'`
41+
* `click 'the_button_id', :wait_for => :text, :element => 'notification_box', :text => 'New Text'`
4142
* `click 'the_button_id', :wait_for => :no_text, :text => 'Disappearing Text'`
43+
* `click 'the_button_id', :wait_for => :no_text, :element => 'notification_box', :text => 'Disappearing Text'`
4244
* `click 'the_button_id', :wait_for => :effects`
4345
* `click 'the_button_id', :wait_for => :condition, :javascript => "some arbitrary javascript expression"`
4446

lib/selenium/rspec/reporting/file_path_strategy.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ def file_path(relative_file_path)
6060
end
6161

6262
def example_hash(example)
63-
Digest::MD5.hexdigest example.backtrace.first
63+
# backtrace is not reliable anymore using the implementation proc
64+
implementation = example.instance_variable_get :'@_implementation'
65+
Digest::MD5.hexdigest implementation.inspect
6466
end
6567

6668
end

test/unit/selenium/rspec/reporting/file_path_strategy_test.rb

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,25 @@
1414
assert_equal File.expand_path("/another/dir"), second_strategy.base_report_dir
1515
end
1616

17-
test "example_hash is distinct when examples first backtrace entry is different" do
17+
test "example_hash is distinct when examples implementation is different" do
1818
strategy = Selenium::RSpec::Reporting::FilePathStrategy.new "report.html"
1919

20-
first_example = stub('example',:backtrace => [ "a", "c" ])
21-
second_example = stub('example',:backtrace => [ "b", "c" ])
20+
first_example = Object.new
21+
first_example.instance_variable_set :'@_implementation', Proc.new {}
22+
second_example = Object.new
23+
second_example.instance_variable_set :'@_implementation', Proc.new {}
24+
2225
assert strategy.example_hash(first_example) != strategy.example_hash(second_example)
2326
end
2427

25-
test "example_hash is the same when examples first backtrace entry is identical" do
28+
test "example_hash is the same when examples implementation is identical" do
2629
strategy = Selenium::RSpec::Reporting::FilePathStrategy.new "report.html"
27-
28-
first_example = stub('example',:backtrace => [ "a", "b" ])
29-
second_example = stub('example',:backtrace => [ "a", "c" ])
30+
31+
same_implementation = Proc.new {}
32+
first_example = Object.new
33+
first_example.instance_variable_set :'@_implementation', same_implementation
34+
second_example = Object.new
35+
second_example.instance_variable_set :'@_implementation', same_implementation
3036
assert_equal strategy.example_hash(first_example),
3137
strategy.example_hash(second_example)
3238
end

0 commit comments

Comments
 (0)