Skip to content

Instantly share code, notes, and snippets.

@drewB
Created April 1, 2010 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drewB/352449 to your computer and use it in GitHub Desktop.
Save drewB/352449 to your computer and use it in GitHub Desktop.
def stub_find_for_specific_values(model, stubs)
model.stub!(:find).at_least(1).and_return do |id|
if stubs.has_key? id
stubs[id]
else
model.find_by_id(id)
end
end
end
#example below will return the mock_user if its id is search for otherwise find will search as normal
mock_user = mock_model(User)
stub_find_for_specific_values(User, mock_user.id => mock_user)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment