我收到以下代码的以下错误消息:
Failure/Error: @league.errors.on(:short_name).should_equal "can't be blank"
NoMethodError:
undefined method `on' for #<ActiveModel::Errors:0x000001017853f0>
@league.errors.on(:short_name).should_equal "can't be blank"
根据我正在阅读的几个文档参考资料,这应该有效。知道发生了什么吗?
答案 0 :(得分:0)
由于@location.errors
是哈希:
require 'rspec'
describe "Location" do
before(:each) do
@location = double("Location")
@location.stub(:errors).and_return(:short_name => "can't be blank")
end
it "should work like a hash" do
@location.errors[:short_name].should == "can't be blank"
end
end