简体   繁体   中英

rspec capybara error - undefined method `visit' for #<RSpec

I have:

  • Have added gem 'capybara' to my Gemfile and I have run bundle

  • Have placed my spec in spec/requests as visit_home_page_root_spec.rb

  • Have added to `spec/spec_helper.rb:

-

require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rails'
require 'capybara/rspec'

but I still get the message shown in the title.

My spec is:

describe "Home Page", :type => :feature do

  it "Visit the home page" do
    visit '/'
    expect(page).to have_content 'Linker'
  end

end

Gemfile.lock has:

rspec-core (2.14.8)
rspec-expectations (2.14.5)
  diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.6)
rspec-rails (2.14.1)
  actionpack (>= 3.0)
  activemodel (>= 3.0)
  activesupport (>= 3.0)
  railties (>= 3.0)
  rspec-core (~> 2.14.0)
  rspec-expectations (~> 2.14.0)
  rspec-mocks (~> 2.14.0)

It sounds like the capybara DSL isn't being included in your example. This has been done automatically less and less (and not at all in rspec 3) but from memory it should be your versions.

Nevertheless, you should be able to remedy this by doing

describe "foo" do
  include Capybara::DSL
end

For any specs that need it. Alternatively, in your RSpec.configure block, doing

config.include(Capybara::DSL, :type => :feature)

Would do that automatically for all specs of type feature)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM