views:

21

answers:

1

my step definition

Transform /^user "([^"]*)"$/ do | email |
  Person.find_by_email(email)
end

Given /^login as (user "([^"]*)")$/ do | user |
  login_as email
end

my feature

login as user "[email protected]"

I am getting this error

And user "[email protected]" has security role "contact"     # features/step_definitions/security_role_steps.rb:14
    And login as user "[email protected]"                        # features/step_definitions/security_role_steps.rb:10
      Your block takes 1 argument, but the Regexp matched 2 arguments. (Cucumber::ArityMismatchError)
      features/step_definitions/security_role_steps.rb:10:in `/^login as (user "([^"]*)")$/'
      ./vendor/plugins/shway_skeletons/lib/shway_skeletons.rb:94:in `send':in `/^login as (user "([^"]*)")$/'
      features/manage_security_roles.feature:14:in `And login as user "[email protected]"'

I am unable to figure out can anybody explain what was wrong with my cucumber transform.

+1  A: 

This is because the parentheses around ( user "([^"]*)" ) are capturing a group, then the actual email is capturing another one. to prevent that, use a non-capturing group, or don't group at all.

Given /^login as user "([^"]*)"$/ do | user |
  login_as email
end

or

Given /^login as (?:user "([^"]*)")$/ do | user |
  login_as email
end
Chubas