I am trying to use capybara
with rspec
.
Gemfile
group :test do
gem 'capybara'
end
According to the docs, i need to add require 'capybara/rspec'
to rails_helper.rb , which i did:
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
Now when i run bundle exec rspec
. i get:
Failure/Error: visit('/')
NoMethodError:
undefined method `visit' for #<RSpec::ExampleGroups::HomeFooters:0x000000035cc4b8>
The test is as follows:
require 'rails_helper'
RSpec.describe "HomeFooters", type: :request do
it "show proper links in footer" do
visit('/')
page.should have_content("Jobs")
end
end
How can i solve this error?
I appreciate any help! Thanks!
capybara
不应与type: :request
,而是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.