问题
I'm going through RailsTutorial and I'm stuck at chapter 9.3. Rspec keeps giving me these errors when I try to run a suite test at the end of 9.3:
/Users/shaan/Sites/sample_app/spec/support/utilities.rb:15:in `sign_in': undefined local variable or method `signin_path' for #<Class:0x107759358> (NameError)
/Library/Ruby/Gems/1.8/gems/activerecord-3.2.3/lib/active_record/validations.rb:56:in `save!': Validation failed: Email has already been taken (ActiveRecord::RecordInvalid)
First I got the top error, then ran the test again many times and I keep getting the second error.
Below are my controller routes and test files:
- controller: http://pastebin.com/vJdCxthQ
- test: http://pastebin.com/SEVLd9Gg
- routes: http://pastebin.com/7LjA5Any
Utilities.rb:
include ApplicationHelper
def full_title(page_title)
base_title = "Ruby on Rails Tutorial Sample App"
if page_title.empty?
base_title
else
"#{base_title} | #{page_title}"
end
end
def sign_in(user)
visit signin_path
fill_in "Email", :with => user.email
fill_in "Password", :with => user.password
click_button "Sign in"
# Sign in when not using Capybara as well.
cookies[:remember_token] = user.remember_token
end
Any idea what I am doing wrong?
回答1:
Check this line
def sign_in(user)
visit signin_path
...
end
signin_path seems to be incorrect. run rake routes to get the correct path & replace that with signin_path
回答2:
I spent a long time chasing this confusing error around too. In my case, the issue was a difference between Rails versions. Try renaming your 'spec/requests' directory to 'features'
来源:https://stackoverflow.com/questions/10276354/railstutorial-ch-9-signin-path-is-undefined-local-variable-email-already-taken