I used to do the following when I used rspec mocks.
user = mock_model(User)
find_method = User.method(:find)
User.stub!(:find).at_least(1).and_return do |id|
if id == mock_user.id.to_s
user
else
find_method.call(id) # May need to instance_eval here, but I
think .call is sufficient.
On 1 Apr 2010, at 23:12, drewB wrote:
David, thanks for your response.
Matt, I totally hear you. In this contrived example, you probably
could but in the project I am working on it would be very difficult.
One of the challenges of joining a project already in progress...
I have felt that pa
For anyone who might come across this message looking for a solution
to the same problem, I wrote the following function to take care of it
(http://gist.github.com/352449)
def stub_find_for_specific_values(model, stubs)
model.stub!(:find).at_least(1).and_return do |id|
if stubs.has_key? id
David, thanks for your response.
Matt, I totally hear you. In this contrived example, you probably
could but in the project I am working on it would be very difficult.
One of the challenges of joining a project already in progress...
On Apr 1, 1:45 pm, Matt Wynne wrote:
> On 1 Apr 2010, at 21:3
On 1 Apr 2010, at 21:35, David Chelimsky wrote:
On Apr 1, 2010, at 3:14 PM, drewB wrote:
Occasionally, I find myself in a situation where I want to have a
mock
obj returned if a method is called with a particular argument but
handled normally otherwise. For example, lets say I have a Model
On Apr 1, 2010, at 3:14 PM, drewB wrote:
> Occasionally, I find myself in a situation where I want to have a mock
> obj returned if a method is called with a particular argument but
> handled normally otherwise. For example, lets say I have a Model
> named User and I am specing a controller that
Occasionally, I find myself in a situation where I want to have a mock
obj returned if a method is called with a particular argument but
handled normally otherwise. For example, lets say I have a Model
named User and I am specing a controller that sends messages from one
user to another. When Use