1
votes

When I try to run my feature specs with Capybara, I get a

undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_1:0x007fdc629c6d28>

error. I know it's an issue of not having capybara configured correctly because otherwise, it would have a visit method.

Here's the relevant part of my gemfile:

group :test, :development do
  gem 'rspec-rails', '~> 2.0'
  gem 'factory_girl_rails', ">= 4.2.0"
  gem 'guard-rspec', "~> 0.7.0"
end

group :test do
  gem 'faker', '~> 1.0.1'
  gem 'capybara', git: 'https://github.com/jnicklas/capybara', ref: '7fa75e55420e'
  gem 'database_cleaner', '~> 0.7.2'
  gem 'launchy', '~> 2.1.0'
  gem 'shoulda-matchers'
end

Using that ref for capybara I got from this article on upgrading to Capybara 2.0.

And here's my spec:

# spec/features/create_user_spec.rb

require 'spec_helper'

feature 'Creating a user' do

  scenario 'adds a new user' do

    visit new_user_registration_path
    fill_in 'Email', :with => '[email protected]'
    [ 'Password', 'Password confirmation' ].each { |p| fill_in p, :with => '12345678' }
    page.should have_content 'User successfully created'
    current_path.should == recipes_path

  end

end

And here's my spec_helper.rb:

# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'

require 'capybara/rspec'
require 'capybara/rails'

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

RSpec.configure do |config|
  config.use_transactional_fixtures = true

  config.infer_base_class_for_anonymous_controllers = false

  config.include Capybara::DSL

  config.order = "random"
end

What I've tried

  • Manually including Capybara::DSL
  • Adding require_relative to give the right routing to the spec_helper file

Please tell me what I'm overlooking.

1

1 Answers

0
votes

Do you have multiple spec_helper.rb files

try giving

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

or giving the full path...

the underscores were not getting rendered.