Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Commit e880a40

Browse files
Fix block support in example.duplicate_with
Update spec to verify block exists in cloned example
1 parent 7ef58fa commit e880a40

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/rspec/core/example.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,10 @@ def duplicate_with(metadata_overrides={})
138138

139139
# don't clone the example group because the new example
140140
# must belong to the same example group (not a clone).
141+
#
142+
# block is nil in new_metadata so we have to get it from metadata.
141143
Example.new(example_group, description.clone,
142-
new_metadata, new_metadata[:block])
144+
new_metadata, metadata[:block])
143145
end
144146

145147
# @private

spec/rspec/core/example_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,17 @@ def metadata_hash(*args)
8484

8585
describe '#duplicate_with' do
8686
it 'successfully duplicates an example' do
87-
example = example_group.example { raise 'first' }
87+
error_string = 'first'
88+
example = example_group.example { raise error_string }
8889
example2 = example.duplicate_with({ :custom_key => :custom_value })
8990

9091
# ensure metadata is unique for each example
9192
expect(example.metadata.object_id).to_not eq(example2.metadata.object_id)
9293
expect(example.metadata[:custom_key]).to eq(nil)
94+
expect(&example.metadata[:block]).to raise_error(error_string)
95+
9396
expect(example2.metadata[:custom_key]).to eq(:custom_value)
97+
expect(&example2.metadata[:block]).to raise_error(error_string)
9498

9599
# cloned examples must have unique ids
96100
expect(example.id).to_not eq(example2.id)

0 commit comments

Comments
 (0)