ruby on rails - rspec mock not getting called on belongs_to association -


i'm trying test controller in rails rspec, it's not calling 1 of mocks made , i'm not sure why.

my model has user class, , game class, , player class, belongs user , game.

i'm trying test this

player = player.find_by_id(params[:id]) if player != nil && player.user == current_user && player.game.remove_player?(player)   redirect_to games_url 

yet can't seem mock remove_player? correctly. i'm doing pretty this:

@player = double("player") player.should_receive(:find_by_id).with(mock_player_id.to_s).and_return { @gplayer } @player.stub(:user).and_return(@current_user) fakegame = double("game") @player.stub(:game).and_return(fakegame) fakegame.should_receive(:remove_player?).with(@player).and_return(true) 

i'm getting error saying remove_player? never called. idea i'm doing wrong? can't tell sure if it's reaching player.user == curent_user, calling find_by_id , not complaining @ all, imagine must reach user check.

edit: @current_user equal current_user

also, tried replacing line 3 with

fakeuser = double("user") @player.should_receive(:user).and_return(@current_user) 

it gives me error saying :user wasn't called.

in second line of spec, return @player instead of @gplayer. if @gplayer isn't defined, find_by_id return nil in spec, if condition short circuit before gets remove_player.


Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -