Undefined Method 'Visit' When Using Rspec and Capybara in Rails

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



Leave a reply



Submit