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

Commit 993b796

Browse files
committed
Refactor: in-line logic from a single-use method.
1 parent 9094876 commit 993b796

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

lib/rspec/core/example.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -340,13 +340,6 @@ def skip_with_exception(reporter, exception)
340340
finish(reporter)
341341
end
342342

343-
# @private
344-
def instance_exec_with_rescue(&block)
345-
@example_group_instance.instance_exec(self, &block)
346-
rescue Exception => e
347-
set_exception(e)
348-
end
349-
350343
# @private
351344
def instance_exec(*args, &block)
352345
@example_group_instance.instance_exec(*args, &block)

lib/rspec/core/hooks.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,9 @@ def run(example)
361361
# @private
362362
class AfterHook < Hook
363363
def run(example)
364-
example.instance_exec_with_rescue(&block)
364+
example.instance_exec(example, &block)
365+
rescue Exception => ex
366+
example.set_exception(ex)
365367
end
366368
end
367369

spec/rspec/core/hooks_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ def hook_collection_for(position, scope)
7474
instance.hooks.run(type, scope, double("Example").as_null_object)
7575
}.not_to yield_control
7676
end
77+
78+
if scope == :example
79+
it "yields the example as an argument to the hook" do
80+
group = RSpec.describe
81+
ex = group.example { }
82+
83+
expect { |p| group.send(type, scope, &p); group.run }.to yield_with_args(ex)
84+
end
85+
end
7786
end
7887
end
7988
end

0 commit comments

Comments
 (0)