undefined method `visit' when using RSpec and Capybara in rails
Adding require 'rails_helper'
at the top of my feature ended up fixing my problem:
require 'rails_helper'
describe "security", :type => :feature do
it "signs users in" do
visit new_sessions_path
fill_in "username", :with => "user"
fill_in "password", :with => "pass"
click_button "Sign In"
page.should have_content('Login Successful')
end
end
This seems odd to me since every example I've seen for rspec and capybara didn't have that require, but oh well. Problem solved.
Original Answer (older versions of rspec)
require 'spec_helper'
is used by older versions of RSpec. The better answer would be require 'rails_helper'
.
undefined method `visit' for # Object (NoMethodError) capybara rspec
As documented you need to require 'capybara/cucumber' to include the capybara dsl methods into cucumber tests. If you have an issue with doing that you'd need to call all the methods on current_session like Capybara.current_session.visit('/')
.
undefined method visit error with capybara, rspec
capybara
isn't suppose to be used with type: :request
, it's type: :feature
.
Undefined method 'visit' (using rspec and capybara)
I've found the problem.... I was missing a it ... do ... end
block around the second call to visit
... Sorry for this and thank you to everyone who's helped me.
Rails Rspec error - undefined method `visit'
The problem is here:
./spec/requests/user_pages_spec.rb
You put the Capybara integration tests in requests
folder. That's why the method visit
won't work.
To fix, just move all the tests from spec/requests
to spec/features
.
Related Topics
Gem Install Permission Problem
Imagemagick - "Core_Rl_Magick_.Dll Not Found" or How to Install Rmagick on Windows With Ruby 1.9.2
What Does the "||=" Operand Stand for in Ruby
How to Use Define_Method to Create Class Methods
Rvm Warning! Path Is Not Properly Set Up
Is This the Best Way to Unescape Unicode Escape Sequences in Ruby
Extract Single String from HTML Using Ruby/Mechanize (And Nokogiri)
Converting an Integer to a Hexadecimal String in Ruby
In Ruby, How Does Coerce() Actually Work
How to Convert a String to a Constant in Ruby
Nomethoderror When Trying to Invoke Helper Method from Rails Controller
How to Convert Datetime.Now to Utc in Ruby
How to Wait for Process to Finish Using Io.Popen