我的大部分测试都在工作,但由于某种原因 FactoryGirl.build ... should_not be_valid 在此语句的末尾不起作用
describe "exceed the maximum number of subscriptions" do
@user = FactoryGirl.create(:user)
loop_count = GlobalVar::MAX_SUBSCRIPTIONS
loop_count.times do
@topic = FactoryGirl.create(:topic)
@subscription = FactoryGirl.create(:subscription, topic: @topic, user: @user)
end
@topic = FactoryGirl.create(:topic)
FactoryGirl.build(:subscription, topic: @topic, user: @user).should_not be_valid
end
在同一规范中,这成功通过:
it "has a maximum length bio" do
FactoryGirl.build(:user, bio: "a"*251).should_not be_valid
end
这是我得到的错误的开始:
(druby://192.168.1.118:53053) C:/Sites/mavens/spec/models/user_spec.rb:42:in `block (3 levels) in <top (required)>': undefined local variable or method `be_valid' for #<Class:0x7e49290> (NameError)
from (druby://192.168.1.118:53053) C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/rspec-core-2.11.1/lib/rspec/core/example_group.rb:238:in `module_eval'
我正在使用 Spork 和 Guard 进行测试。每次运行时,我都在 spec_helper 中重新加载了 FactoryGirl。已重新启动 spork 几次,但它在重新启动时不起作用。让我知道我的任何附加代码是否会有所帮助,并且一如既往地感谢您的帮助!