Created
March 29, 2012 15:40
-
-
Save rafops/2238714 to your computer and use it in GitHub Desktop.
Mock polymorphic associations with Mocha
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mock_polymorphic | |
mock().tap do |p| | |
p.expects(:class).returns(p).at_least_once | |
p.expects(:base_class).returns(p).at_least_once | |
p.expects(:name).returns('Mock').at_least_once | |
p.expects(:id).returns((rand * 10e5).round).at_least_once | |
p.expects(:blank?).returns(false).at_least_once | |
p.expects(:destroyed?).returns(false).at_least_once | |
p.expects(:new_record?).returns(false).at_least_once | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment