This pull request builds on guard-cucumber to allow developers to dynamically focus on specific scenarios in their Cucumber feature files. This has made working with specific Cucumber scenarios a lot easier for me.
Focusing on cucumber scenarios is already easy
Say i’m working on a “User Management” feature. It lives in features/user_management.feature. It includes a variety of user scenarios, but the ones I want to test in particular are about how users invite each other to the app.
Right now I can do this by specifying a tag to focus on in the guard-cucumber initializer in my Guardfile. Like so:
guard 'cucumber', :cli => ‘—tags @focus’
And then I put @focus above every invitation scenario that I want to focus on:
@focus
Scenario: The user invites someone else
Given ...
That’s great, now cucumber will only test the scenarios where one user invites another to the system. That was easy.
But dynamically adjusting the focus is hard
Now i’m done testing invitations and I want to be sure that the rest of my “User Management” scenarios are working. I delete my focus tags from the user_management.feature file. Then I save the file, expecting guard-cucumber to run all the scenarios.
Nothing happens, no tests run. If I want to run all my tests again, I have to:
edit the focus tags in my user_management.feature file
jump back to my Guardfile
remove the cucumber —tag option in the guard-cucumber initializer.
restart guard
jump back to my feature file
save the feature to run tests again
What if I want to focus on a different subset of scenarios? I have to repeat all the steps above.
The pull request makes dynamic focusing easier
This pull request aims to remove steps 2-5 from this process. It does this by allowing the user to tell guard-cucumber which tag to focus on, like so:
guard 'cucumber', :focus_on => ‘focus’
When guard-cucumber sees that the focus_on key has a value, it focuses on scenarios tagged with that value. (@focus, in this example). If @focus was found, it updates the feature file’s path using the standard cucumber notation. Then it hands off that updated path to cucumber. For example, if @focus was found on line 6:
cucumber user_management.feature:6
would eventually run. If the user removes the @focus tag from the file (in order to run all scenarios) then guard-cucumber will run all scenarios in that file.
Who Cares
People who use rspec can dynamically focus on tests using the:focus symbol. You add the symbol to a specific test, and it will run that test only. You remove the symbol and all tests run. These guys requested something like this in the cucumber mailing list.
Thanks, this has made testing and development much smoother for me lately, especially when i’m working with cucumber tests.
What a perfect timing! After not using Cucumber on my previous projects, I just introduced it on the current one and can't wait to use the focus feature in the new year. Thanks a lot for this!
tl;dr
This pull request builds on
guard-cucumber
to allow developers to dynamically focus on specific scenarios in their Cucumber feature files. This has made working with specific Cucumber scenarios a lot easier for me.Focusing on cucumber scenarios is already easy
Say i’m working on a “User Management” feature. It lives in
features/user_management.feature
. It includes a variety of user scenarios, but the ones I want to test in particular are about how users invite each other to the app.Right now I can do this by specifying a tag to focus on in the
guard-cucumber
initializer in my Guardfile. Like so:guard 'cucumber', :cli => ‘—tags @focus’
And then I put
@focus
above every invitation scenario that I want to focus on:That’s great, now cucumber will only test the scenarios where one user invites another to the system. That was easy.
But dynamically adjusting the focus is hard
Now i’m done testing invitations and I want to be sure that the rest of my “User Management” scenarios are working. I delete my focus tags from the
user_management.feature
file. Then I save the file, expectingguard-cucumber
to run all the scenarios.Nothing happens, no tests run. If I want to run all my tests again, I have to:
user_management.feature
fileGuardfile
—tag
option in theguard-cucumber
initializer.feature
to run tests againWhat if I want to focus on a different subset of scenarios? I have to repeat all the steps above.
The pull request makes dynamic focusing easier
This pull request aims to remove steps 2-5 from this process. It does this by allowing the user to tell
guard-cucumber
which tag to focus on, like so:guard 'cucumber', :focus_on => ‘focus’
When
guard-cucumber
sees that thefocus_on
key has a value, it focuses on scenarios tagged with that value. (@focus
, in this example). If@focus
was found, it updates the feature file’s path using the standard cucumber notation. Then it hands off that updated path to cucumber. For example, if@focus
was found on line 6:cucumber user_management.feature:6
would eventually run. If the user removes the
@focus
tag from the file (in order to run all scenarios) thenguard-cucumber
will run all scenarios in that file.Who Cares
People who use rspec can dynamically focus on tests using the
:focus
symbol. You add the symbol to a specific test, and it will run that test only. You remove the symbol and all tests run. These guys requested something like this in the cucumber mailing list.Thanks, this has made testing and development much smoother for me lately, especially when i’m working with cucumber tests.