-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only run feature hooks for features that will actually be run (#209)
* feature hooks only execute if the feature would run given the tags Previously, all feature hooks were executing no matter what tags were provided. Files + line numbers didn't have this behavior; they actually resulted in only some feature hooks running. Now, we only run a feature (and therefore it's hooks) if, for any of its scenarios, the combination of that feature's tags and that scenario's tags matches the run's tags. This required changes to setup in some Runner tests, as Feature instances with no associated Scenario instances can't be included in a Runner run (because they have no Scenarios to match against). * clarify documentation on filtering runs with tags * fix typos --------- Co-authored-by: Oriol Gual <oriolgual@users.noreply.github.com>
- Loading branch information
1 parent
0946544
commit e5f1380
Showing
6 changed files
with
119 additions
and
14 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
Feature: Feature Hooks and Tags | ||
In order to run only the appropriate setup and teardown code | ||
As a developer | ||
I want spinach to only run feature hooks if those features would be run under the tags I provided | ||
|
||
Scenario: No tags specified | ||
Given I have a tagged feature with an untagged scenario | ||
And I have an untagged feature with a tagged scenario | ||
When I don't specify tags | ||
Then all the feature hooks should have run | ||
|
||
Scenario: Tags specified | ||
Given I have a tagged feature with an untagged scenario | ||
And I have an untagged feature with a tagged scenario | ||
When I specify a tag the features and scenarios are tagged with | ||
Then all the feature hooks should have run | ||
|
||
Scenario: Tags excluded | ||
Given I have a tagged feature with an untagged scenario | ||
And I have an untagged feature with a tagged scenario | ||
When I exclude a tag the features and scenarios are tagged with | ||
Then no feature hooks should have run |
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,55 @@ | ||
class Spinach::Features::FeatureHooksAndTags < Spinach::FeatureSteps | ||
include Integration::SpinachRunner | ||
|
||
step 'I have a tagged feature with an untagged scenario' do | ||
write_file 'features/a.feature', <<-FEATURE | ||
@tag | ||
Feature: A | ||
Scenario: A1 | ||
Then a1 | ||
FEATURE | ||
|
||
write_file 'features/steps/a.rb', <<-STEPS | ||
class Spinach::Features::A < Spinach::FeatureSteps | ||
step 'a1' do; end | ||
end | ||
STEPS | ||
end | ||
|
||
step 'I have an untagged feature with a tagged scenario' do | ||
write_file 'features/b.feature', <<-FEATURE | ||
Feature: B | ||
@tag | ||
Scenario: B1 | ||
Then b1 | ||
FEATURE | ||
|
||
write_file 'features/steps/b.rb', <<-STEPS | ||
class Spinach::Features::B < Spinach::FeatureSteps | ||
step 'b1' do; end | ||
end | ||
STEPS | ||
end | ||
|
||
step "I don't specify tags" do | ||
run_spinach | ||
end | ||
|
||
step 'I specify a tag the features and scenarios are tagged with' do | ||
run_spinach({append: "--tags @tag"}) | ||
end | ||
|
||
step 'I exclude a tag the features and scenarios are tagged with' do | ||
run_spinach({append: "--tags ~@tag"}) | ||
end | ||
|
||
step 'all the feature hooks should have run' do | ||
@stdout.must_match("Feature: A") | ||
@stdout.must_match("Feature: B") | ||
end | ||
|
||
step 'no feature hooks should have run' do | ||
@stdout.wont_match("Feature: A") | ||
@stdout.wont_match("Feature: B") | ||
end | ||
end |
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