Note that there are some explanatory texts on larger screens.

plurals
  1. POundefined method `visit' when using RSpec and Capybara in rails
    text
    copied!<p>I can't get capybara working with rspec. It gives me this error:</p> <pre><code>undefined method `visit' for #&lt;RSpec::Core::ExampleGroup::Nested_1:0x16529f8 @example=nil&gt; </code></pre> <p>I know there are lots of posts about this but non of the solutions are working for me. Most of them involve the specs not being in /spec/features - which mine is in.</p> <p>First the error: </p> <pre class="lang-rb prettyprint-override"><code>$bundle exec rspec spec F Failures: 1) security signs users in Failure/Error: visit "/sessions/new" NoMethodError: undefined method `visit' for #&lt;RSpec::Core::ExampleGroup::Nested_1:0x16529f8 @example=nil&gt; # ./spec/features/security_spec.rb:4:in `(root)' Finished in 0.006 seconds 1 example, 1 failure Failed examples: rspec ./spec/features/security_spec.rb:3 # security signs users in </code></pre> <p>I think its important to note that at first I was using the URL Helper 'new_sessions_path' and it kept giving me an error <code>undefined local variable or method 'new_sessions_path'</code>. I know it is valid because: </p> <pre class="lang-rb prettyprint-override"><code>$ rake routes logout_sessions GET /sessions/logout(.:format) sessions#logout sessions POST /sessions(.:format) sessions#create new_sessions GET /sessions/new(.:format) sessions#new contracts POST /contracts(.:format) contracts#create new_contracts GET /contracts/new(.:format) contracts#new edit_contracts GET /contracts/edit(.:format) contracts#edit GET /contracts(.:format) contracts#show PUT /contracts(.:format) contracts#update DELETE /contracts(.:format) contracts#destroy root / contracts#index </code></pre> <p>My Gemfile: </p> <pre class="lang-rb prettyprint-override"><code>source 'https://rubygems.org' gem 'rails', '3.2.11' gem 'execjs' group :assets do gem 'sass-rails', '~&gt; 3.2.3' gem 'coffee-rails', '~&gt; 3.2.1' gem 'uglifier', '&gt;= 1.0.3' end gem 'jquery-rails' gem 'activerecord-oracle_enhanced-adapter', '~&gt; 1.4.1' gem 'jruby-openssl' gem 'therubyrhino' gem 'kaminari' gem 'nokogiri' group :development do gem 'warbler' end group :test do gem 'rspec-rails' gem 'capybara' gem 'activerecord-jdbcsqlite3-adapter' end </code></pre> <p>spec_helper.rb inside of my_app/spec: </p> <pre class="lang-rb prettyprint-override"><code># 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' # Capybara integration 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| # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures # config.fixture_path = "#{::Rails.root}/spec/fixtures" config.use_transactional_fixtures = true config.infer_base_class_for_anonymous_controllers = false config.order = "random" # Include path helpers config.include Rails.application.routes.url_helpers end </code></pre> <p>my_app/spec/features/security_spec.rb: </p> <pre class="lang-rb prettyprint-override"><code>describe "security", :type =&gt; :feature do it "signs users in" do visit "/sessions/new" fill_in "username", :with =&gt; "user" fill_in "password", :with =&gt; "pass" click_button "Sign In" page.should have_content('Login Successful') end end </code></pre> <p>I've tried defining the test above both with and without <code>:type =&gt; :feature</code>. It makes no difference either way. Any ideas what I should try next?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload