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
- How to fix “Undefined method ‘visit’” with Capybara 2.0
- rspec-rails and capybara 2.0: what you need to know
- Capybara 2.0 Upgrade Guide
- Introducing Capybara 2.1
- End-to-end testing....
- Capybara project on GitHub
- Stack overflow on nested featues
- secret_key_base not defined
An incomplete list of what I changed
Added to spec_helper:
require 'capybara/rspec'
require 'capybara/rails'
...
config.include Rails.application.routes.url_helpers
it { should have_selector('title', text: 'Sign up') }
it { should have_title('Sign up') }