Undefined Method: Visit (Running RSpec with Capybara)

Last updated:

Ok. There's a couple of things that could be causing this, and this is what you can do to sort it out (I'm running capybara (2.2.0), rspec-rails (2.14.0) on rails (4.0.1) on ruby 2.1.0dev):

  • add require 'capybara/rspec' to spec_helper.rb
  • Your code is under spec/requests; it should be under spec/features. Create the folder if you don't have it. (worked for me)

  • add include Capybara::DSL to RSpec.configure block (probably located in spec/spec_helper.rb)

  • make sure all your calls to visit should be made within it "..." do ... end. I know this is not really a caveat but I've made this mistake and so can others.(worked for me)

  • use feature blocks instead of describe blocks in your spec code.

P.S.: There's two worked for me options because I had this problem twice. Once right after I installed it (and the code got place into spec/requests for some reason), and again after a few days, which turned out to be a bad oversight on my part... I forgotten to wrap the call to visit with an it..do..end block.

Dialogue & Discussion