Calling nested steps with placeholders

51 views
Skip to first unread message

Eric M.

unread,
Sep 29, 2012, 7:52:44 PM9/29/12
to ruby-...@googlegroups.com
I have two questions related to the following steps:

1. I've read the documentation and thought that arguments could be passed in quoted or not quoted.  I'm unable to pass in "email_password" in the last step unless it is quoted.  Is there some specific to define in the step to have this behavior?  It seems to work fine when I pass in an unquoted parameter to a defined placeholder.

2. I have the last step working by calling step and interpolating the string for the variable.  It does not seem possible to do this with the send method as the placeholder for :credential is bypassed?  Is there any way to change email_password to :credential to take advantage of the placeholder I defined and past that along to the steps?

step "I registered as admin :credentials" do |credentials|
  create(:user, :admin, email: credentials[:email], password: credentials[:password])
end

step "I login as :credentials" do |credentials|
  visit login_path

  fill_in 'Email',    :with => credentials[:email]
  fill_in 'Password', :with => credentials[:password]

  click_button 'Login'
end

step "I am logged in as admin :email_password" do |email_password|
  send "I registered as admin :credentials", email_password
  send "I login as :credentials", email_password
  # step "I registered as admin #{email_password}"
  # step "I login as #{email_password}"
end

Thanks,
Eric

Jonas Nicklas

unread,
Sep 29, 2012, 9:02:36 PM9/29/12
to ruby-...@googlegroups.com
If you use "send", the placeholder is not resolved, so you need to
send in the argument the same way that it would have been after being
transformed by the placeholder, if that makes sense. You can only use
unquoted strings as placeholders if they contain only word characters,
they can't contain spaces for example, maybe that is the problem?

/Jonas

Jonas Nicklas

unread,
Sep 29, 2012, 9:03:32 PM9/29/12
to ruby-...@googlegroups.com
You could have used the same placeholder in the last example and then
used "send" and sent the block argument straight through. I think that
should have worked.

/Jonas

Eric M.

unread,
Sep 29, 2012, 10:28:33 PM9/29/12
to ruby-...@googlegroups.com
I was passing in an unquoted email address, so the @ and . would be the culprits here.  I'm curious the reason for the restriction.

Eric M.

unread,
Sep 29, 2012, 10:29:30 PM9/29/12
to ruby-...@googlegroups.com


On Saturday, September 29, 2012 9:03:53 PM UTC-4, jnicklas wrote:
You could have used the same placeholder in the last example and then
used "send" and sent the block argument straight through. I think that
should have worked.


This worked and is the solution I went with.  Thanks.
Reply all
Reply to author
Forward
0 new messages