Error messages can't be found by capybara

719 views
Skip to first unread message

Daniel Salmerón Amselem

unread,
Feb 17, 2011, 6:51:19 AM2/17/11
to plataformate...@googlegroups.com
Hi everyone!

I'm using Steak 1.1.0 for acceptance testing with Capybara 0.4.1.2, RSpec 2.5.0 and Rails 3.0.4, and I've tried to run a test like the one below, but unfortunately the message displayed doesn't seem to appear in the DOM.

  scenario "should not be able to create a group without a name" do
    visit("/groups/new")
    click_on "Save"
    page.should have_content("Please fillout this field.")
  end

I've tried to understand how those error notifications are implemented and it looks like is using the content_tag method to attach the error to the DOM. Does anyone have any advice on how to test this?
Is simple_form designed to show the error notifications without generating a new HTTP request to the 'create' action, and being redirected back to the 'new' one when there are errors on the object?

Any hint would be appreciate it. Thanks.

Carlos Antonio da Silva

unread,
Feb 17, 2011, 7:02:37 AM2/17/11
to plataformate...@googlegroups.com, Daniel Salmerón Amselem
Sorry, but I guess you're messing up things a bit, talking about acceptance testing, DOM, SimpleForm and http requests.
In the default scenario, when you click Save and your form has errors, it'd render the new action/view again. Assuming your object has errors, SimpleForm will just show them.

Remember SimpleForm is a form builder, it's not its responsibility to handle anything related to ajax, http requests, and all that stuff =)

--
At.
Carlos A. da Silva

Daniel Salmerón Amselem

unread,
Feb 17, 2011, 7:09:36 AM2/17/11
to plataformate...@googlegroups.com, Daniel Salmerón Amselem
Thanks Carlos, but my form doesn't generate an HTTP request to the "create" action when I click on the "Save" button. I've checked it on the rails server console. 

I understand simple_form is just a FormBuilder and doesn't have anything to do with HTTP requests and all that stuff. I also understand the errors are generated by the "create" action when you try to save the object. But in this particular case, if I leave the input field blank, it shows a message that says: "Please fillout this field" for a couple of seconds and then it disappears. My form looks like this:

= simple_form_for @group do |f|
  = f.input :name
  = f.button(:submit, 'Guardar')

and the Group model has a validates_presence_of :name

Carlos Antonio da Silva

unread,
Feb 17, 2011, 7:15:19 AM2/17/11
to plataformate...@googlegroups.com, Daniel Salmerón Amselem
Ok, so I believe you're doing some javascript work here, am I right?
If so, what's the capybara driver you're using? Rack-test does not work with javascript, so you'd have to use another driver such as selenium or culerity for instance.

Daniel Salmerón Amselem

unread,
Feb 17, 2011, 7:49:54 AM2/17/11
to plataformate...@googlegroups.com, Daniel Salmerón Amselem
I'm not using any javascript, and right now I'm testing it manually with Google Chrome. It's really weird, I don't know where is that message coming from.

I've make a small screen video recording so you can see what happens.


If you need more information I would gladly give it to you. Oh! And thanks for helping me on this.

Carlos Antonio da Silva

unread,
Feb 17, 2011, 7:58:38 AM2/17/11
to plataformate...@googlegroups.com, Daniel Salmerón Amselem
Ahhh.. guess now I got it!

What I believe it's happening is that SF is generating a "required" attribute in your input (html5), based on the validation you have. Then Google Chrome makes it a required input, so it won't let you submit without filling in this field. But this message will never appear on your tests, it's a Chrome feature.
You will have to write tests with the default error messages, such as "can't be blank".

Your screencast helped a lot =D.

Daniel Salmerón Amselem

unread,
Feb 17, 2011, 8:06:49 AM2/17/11
to plataformate...@googlegroups.com, Daniel Salmerón Amselem
Wow!!! Thanks Carlos, you saved me a lot of hours with this. Do you think this is something that should be on the README file? I mean, this is something that can happen to a lot of people...

Carlos Antonio da Silva

unread,
Feb 17, 2011, 8:19:02 AM2/17/11
to plataformate...@googlegroups.com, Daniel Salmerón Amselem
I believe a more appropriate local is the wiki, what do you think?
Maybe you could open a new page there explaining about Google Chrome features and HTML5, and talk about the :required stuff.

Also, I guess someone was working on a feature to disable HTML5 features in SimpleForm, which would disable this :required attribute as well.  Sounds good to disable them with such "issues" sometimes imo, lets see how it goes.

On Thu, Feb 17, 2011 at 11:06 AM, Daniel Salmerón Amselem <daniel....@gmail.com> wrote:
Wow!!! Thanks Carlos, you saved me a lot of hours with this. Do you think this is something that should be on the README file? I mean, this is something that can happen to a lot of people...



Daniel Salmerón Amselem

unread,
Feb 22, 2011, 12:45:34 PM2/22/11
to Carlos Antonio da Silva, plataformate...@googlegroups.com
Sorry Carlos for this late response. I'll try to write this page sometime this week.

Daniel Salmerón Amselem

Carlos Antonio da Silva

unread,
Feb 22, 2011, 2:21:56 PM2/22/11
to Daniel Salmerón Amselem, plataformate...@googlegroups.com
No problem, do it at your time :)
Reply all
Reply to author
Forward
0 new messages