RailsTutorial第9章:signin_path是未定义的局部变量?电子邮件已经被拍

时间:2012-04-23 07:19:47

标签: ruby-on-rails railstutorial.org

我正在阅读RailsTutorial,我坚持第9.3章。当我尝试在9.3结束时运行套件测试时,Rspec不断给我这些错误:

/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)

首先我得到了最大的错误,然后再次运行测试多次,我不断收到第二个错误。

以下是我的控制器路线和测试文件:

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

知道我做错了吗?

2 个答案:

答案 0 :(得分:2)

检查此行

def sign_in(user)
visit signin_path
...
end

signin_path似乎不正确。运行rake routes以获得正确的路径&amp;将其替换为signin_path

答案 1 :(得分:0)

我花了很长时间来追逐这个令人困惑的错误。就我而言,问题是Rails版本之间的区别。尝试将“spec / requests”目录重命名为“features”