6

I'm looking to set up a bunch of integration tests for an Rails 3 app that is already built. The app is built with Rails 3 and Ruby 1.9.2. I've seen recommendations for Capybara, Cucumber and RSpec 2 but I'm not sure what the advantages of each are.

I've also noticed that they seem to be closely tied together. The post I've seen always seem to talk about using Capybara with Cucumber, or using Rspec with Cucumber.

What are the advantages/disadvantages for each of them? Are there certain combinations that work best together?

2 Answers 2

13

All these test tools fall in different parts of the testing environment.

If you want to set up integration tests, then you should use Cucumber because it has no real alternative. Cucumber is designed to easy Behaviour Driven Development but even if you don't BDD it is perfect for integration testing.

Capybara mission statement is "webrat alternative which aims to support all browser simulators". So to simulate the browser part (http request, DOM manipulation, etc) you have two alternatives Webrat or Capybara. Cucumber integrates fine with both of them. In fact it detects which one you have installed in your system and by default uses it.

On the other side is Rspec. Rspec is not a tool for Integration Testing but for Unit Testing (with a BDD approach). In http://www.pragprog.com/titles/achbd/the-rspec-book it is explained very clearly. Cucumber is in an outer circle of application behaviour and rspec is in an inner circle of class behaviour. The alternative to rspec is classic Test::Unit classes.

For more information see:

Sign up to request clarification or add additional context in comments.

3 Comments

great answer, but may I suggest adding links for Cucumber, Capybara, Webrat, RSpec and Unit::Test. I think you'll get more up votes.
Very good post and answers. So Rspec covers Rails' unit test of model and Cucumber covers Rails' integration test, then what covers Rails' functional test of controllers?
@GeorgeW Rails functional tests are indeed unit tests, they try to test the controllers in isolation (as much as possible). So, to make the answer easy: RSpec for everything but integration tests, where you can use Cucumber. Then of course you can find alternatives to everything.
0

In summary, use all three.

Use RSpec...

  • ...for testing methods in your models, controllers, and helpers in isolation.
  • Also known as Unit testing.

Use Cucumber...

  • ...for testing high level features of your application.
  • Also known as integration testing. Verifies that all the pieces work together.
  • Good for testing from a user's perspective.

Use Capybara with Cucumber...

  • ...for navigating your app like a user would through the browser.
  • ...for testing your views contain the content that a user would expect to see.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.