Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

#gemfile
...
gem 'rspec-rails'
gem 'capybara'

i have add require 'capybara/rails' in spec_helper.rb according with official docs. i have generate a test:

$rails generate integration_test authentication_pages

i have write a test:

#spec/features/authentication_pages_spec.rb
describe "Authentication" do
  subject { page }    
  describe "signin" do    
    before { visit new_user_session_path }    
    describe "with invalid information" do
      before { click_button "Sign in" }    
      it { should have_title('Sign in') }
    end
  end
end

running the test i had an error:

$rspec spec/features/authentication_pages_spec.rb 
F

Failures:

  1) Authentication signin with invalid information 
     Failure/Error: before { visit new_user_session_path }
     NameError:
       undefined local variable or method `new_user_session_path' for #<RSpec::Core::ExampleGroup::Nested_1::Nested_1::Nested_1:0x000000010f9618>
     # ./spec/features/authentication_pages_spec.rb:6:in `block (3 levels) in <top (required)>'

Finished in 0.0007 seconds
1 example, 1 failure

Failed examples:

rspec ./spec/features/authentication_pages_spec.rb:11 # Authentication signin with invalid information

new_user_session_path is a valid path, i'm using it in my app and it works.

i have no solution, i have respected the official docs. Can you help me?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
212 views
Welcome To Ask or Share your Answers For Others

1 Answer

i have found the error: missing require 'spec_helper' in spec/features/authentication_pages_spec.rb

the correct file is this:

#spec/features/authentication_pages_spec.rb
require 'spec_helper'
describe "Authentication" do
  subject { page }    
  describe "signin" do    
    before { visit new_user_session_path }    
    describe "with invalid information" do
      before { click_button "Sign in" }    
      it { should have_title('Sign in') }
    end
  end
end

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...