Showing posts with label Capybara. Show all posts
Showing posts with label Capybara. Show all posts

Sunday, 22 April 2012

Why not to test everything with Capybara

Firstly, I like Capybara. I think it is nice how easy it is to test with just a few verbs, and you can do things from the perspective of the user. It is no good having the back end for a feature if nobody is ever going to click the button to make it happen. I decided to try do an entire project using just Capybara for testing.

However this comes at a price. Each assertion restarts Rails Server.
This is VERY slow for lots of tests to the point where each test takes about 2 seconds in my current project.

I suppose a drawback some people might make is my tests are tightly bound to the actual view which is another drawback of using Capybara.

Yet another issue I am hitting is organization, all my Capybara tests end up in the same Requests folder which is quite naughty of me.

So, Capybara is slow on many assertions, it links you to the way you display information, and it makes me personally use a disorganised file structure.
Conclusion is I should not use entirely Capybara for the entire project testing. I really need to mix Rspec in there with occasional sprinkles of Capybara.

Wednesday, 14 March 2012

A Newfound Love of Testing

So I will say it from the start, I dislike cucumber with a passion. It just feels like another language I need to write, then I end up writing code to "pass" my tests where I actually end up testing my tests using the code I would have originally wrote.

This meant that all that happened was I sat in the back of lectures thinking "Nope Nope Nope", and that it would just double my work load.
On top of that, cucumber-rails has the added bonus of breaking all machines running windows. Not really an appropriate tool to pick to teach us TDD on windows university PCs with.

Then along came capybara.
The great thing is you can basically write all your tests as variations on a few commands.

  • Click_on "some_button_id"
  • Page.should have_content  "some #{dynamic} content" 
  • visit some_path
  • current_path.should eq some_path
  • fill_in "field name", :with => "some #{dynamic} content"


That is pretty much it. With capybara, it is like sitting behind someone telling them what to do, it is no longer complicated or cumbersome and your testing doesn't need to be complicated buggy code of its own. It is REALLY simple and I like it. I like it a lot. It even encourages you to make your HTML better documented as if there is a page with a hundred DELETE buttons, you don't want to accidentally click on the one for yourself.

Mix it with Factory_Girl and you are flying in seconds!