Tag Archives: Cucumber

Using Instance Variables with Cucumber Steps

I was recently helping a developer test a feature using cucumber.  He was using mostly webrat steps and basic Rails features like dynamic finder methods. He knew that he could use local variables in steps but didn’t know he could use instance variables to simplify the process of finding all of the objects he needed to test.

Let’s say you need to test for a value that you store in the database but you can not find on any page in your application. Perhaps you needed to have setup several users and test that one particular user has a valid internal GUID set on it.  You could just select the user into a local variable by a known label to test it.

Posted in Uncategorized | Tagged , , , , , | 4 Comments

Creating a Reusable Dictionary of Steps in Cucumber

Corey and I have been using Cucumber to write our integration tests on our current project and I thought I’d share a tip with you that has made our lives so much easier. When making steps in Cucumber, try to make them reusable. The idea behind Cucmber’s integration tests is that you are creating a language to talk about (and test) your project. By creating a dictionary of reusable steps we cut down the amount of time it takes to write new features, and decrease the size of the testing language which makes it easier to wrap your head around it. Here is a sample step definition that could be used to check for various http response codes

Posted in agile development, Cucumber, ruby, rubyonrails | Tagged , , , , , , , , | Leave a comment