Capybara Methods: undefined
I cannot get capybara to work. I am using capybara 2.0.0
I am getting this error
Failure/Error: visit "/users/sign_in"
NoMethodError:
undefined method `visit' for #<RSpec::Core::ExampleGroup::Nested_21:0x007fdda4c6eba0>
according to this specification
specs / requests / forgot_password_spec.rb
describe "forgot password" do
it "redirects user to users firms subdomain" do
visit "/users/sign_in"
end
end
I have no errors that capybara cannot find and it is included in spec_helper.rb
spec_helper.rb
require 'rubygems'
require 'spork'
require 'database_cleaner'
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rspec'
require 'rspec/autorun'
require 'factory_girl'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.include Devise::TestHelpers, :type => :controller
config.extend ControllerMacros, :type => :controller
config.include RequestMacros, :type => :request
config.mock_with :rspec
config.use_transactional_fixtures = false
config.before(:suite) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
config.infer_base_class_for_anonymous_controllers = false
end
Spork.each_run do
FactoryGirl.reload
end
end
Has anyone else encountered this?
source to share
If you have a version >= 2.0
, any tests that use Capybara's methods such as visit
should be in the spec / features directory , not spec / requests where they are usually found in Capybara 1.1.2
.
For more information see the following links:
If you don't want to use the spec / features directory , you can mark the test as feature
follows and use Capybara's methods:
describe "Some action", type: :feature do
before do
visit "/users/sign_in"
# ...
end
# ...
end
source to share
In my case, I got this error because I forgot to put require "spec_helper"
at the top of my new spec file.
I've been doing this long enough to add an answer to an already answered question in the hopes that it will help another heel (or most likely I'll be looking for it again in the future).
source to share