Skip to content

Instantly share code, notes, and snippets.

@rafops
Created March 29, 2012 15:40
Show Gist options
  • Save rafops/2238714 to your computer and use it in GitHub Desktop.
Save rafops/2238714 to your computer and use it in GitHub Desktop.
Mock polymorphic associations with Mocha
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