0

This seems to be a common issue, but I've looked at undefined method `visit' when using RSpec and Capybara in rails and Rails Rspec error - undefined method `visit' and neither solution works for me.

Capybara is working just fine for the Cucumber tests I have under /features.

My RSpec test is in /spec/features and begins:

require 'rails_helper'

describe 'session_project', type: :controller do
  before(:each) do
    @user = User.create(
        username: 'user',
        password: 'test',
        password_confirmation: 'test',
        email: 'user@example.com',
        role: 3
    )
    @project = Project.create(name: 'Project 1', active: true, user_id: @user.id)
  end
  context 'when I am on the view Project 1 page' do
    before do
      visit '/projects'
      find(:xpath, %{//tr[td='Project 1']/td[@class='list_actions']/a[text()='View']}).click
    end
    # ... and so on.

The line visit '/projects' is giving me the error Undefined method 'visit

If I include config.include Capybara::DSL in my RSpec configuration it complains that Capybara is an undefined constant, so perhaps RSpec is looking in the wrong place for it?

Any ideas on how I can get RSpec working with Capybara?

Community
  • 1
  • 1
digitig
  • 1,989
  • 3
  • 25
  • 45

1 Answers1

0

Your test is a feature test (it describes how a user interacts with the app in a browser), and yet it's tagged with type: :controller. Change it to type: :feature.

Feature specs also include Capybara by default.

https://www.relishapp.com/rspec/rspec-rails/v/3-1/docs/feature-specs/feature-spec

sevenseacat
  • 24,699
  • 6
  • 63
  • 88