Hi guys,
I’m writing a integration test and i’m still have problems with a form
field.
The RSpec continues to show me a message bellow:
Failure/Error: fill_in :password_confirmation, :with =>
@attr[:password_confirmation]
Webrat::NotFoundError:
Could not find field: :password_confirmation
But the field is there, look the field code:
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation %>
This field create the follow HTML code for me:
Password
confirmation
And it works fine when I use the browser.
Please, Has anybody idea of what’s happening?
Att,
Pablo Lacerda de Miranda
[email protected]
+55 11 8701-1086
On 2 May 2011 13:53, Pablo L. de Miranda [email protected]
wrote:
But the field is there, look the field code:
And it works fine when I use the browser.
Please, Has anybody idea of what’s happening?
Webrat only sees the generated HTML, not the view code. In particular,
it finds the field based on either the text of an associated label, or
the ‘name’ attribute of the field:
http://rdoc.info/github/brynary/webrat/master/Webrat/Scope:fill_in
In your case, the text of the associated label is “Password
confirmation” and the ‘name’ attribute of the field is
“subdomain[password_confirmation]” (which you can check by looking at
the generated HTML). So you need to pass one of those to the ‘fill_in’
method.
Chris
Hi Chris,
Thank your for your explanation, but I have a doubt about this. I’m
printing the method test bellow:
it “should create a new account” do
lambda do
visit new_subdomain_path
response.should render_template(‘subdomains/new’)
fill_in :nome, :with => @attr[:name]
fill_in :responsavel, :with => @attr[:responsable]
fill_in :email, :with => @attr[:email]
fill_in :password, :with => @attr[:password]
fill_in :password_confirmation, :with =>
@attr[:password_confirmation]
click_button
end.should change(Subdomain, :count).by(1)
end
My test recognize all the field except the password confirmation
field, why? This is why I can’t sleep, why just this field in
particular?
Thanks,
Pablo
Chris,
Thank you man, I replaced all my symbol for field name references, and
worked fine.
Pablo
On 2 May 2011, at 18:04, “Pablo L. de Miranda” [email protected]
wrote:
fill_in :email, :with => @attr[:email]
fill_in :password, :with => @attr[:password]
fill_in :password_confirmation, :with => @attr[:password_confirmation]
click_button
end.should change(Subdomain, :count).by(1)
end
My test recognize all the field except the password confirmation
field, why? This is why I can’t sleep, why just this field in
particular?
Probably because that’s the only attribute with a two-word name. Webrat
is matching the others based on their label (because ‘email’ and ‘Email’
match case-insensitively), but ‘password_confirmation’ and ‘Password
confirmation’ do not match, because ‘_’ != ’ '.
Chris