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
Add config.when_first_matching_example_defined
.
#2175
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
70 changes: 70 additions & 0 deletions
70
features/hooks/when_first_matching_example_defined.feature
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
Feature: `when_first_matching_example_defined` hook | ||
|
||
In large projects that use RSpec, it's common to have some expensive setup logic | ||
that is only needed when certain kinds of specs have been loaded. If that kind of | ||
spec has not been loaded, you'd prefer to avoid the cost of doing the setup. | ||
|
||
The `when_first_matching_example_defined` hook makes it easy to conditionally | ||
perform some logic when the first example is defined with matching metadata, | ||
allowing you to ensure the necessary setup is performed only when needed. | ||
|
||
Background: | ||
Given a file named "spec/spec_helper.rb" with: | ||
"""ruby | ||
RSpec.configure do |config| | ||
config.when_first_matching_example_defined(:db) do | ||
require "support/db" | ||
end | ||
end | ||
""" | ||
And a file named "spec/support/db.rb" with: | ||
"""ruby | ||
RSpec.configure do |config| | ||
config.before(:suite) do | ||
puts "Bootstrapped the DB." | ||
end | ||
config.around(:example, :db) do |example| | ||
puts "Starting a DB transaction." | ||
example.run | ||
puts "Rolling back a DB transaction." | ||
end | ||
end | ||
""" | ||
And a file named ".rspec" with: | ||
""" | ||
--require spec_helper | ||
""" | ||
And a file named "spec/unit_spec.rb" with: | ||
""" | ||
RSpec.describe "A unit spec" do | ||
it "does not require a database" do | ||
puts "in unit example" | ||
end | ||
end | ||
""" | ||
And a file named "spec/integration_spec.rb" with: | ||
""" | ||
RSpec.describe "An integration spec", :db do | ||
it "requires a database" do | ||
puts "in integration example" | ||
end | ||
end | ||
""" | ||
|
||
Scenario: Running the entire suite loads the DB setup | ||
When I run `rspec` | ||
Then it should pass with: | ||
""" | ||
Bootstrapped the DB. | ||
Starting a DB transaction. | ||
in integration example | ||
Rolling back a DB transaction. | ||
.in unit example | ||
. | ||
""" | ||
|
||
Scenario: Running just the unit spec does not load the DB setup | ||
When I run `rspec spec/unit_spec.rb` | ||
Then the examples should all pass | ||
And the output should not contain "DB" |
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
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
Oops, something went wrong.
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.
s/
childeren
/children
/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.
Cleaned it up post merge :)
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.
Thanks :).