Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Integration Testing

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?

like image 750
Kyle d'Oliveira Avatar asked Dec 27 '10 18:12

Kyle d'Oliveira


People also ask

What is rails integration test?

While unit tests make sure that individual parts of your application work, integration tests are used to test that different parts of your application work together.

Is RSpec used for integration testing?

Integration Test Using CapybaraCapybara is an exceptionally great tool for performing an integration test with RSpec because it helps you perform end-to-end tests on your applications. It does this by simulating how a real user would interact with your application.

How do I run a rails test?

2.7 The Rails Test Runner Or we can run a single test file by passing the bin/rails test command the filename containing the test cases. This will run all test methods from the test case. You can also run a particular test method from the test case by providing the -n or --name flag and the test's method name.

How do I test a controller in Ruby on rails?

The currently accepted way to test rails controllers is by sending http requests to your application and writing assertions about the response. Rails has ActionDispatch::IntegrationTest which provides integration tests for Minitest which is the Ruby standard library testing framework.


1 Answers

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:

  • Cucumber
  • Capybara
  • Webrat
  • RSpec
  • Test::Unit
like image 135
David Avatar answered Sep 19 '22 02:09

David