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'tospec_helper.rb Your code is under
spec/requests; it should be underspec/features. Create the folder if you don't have it. (worked for me)add
include Capybara::DSLtoRSpec.configureblock (probably located inspec/spec_helper.rb)make sure all your calls to
visitshould be made withinit "..." do ... end. I know this is not really a caveat but I've made this mistake and so can others.(worked for me)use
featureblocks instead ofdescribeblocks 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.