Lets say I have a controller: UserController
and there is a method:
before_action :add_friend
def add_friend
@friend = Friend.last
end
How can I stub add_friend
and create instead another instance_variable called @friend2
:
@friend2 = Friend.first
So that:
@friend == nil
and
@friend2.nil? == false
What I tried was:
@friend2 = Friend.first
UserController.any_instance.stubs(:add_friend).returns(@friend2)
But that didnt worked! Thanks
Aucun commentaire:
Enregistrer un commentaire