使用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