Why and How to write specs?

Why write tests ? Some answers might be Because I have been told by my manager Some could be yay! let's bolt on writing tests because it's cool But some meaningful reasons could be Test-Driven Development is a developer practice that involves writing tests before writing the code being tested. Begin by writing a very small test for code that does not yet exist. Run the test, and, naturally, it fails. Now write just enough code to make that test pass. No more. It gives a strong base for your project or library or even a framework to build upon flawlessly

Capybara-Webkit : How it works and its anomolies

This post is to explain some insights of [capybara-webkit][1] and its functional setup. What is capybara-webkit ? Capybara-webkit is used for acceptance tests in our rails 3 application and it turned out to be non trivial, even though there are excellent tools out there, and they keep getting better. WebKit is an open source web browser engine and capybara-webkit depends on a WebKit implementation from Qt, a cross-platform development toolkit. Using capybara with the capybara-webkit driver, works great because it runs in headless mode, without annoying browser windows popping up. How to setup ? gem "capybara-webkit" Set javascript driver to webkit

Useful Links on Rspec, Cucumber, Capybara,TDD, BDD

Hello Everyone, I wanted to share few links that Swapnil shared with me in the past. All of the links were really great. So I am sharing it here. Also if possible, just take an hour to go through the links. They are really good. If you guys find any good links other than the ones I give below, please post them as comments.So that this post can help someone who needs good references for the specs in the future. https://github.com/jnicklas/capybara https://gist.github.com/zhengjia/428105 :capybara cheat sheet http://eggsonbread.com/2010/09/

Faster Specs with FixtureBuilder

What is [fixture_builder][1] ? Fixture Builder creates fixtures based on your definitions of [FactoryGirl][2] Why fixture_builder ? In projects with huge test suite, its possible that the creation of AR objects hinders the test performance. So to gain performance, we can avoid the redundant database transaction by building subsequent fixtures. Examples https://github.com/rdy/fixture_builder#example It gives tremendous boost to your test execution time. For us the statistics for 550 test cases were : Before fixture_builder ~ 2.5 hours After fixture_builder ~ 19.37 minutes Note : This should be backed up by proper [DatabaseCleaner][3]

Stub HTTP requests in Rspec

In rspec, we need to make http call for our test to pass. In this case, we are actually making http request which is not a best practice while we are executing tests. The best way is to fake http request with the actual expected response without making actually going to that url. For faking http request in ruby, we have couple of gems namely FakeWeb and WebMock. FakeWeb: Usage: Include 'fakeweb' in your Gemfile under test group only. require it in spec helper. use it in specs Syntax: FakeWeb.register_uri(method, url, :body => "response text, html,