Search code examples
ruby-on-railscucumberbdd

Writing steps the Cucumber way


I am new to Cucumber (using with Rails 2.3.11 and webrat) and I am having a hard time learning the methods/syntax that I should be using when I write my steps.

My feature files use natural language, but my step files look a lot like a Test::Unit test.

I cannot find an exhaustive list of the useful methods made available to me by Cucumber and its pre-requisites.

I cannot find out the difference between traditional methods from Test::Unit, etc. compared to the Cucumber methods.

Example:

  • what is the difference between get and visit ?

    EDIT - I found the visit method in the webrat RDoc files. It looks like you cannot pass a cookie hash with visit as you can with get. But this example is still valid as it shows the kind of problem I am running into when trying to learn Cucumber.

My fear is that my step files will be ugly to read (even if they get the job done) and that there is a much prettier syntax that I could use while achieving the same test coverage.


Solution

  • Get/visit are both webrat conventions, not Cucumber, so it sounds like the Webrat RDoc might help you out there.

    As far as your step files looking ugly, it's ok if they start that way but once they are working you can clean them up as you learn. For instance, Page Object modeling allows you to add another level of abstraction to your steps. Here are some articles to get you started: