Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guard::Cucumber::Focuser #6

Merged
merged 12 commits into from
Dec 28, 2012
Merged

Guard::Cucumber::Focuser #6

merged 12 commits into from
Dec 28, 2012

Conversation

martco
Copy link

@martco martco commented Dec 28, 2012

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:

@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:

  1. edit the focus tags in my user_management.feature file
  2. jump back to my Guardfile
  3. remove the cucumber —tag option in the guard-cucumber initializer.
  4. restart guard
  5. jump back to my feature file
  6. 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.

netzpirat added a commit that referenced this pull request Dec 28, 2012
Guard::Cucumber::Focuser
@netzpirat netzpirat merged commit 98d6bc2 into guard:master Dec 28, 2012
@netzpirat
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants