Cucumber::ArityMismatchError error after Transform

2019-08-10 08:31发布

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 "ca@example.org"

I am getting this error

And user "ca@example.org" has security role "contact"     # features/step_definitions/security_role_steps.rb:14
    And login as user "ca@example.org"                        # 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 "ca@example.org"'

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

1条回答
家丑人穷心不美
2楼-- · 2019-08-10 09:16

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
查看更多
登录 后发表回答