That’s odd. I use the same step in my own scenarios and it works fine.
One problem I did run into is that the label alone isn’t always enough
for webrat to find the input field. The id on the label must match the
id on the labeled field for selection by label to work. Sometimes they
differ, for example, if you use form_for() but don’t call the label
method on the yielded form object, and instead use the label_tag
helper method.
I ran into this just yesterday with one of the views
restful_authentication generates.
It had generated something like this (for a Reviewer model):
<%= label_tag ‘password_confirmation’, ‘Confirm Password’ %>
<%= f.text_field :password_confirmation %>
Which produced HTML like this:
Confirm Password
I changed it to this:
<%= f.label :password_confirmation, “Confirm Password” %>
<%= f.text_field :password_confirmation %>
Which produces this:
Confirm
Password
And it worked fine.
Mike
On Nov 13, 2008 2:42 PM, “James B. Byrne” [email protected] wrote:
On Thu, November 13, 2008 14:02, James B. Byrne wrote: > > What is the
correct syntax to test sele…
present in an input box? …
The webrat API specifies this:
selects(option_text, options = {})
Verifies that a an option element exists on the current page with the
specified text. You can optionally restrict the search to a specific
select list by assigning options[:from] the value of the select list’s
name or a label. Stores the option’s value to be sent when the form is
submitted.
Examples:
selects “January”
selects “February”, :from => “event_month”
selects “February”, :from => “Event Month”
But when I try to use something like:
And I select “CORP” from “Legal Form”
# features/step_definitions/webrat_steps.rb:16
This is what happens:
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.choose (NoMethodError)
/usr/lib/ruby/gems/1.8/gems/webrat-0.3.2/lib/webrat/core/scope.rb:91:in
selects' /usr/lib/ruby/gems/1.8/gems/webrat-0.3.2/lib/webrat/rails.rb:88:in
send’
So, checking out webrat.steps I see this:
When /^I select “(.)" from "(.)”$/ do |value, field|
selects(value, :from => field)
end
So, as far as I can make out, given the webrat API specifies that a
label
is an acceptable target, this should work. But it evidently does not.
Is
this a webrat problem then?
– *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:…