Configure Test::Unit and Capybara

While trying to set up Capybara with Test::Unit, I ran into trouble finding documentation on how to do it. Ultimately, I found the answer in the gem’s README, but for those who just want to google-and-go, I figured I’d post this for you.

Simply, throw this in your Gemfile

1
2
3
group :test do
  gem 'capybara'
end

and run `bundle`

Now, open up test/test_helper.rb: we’re going to require capybara, and then crack open the integration test class to include Capybara and pass it your app

1
2
3
4
5
6
7
8
# test_helper.rb
...
include Capybara

class ActionDispatch::IntegrationTest
  include Capybara
  Capybara.app = Issuepad::Application
end

That should do it, let me know if you run into any other issues.

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Twitter

Comment | Trackback

Code

4 Responses to “Configure Test::Unit and Capybara”

  1. komagata Says:

    April 6th, 2011 at 4:50 am

    This article save me from involved rspec.
    Just what I’ve been looking for.
    Thank you so much!

  2. Jo Liss Says:

    April 13th, 2011 at 7:33 am

    If you are on Rails, you’d also want to put require ‘capybara/rails’ in test_helper.rb to automagically load Rails support. With that, you should not need to set Capybara.app anymore.

  3. Frank Says:

    April 13th, 2011 at 7:38 am

    Awesome, thanks!

  4. Prakash Murthy Says:

    June 9th, 2011 at 6:57 pm

    Thanks; this was very helpful.

    However, the steps above alone did not make it work successfully. I had to include the following lines in the test/test_helper.rb file:

    require ‘capybara’
    require ‘capybara/dsl’

Leave a Reply