How do you stub all methods of a particular mock instance?

I have a specific layout that is being processed by a third party. I just want to check that the same layout was returned back.

However, the third party calls the array methods and saves the methods that my test really doesn't care about. Is there any way to tell me about this, that it expects / drowns out all the methods associated with this particular mock instance?

eg.

user = mock(User)
user.stub_all

Thank!

EDIT

More about the problem:

Test:

  it "creating an invitation should return invitation" do
    invitation = mock_model(Invitation)
    invitation.stub(:[]=)
    invitation.stub(:save)
    Invitation.stub(:create).and_return(invitation)
    @user.create_invitation
    @user.create_invitation.should == invitation        
  end

Checked code:

 def create_invitation
    invitation = Invitation.create
    self.invitations.push(invitation)
    return invitation
  end

I need to make fun of the following, which is not directly related to what I'm testing:

invitation.stub(:[]=)
invitation.stub(:save)
+3
source share
1 answer

Answer

user = mock(User).as_null_object

but overall, this approach means that your objects are too large and your tests are not granular enough.

+6

All Articles