This repository was archived by the owner on Nov 30, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 753
Make rspec-expectations and rspec-mocks APIs available in before(:suite)
hooks
#1986
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,30 @@ module RSpec::Core | |
}.to raise_error(ZeroDivisionError) | ||
end | ||
|
||
it 'runs in the context of an example group' do | ||
run_context = nil | ||
RSpec.configuration.__send__(registration_method, :suite) { run_context = self } | ||
RSpec.configuration.with_suite_hooks { } | ||
expect(run_context).to be_a ExampleGroup | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's worth adding some lines to this (or perhaps making a new spec) showing that rspec-mocks and rspec-expectations APIs can be used from within the hook. Ultimately that's the bug we're trying to fix. l think that as rspec-core currently works, any block evaluated in the context of an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See below :) |
||
|
||
it 'allows access to rspec-mocks methods within the hook' do | ||
run = false | ||
RSpec.configuration.__send__(registration_method, :suite) do | ||
RSpec::Mocks.with_temporary_scope { double('something') } | ||
run = true | ||
end | ||
RSpec.configuration.with_suite_hooks { } | ||
expect(run).to be true | ||
end | ||
|
||
it 'allows access to rspec-expectation methods within the hook' do | ||
RSpec.configuration.__send__(registration_method, :suite) { expect(true).to be false } | ||
expect { | ||
RSpec.configuration.with_suite_hooks { } | ||
}.to raise_error RSpec::Expectations::ExpectationNotMetError | ||
end | ||
|
||
context "registered on an example group" do | ||
it "is ignored with a clear warning" do | ||
sequence = [] | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Friends" implies plural but it's really just
after(:suite)
, right? Might as well say:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, technically they are run in the context of an instance of an example group, not an example group. Users are often confused by this so it's helpful if we're accurate in our changelog entries :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would still require the user calling
with_temporary_scope
before being able to use mocks correct?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It's explicitly documented that that's required if you ever want to use rspec-mocks outside the scope of a single example:
https://relishapp.com/rspec/rspec-mocks/v/3-3/docs/basics/scope
This bug fix doesn't affect
with_temporary_scope
in any way.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 😸
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are multiple (
before
,after
,prepend_before
,append_before
,prepend_after
,append_after
) but I'll change it if you prefer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
huh, I forgot about those.
It's fine how it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the example group vs instance of the example group thing still matters, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I always do too, but I was reminded by the spec file :) (it loops through all of them)