Thursday, December 23, 2010

Capybara labels not working

Actually, they are.

Say you have a post model, and you gave it the label foobar.
Now you try to use that label to refer to the model you've created/found.
Consider the following example:



This example, rather than failing by saying the model did not match the fields passed into it, violently fails by giving the error:


Not very pretty, right?
In fact, I personally mistook this for having something wrong with my labels.
Turns out, the label is totally fine, but the error thrown, well... threw me off...

It took me way too much time to go through any bit of capybara documentation I could lay my hands on, and I still not understand why I got the error.

Finally, turns out Pickle raises this error, not because this label is not valid, but rather because the model "myteacher" doesn't match the attributes I'm requesting.

For example: the following test, which uses the same label is actually passing.


Hopefully this saves you some good quality time between your head and your favorite wall.
I emailed the developer of Pickle and I'm hoping he'll be kind enough to change the error a bit in future versions so that it is clearer what's happening.

Capybara and Selenium in Rails 3 tests fail and browser doesn't start

I had an issue with Firefox not starting to run Selenium in Rails 3.
Instead, my tests failed, giving me all red (even for steps that were previously passing without JS). Turns out this is caused by a dependency issue.
Someone thankfully posted a question on StackOverflow that helped me get through this.
To fix it, simply run add this to your Gemfile

Then run

This should fix it for you.

You can also track this issue at Github, where I posted this very solution.