kofhearts
kofhearts

Reputation: 3794

"undefined method visit" error with capybara, rspec

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!

Upvotes: 0

Views: 773

Answers (1)

Roman Kiselenko
Roman Kiselenko

Reputation: 44380

capybara isn't suppose to be used with type: :request, it's type: :feature.

Upvotes: 5

Related Questions