I’ve just started reading up on Rspec and am trying to write a few specs
to test methods in my models.
Consider the following
class Users
has_many :items
def state_of_last_item?
case items.active.last.state #uses a named scope
when 0
# do something
when 1
# do something
when 2
# do something
end
end
end
I want to write the spec to test that the ‘do somethings’ are working as
expected. How do I stub out the bit with the named scope? I thought it
would be something like:
@user.stub!(‘items.active.last.state’).and_return(0)
but this doesn’t work. What is the correct way to stub out something
like this?
Thanks
TC