In the following example the @user.expects(:send_invitations!).once assertion is failing, even though the invitations are being sent by the app and the @send_invitations variable is being assigned. Would you expect @user.send_invitations! to be invoked at this point or is @user.expects(:send_invitations!) being used incorrectly?
The Controller
class RegistrationsController < ApplicationController
before_filter :require_active_user
def welcome
if params[:send_invitations]
current_user.send_invitations!
@send_invitations = true
end
end
end
The Controller Test
require 'test_helper'
class RegistrationsControllerTest < ActionController::TestCase
context "With a logged-in user" do
setup { login_as @user = Factory(:user) }
context ":welcome" do
context "with params[:send_invitations] present" do
setup { get :welcome, { :send_invitations => true } }
should "send invitations" do
@user.expects(:send_invitations!).once # tests say this isn't being invoked
assert assigns(:send_invitations) # but tests say this IS being assigned
end
end
context "without the presence of params[:send_invitations]" do
setup { get :welcome }
should "not send invitations" do
@user.expects(:send_invitations!).never # passes fine
assert !assigns(:send_invitations!) # also passes fine
end
end
end
end
end