1

我正在阅读 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)

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

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

实用程序.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

知道我做错了什么吗?

4

2 回答 2

2

检查这一行

def sign_in(user)
visit signin_path
...
end

signin_path似乎不正确。运行rake routes以获取正确的路径并将其替换为signin_path

于 2012-04-24T03:18:22.710 回答
0

我也花了很长时间来寻找这个令人困惑的错误。就我而言,问题在于 Rails 版本之间的差异。尝试将“spec/requests”目录重命名为“features”

于 2014-10-08T20:32:26.160 回答