【发布时间】:2010-06-28 16:07:39
【问题描述】:
我正在使用一些 Shoulda rspec 匹配器来测试我的模型,其中之一是:
describe Issue do
it { should_not allow_value("test").for(:priority) }
end
我的问题是我在模型中的验证看起来像这样:
validates_format_of :priority, :with => /^(Low|Normal|High|Urgent)$/, :on => :update
所以当运行这个测试时,我得到:
1) 'Issue should not allow priority to be set to "test"' FAILED
Expected errors when priority is set to "test", got errors: category is invalid (nil)title can't be blank (nil)profile_id can't be blank (nil)
验证没有被触发,因为它只在更新时运行,我如何在更新和创建时使用这些应该匹配器?
【问题讨论】:
标签: ruby-on-rails unit-testing rspec shoulda