我正在尝试测试用户已成功创建的注释显示在用户的个人页面上。但是,每当我运行测试时,我都会遇到折旧错误,并且由于未定义用户而导致测试无法正常运行。
user_page_spec.rb
let (:user) { FactoryGirl.create(:user) }
describe "user note list" do
before(:all) { 10.times { FactoryGirl.create(:note, user: user) } }
after(:all) { Note.delete_all }
工厂.rb
FactoryGirl.define do
factory :user do
name "JowJebus"
provider "twitter"
uid "123456"
//matches omniauth fake user
factory :note do
sequence(:title) { |n| "Note_#{n}" }
sequence(:content) { |n| "Lorem ipsum ..... #{n}" }
user
结果错误:
undefined method 'notes' for nil:NilClass
和折旧误差
This is deprecated behavior that will not be supported in RSpec 3.
'let' and 'subject' declarations are not intended to be called
in a 'before(:all)' hook, as they exist to define state that...
所以很明显我要让用户不正确地进行这个测试,如何正确地做到这一点?
谢谢。
注意:我正在测试的东西确实有效。我只需要帮助正确地对其进行测试。