简体   繁体   中英

undefined method `visit' for #<RSpec

i'm sure this is answered somewhere on stackoverflow but for the life of me, i can't find why my situation is different than what is already written so here goes.

using rspec w/ capybara

  1) report_cards#index must have 'Report Cards Index'
 Failure/Error: visit '/'
 NoMethodError:
   undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_4:0x007fcc3aa33960>
 # ./spec/views/report_cards_view_spec.rb:7:in `block (2 levels) in <top (required)>'

/spec/views/report_cards_view_spec.rb looks like

require 'spec_helper'
describe "report_cards#index" do
  it "must have 'Report Cards Index'" do
  visit '/'
  page.should have_content("something")
  end
end

top lines from spec_helper.rb looks like

ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rails'
require 'capybara/rspec'

gemfile looks like

`source 'https://rubygems.org'`
gem 'rails', '3.2.7'
gem 'jquery-rails'
gem 'pg', '~> 0.14.0'
gem 'devise', '~> 2.1.2'
gem "quiet_assets", "~> 1.0.1"
gem 'thin'
gem 'bourbon'
gem "haml-rails"
gem "httparty", "~> 0.8.3"
gem "activerecord-import", "~> 0.2.10"

group :test, :development do
  gem "rspec-rails", "~> 2.0"
  gem 'capybara', '~>1.1.2'
  gem "fabrication", "~> 2.2.0"
  gem "launchy", "~> 2.1.2"
end

group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'
  gem 'uglifier', '>= 1.0.3'
end`

i'm pretty junior so go easy :) - THX !

capybara is not included in views spec, and it is for integration testing.

try to move your spec file into spec/requests directory

I had a similar issue and all i had to do was to add

config.include Capybara::DSL

to the spec_helper.rb file

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