When running my specs with rspec & capybara, it can't find capybara's visit method. Is there another initialization step I need to do?
$bundle exec rspec spec
/home/brian/projects/expense_track/expense_track/spec/requests/homepage_spec.rb:6:in `block (2 levels) in <top (required)>': undefined method `visit' for #<Class:0xb6572b8> (NoMethodError)
Gemfile:
group :test, :development do
gem "rspec-rails"
gem "capybara"
end
top of my spec_helper.rb:
# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rspec'
require 'rspec/autorun'
homepage_spec.rb:
require 'spec_helper'
describe "The home page" do
context "home page exists" do
visit "/"
page.should have_content("elephants")
end
end
This blog post helped me fix the issue: http://rubyflewtoo.blogspot.com/2012/12/rails-32-minitest-spec-and-capybara.html
For rspec 3 and rails, make sure you are using
require "rails_helper"
, instead ofrequire "spec_helper"
.Otherwise, review the latest changes to rspec 3 & rspec-rails and Capybara 2.0.x.
Unfortunately this workaround doesn't do it for me. I still get
The repo is public under: https://github.com/ikusei/Goldencobra_Newsletter You need to look at the branch '28817499-subscribe'
edit: If i put include Capybara::DSL inside my describe block it works.
but including Capybara::DSL in the global scope is not recommended!
Because I do not know a good way.
A few things to note here :
This worked for me.
This enables you to use Capybara's helpers inside spec/requests.
Because RSpec.configure not including capybara DSL in spec_helper.rb
It is an ugly solution, but you can add this to your spec_helper.rb.
The git issue for this:
https://github.com/rspec/rspec-rails/issues/503