Friday, July 12, 2013

Getting my project to work with Capybara 2.0

My project was originally designed following Michael Hartl's excellent tutorial.  I was using a 1.x verison of Capybara and only had "cockpit error" types of problems - my own fault.

When I moved to Rails 4.0, my tests stopped working.  So I upgraded to Capybara 2.1 and dug in.  I must say I was surprised at the nature of the changes between 1.x and 2.1.

Some symptoms:

  • Accessors like "root_path" stopped working
  • visit stopped working
In general, you will need to modify your tests.
  • the requests directory should be named features
  • require 'spec_helper' needs to be require_relative '../spec_helper'
    • I haven't figured out how to adjust the search path to allow the original construct to work.
  • The outermost "describe" blocks should be "features"
I discovered that features don't nest, nor do scenarios.  See the references below.  In order to make 'visit' work, I turn the outermost 'describe' block into a feature block.

I tried using scenarios for inner blocks.  This was very painful and I went back to describe for inner blocks.

Reference links

An incomplete list of what I changed

Added to spec_helper:

require 'capybara/rspec' require 'capybara/rails' ... config.include Rails.application.routes.url_helpers


I had several checks for title that needed to be updated. They were
it { should have_selector('title', text: 'Sign up') }
Now:
it { should have_title('Sign up') }
An update to this post will follow as i organize my notes.

No comments:

Post a Comment