Search code examples
ruby-on-rails-3cucumberwebrat

Cucumber/Webrat: Provide params to GET request


I am using cucumber to write features for a new ruby on rails application. This is my first time using either tool, and I'm trying to figure out how to send parameters to the request with the webrat visit() function.

I would like to have a step like the following:

Given I am on the user details page for user "32"

This should send the test to http://example.com/user/32

I know how to visit just the users_path page with webrat, but I can't figure out how to send the additional parameters along with it.


Solution

  • Take a look in ./features/support/paths.rb. This contains the mappings that Webrat will use to match the paths in your features. For example, /the home page/ maps to the string '/'. You can add your own mappings and use a regexp to pull out any needed parameters. Eg. (from the standard paths.rb):

    when /^(.*)'s profile page$/i
      user_profile_path(User.find_by_login($1))