Forum: Ruby on Rails Rspec response.should have_selector not matching

942ec2f3d036c5c82c02b93957645399?d=identicon&s=25 Greg (Guest)
on 2011-11-21 20:25
(Received via mailing list)
Hi all,
I got some problems with my integration test. I have a form were a new
user can sign up. If the form is blank and submitted the normal error
occur. The error div has an id "error_explanation". In my integration
test i try to match it but the test is always red. Here some Code:

# encoding : utf-8
require 'spec_helper'

describe "Users" do

   describe "signup" do
     describe "failure" do

       it "should not make a new user" do
         lambda do
           visit registrieren_path
           fill_in "Benutzername", :with => ""
           fill_in "Email", :with => ""
           fill_in "Passwort", :with => ""
           fill_in "Passwort besttigen", :with => ""
           click_button
           response.should render_template('users/new')
           response.should have_selector("div", :id =>
"error_explanation")
         end.should_not change(User, :count)
       end
     end
   end
end


Here is the error:

expected following output to contain a <div id='error_explanation'/> tag
...
and the whole html output.


I checked my output and the strange thing is that i even can't find the
form in the output. It looks like the test is checking the index page
instead of the one tried to reach with the visit registrieren_path.

I'm using Rspec Rails v.2.7.0 with Webrat 0.7.3

Hope someone got a hint for me :)

Best regards

Greg
942ec2f3d036c5c82c02b93957645399?d=identicon&s=25 Greg (Guest)
on 2011-11-21 20:40
(Received via mailing list)
On 21.11.2011 20:24, Greg wrote:
>
>           click_button
> Here is the error:
> I'm using Rspec Rails v.2.7.0 with Webrat 0.7.3
>
> Hope someone got a hint for me :)
>
> Best regards
>
> Greg
>
Ok I found the error. I should have pass the submit buttons value to the
click_button function. Now the test is green :)

Thanks anyway.

Regards Greg
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.