我正在尝试将rspec
与capybara
一起使用。
Gemfile
group :test do
gem 'capybara'
end
根据文档,我需要向{em> rails_helper.rb 中添加require 'capybara/rspec'
,
require 'spec_helper'
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'rspec/rails'
require 'capybara/rspec'
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
config.infer_spec_type_from_file_location!
config.filter_rails_from_backtrace!
end
现在,当我运行bundle exec rspec
时。我得到:
Failure/Error: visit('/')
NoMethodError:
undefined method `visit' for #<RSpec::ExampleGroups::HomeFooters:0x000000035cc4b8>
测试如下:
require 'rails_helper'
RSpec.describe "HomeFooters", type: :request do
it "show proper links in footer" do
visit('/')
page.should have_content("Jobs")
end
end
我该如何解决此错误?
感谢您的帮助!谢谢!
答案 0 :(得分:4)
capybara
不能与type: :request
一起使用,而是type: :feature
。