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

Commit 45f2cd9

Browse files
committed
Merge pull request #1986 from rspec/run_suite_hooks_in_an_example_group
1 parent ea26891 commit 45f2cd9

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

Changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
### Development
2+
3+
Bug Fixes:
4+
5+
* Correctly run `before(:suite)` (and friends) in the context of an example
6+
group instance, thus making the expected RSpec environment available.
7+
(Jon Rowe, #1986)
8+
19
### 3.3.0 / 2015-06-12
210
[Full Changelog](http://github.com/rspec/rspec-core/compare/v3.2.3...v3.3.0)
311

lib/rspec/core/example.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ def issue_deprecation(_method_name, *_args)
558558
class SuiteHookContext < Example
559559
def initialize
560560
super(AnonymousExampleGroup, "", {})
561+
@example_group_instance = AnonymousExampleGroup.new
561562
end
562563

563564
# rubocop:disable Style/AccessorMethodName

spec/rspec/core/suite_hooks_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,30 @@ module RSpec::Core
2323
}.to raise_error(ZeroDivisionError)
2424
end
2525

26+
it 'runs in the context of an example group' do
27+
run_context = nil
28+
RSpec.configuration.__send__(registration_method, :suite) { run_context = self }
29+
RSpec.configuration.with_suite_hooks { }
30+
expect(run_context).to be_a ExampleGroup
31+
end
32+
33+
it 'allows access to rspec-mocks methods within the hook' do
34+
run = false
35+
RSpec.configuration.__send__(registration_method, :suite) do
36+
RSpec::Mocks.with_temporary_scope { double('something') }
37+
run = true
38+
end
39+
RSpec.configuration.with_suite_hooks { }
40+
expect(run).to be true
41+
end
42+
43+
it 'allows access to rspec-expectation methods within the hook' do
44+
RSpec.configuration.__send__(registration_method, :suite) { expect(true).to be false }
45+
expect {
46+
RSpec.configuration.with_suite_hooks { }
47+
}.to raise_error RSpec::Expectations::ExpectationNotMetError
48+
end
49+
2650
context "registered on an example group" do
2751
it "is ignored with a clear warning" do
2852
sequence = []

0 commit comments

Comments
 (0)