2008-01-28

rspec_matchers真弱

关键字: rspec_matchers
使用Mocha时,发现Model的find方法的返回值变成true了
几经折腾,发现是rspec_matchers这个plugin的一段代码导致的:
def validate_uniqueness_of(attribute)
  return simple_matcher("model to validate the uniqueness of #{attribute}") do |model|
    model.class.stub!(:find).and_return(true)
    !model.valid? && model.errors.invalid?(attribute)
  end
end

find方法被stub为返回true了,靠!

还有一段代码:
def validate_confirmation_of(attribute)
  return simple_matcher("model to validate the confirmation of #{attribute}") do |model|
    model.send("#{attribute}_confirmation=", 'asdf')
    !model.valid? && model.errors.invalid?(attribute)
  end
end

很可爱的plugin
评论
发表评论

您还没有登录,请登录后发表评论

hideto
搜索本博客
我的相册
A6bdc31c-c66e-468e-961e-9cc721e82adc-thumb
screenshot
共 1 张
存档
最新评论