31 December, 2012

cucumber disambiguation, or... survival tip for a noob in an existing rails project

I've just jumped into an existing rails project at work. The existing team is using the hell out of BDD/TDD. While I'm super excited to get there with them, I struggled HUGE with the fact that their features and steps have been heavily optimized and DRYed out. To grok the project and the methodology, I was trying to jump from feature to step and because they've been working with this for a while, they have organized source around DRY, not around readability and discoverability. As such, I was stumbling around trying to figure out where the hell each of the step definitions were for the features I was reading.

I finally stumbled upon the right incantation of cucumber options to get what i needed:


bundle exec cucumber -o cuke.out --format stepdefs features 


If you want to do all features. However, if you just want to discover the feature-step relationships for a specific feature:


bundle exec cucumber -o cuke.out --format stepdefs features/specific_feature_file.feature


Will produce output like this:

5.1738260 /^I am logged in as a valid user$/
   # features/step_definitions/authentication_steps.rb:100
2.6341953 /^(?:|I )go to (.+)$/
   # features/step_definitions/web_steps.rb:48
2.1448050 /^I should be able to visit the admin area$/
   # features/step_definitions/admin/admin_steps.rb:5
1.2116820 /^I am logged in as an admin$/
   # features/step_definitions/authentication_steps.rb:106
0.7382180 /^I am logged in as an uber admin$/
   # features/step_definitions/authentication_steps.rb:118
0.1408770 /^I should see the Contacts\/New Contacts page$/
   # features/step_definitions/marketing/contact_list_steps.rb:1
0.0094120 /^(?:|I )should not see "([^"]*)"$/
   # features/step_definitions/web_steps.rb:123
0.0092010 /^(?:|I )should see "([^"]*)"$/
   # features/step_definitions/web_steps.rb:105


Now, you can tell where the f-uh-uh-uh-uke, fuke... er... cuke the implementation is. Odds are, a team who's been doing this for a while have shut off step output because they know the project like the back of their hand, but something like this will help a noob like you get up to speed in an existing project. Well, it helped me and it took a while to find the right search terms to give me what I needed. Oh, also, the output file was a huge help because the number of NOT MATCHED BY ANY STEPS lines in the project blew the useful stuff right out of my iTerm's scroll history.

Good luck...

Now, I'm thinking of writing a vim plugin that will use this output to create a ctags like file that will allow you to jump around from feature to step regardless of what your file naming conventions are. 



No comments: