使用Mocha时,发现Model的find方法的返回值变成true了
几经折腾,发现是rspec_matchers这个plugin的一段代码导致的:
[code]
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
[/code]
find方法被stub为返回true了,靠!
还有一段代码:
[code]
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
[/code]
很可爱的plugin
几经折腾,发现是rspec_matchers这个plugin的一段代码导致的:
[code]
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
[/code]
find方法被stub为返回true了,靠!
还有一段代码:
[code]
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
[/code]
很可爱的plugin
使用Mocha时遇到Model的find方法返回true的问题,发现是由rspec_matchers插件中的一段代码导致,该代码将find方法替换成始终返回true。
9

被折叠的 条评论
为什么被折叠?



