我在此检验:
require spec_helper
describe League do
it should default weekly to false do
league = Factory.create(:league, :weekly => nil)
league.weekly.should == false
end
end
end
我的模式如下:
class League < ActiveRecord::Base
validates :weekly, :inclusion => { :in => [true, false] }
before_create :default_values
protected
def default_values
self.weekly ||= false
end
end
When I run my test, I get the following error message:
Failure/Error: league = Factory.create(:league, :weekly => nil)
ActiveRecord::RecordInvalid:
Validation failed: Weekly is not included in the list
我尝试了两种不同的办法,试图制造一个模棱两可的记录,引发back击,但我有 t。 在使用RSpec进行测试时,我没有什么东西?