-
-
Notifications
You must be signed in to change notification settings - Fork 764
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
My reasoning is: rspec-rails needs to do the following condition: `if RSpec.current_scope == :before_context_hook` test_prof needs to do the following condition: `if RSpec.current_scope == :before_context_hook` amd my little helper needs the following `unless [:before_example_hook, :example].include?(RSpec.current_scope)`
- Loading branch information
Showing
8 changed files
with
133 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,84 @@ | ||
Feature: RSpec provides the current_scope as RSpec::current_scope | ||
|
||
You can detect which rspec scope your helper methods or library code is executing in. | ||
This is useful if for example, your method only makes sense to call in a certain context. | ||
|
||
Scenario: Detecting the current scope | ||
Given a file named "current_scope_spec.rb" with: | ||
"""ruby | ||
unless RSpec.current_scope == :suite | ||
raise "bad current scope: #{RSpec.current_scope.inspect}" | ||
end | ||
RSpec.configure do |c| | ||
c.before :suite do | ||
expect(RSpec.current_scope).to eq(:before_suite_hook) | ||
end | ||
c.before :context do | ||
expect(RSpec.current_scope).to eq(:before_context_hook) | ||
end | ||
c.before :example do | ||
expect(RSpec.current_scope).to eq(:before_example_hook) | ||
end | ||
c.around :example do |ex| | ||
expect(RSpec.current_scope).to eq(:before_example_hook) | ||
ex.run | ||
expect(RSpec.current_scope).to eq(:after_example_hook) | ||
end | ||
c.after :example do | ||
expect(RSpec.current_scope).to eq(:after_example_hook) | ||
end | ||
c.after :context do | ||
expect(RSpec.current_scope).to eq(:after_context_hook) | ||
end | ||
c.after :suite do | ||
expect(RSpec.current_scope).to eq(:after_suite_hook) | ||
end | ||
end | ||
RSpec.describe "RSpec.current_scope" do | ||
before :context do | ||
expect(RSpec.current_scope).to eq(:before_context_hook) | ||
end | ||
before :example do | ||
expect(RSpec.current_scope).to eq(:before_example_hook) | ||
end | ||
around :example do |ex| | ||
expect(RSpec.current_scope).to eq(:before_example_hook) | ||
ex.run | ||
expect(RSpec.current_scope).to eq(:after_example_hook) | ||
end | ||
after :example do | ||
expect(RSpec.current_scope).to eq(:after_example_hook) | ||
end | ||
after :context do | ||
expect(RSpec.current_scope).to eq(:after_context_hook) | ||
end | ||
it "is :example in an example" do | ||
expect(RSpec.current_scope).to eq(:example) | ||
end | ||
it "works for multiple examples" do | ||
expect(RSpec.current_scope).to eq(:example) | ||
end | ||
describe "in nested describe blocks" do | ||
it "still works" do | ||
expect(RSpec.current_scope).to eq(:example) | ||
end | ||
end | ||
end | ||
""" | ||
When I run `rspec current_scope_spec.rb` | ||
Then the examples should all pass |
This file contains 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 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 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 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 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