Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7833713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:51:37+00:00 2026-06-02T12:51:37+00:00

I have a particular mock that is being handled by a third party. I

  • 0

I have a particular mock that is being handled by a third party. I just want to check that the same mock has been returned back.

However, the third party calls array methods and save methods that my test doesnt really care about. Is there a way to tell my mock that it expects/stub all methods to do with that particular mock instance?

eg.

user = mock(User)
user.stub_all

Thanks!

EDIT

More info 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

Code being tested:

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

I need to mock the following which are not directly related to what I am testing:

invitation.stub(:[]=)
invitation.stub(:save)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T12:51:38+00:00Added an answer on June 2, 2026 at 12:51 pm

    The answer is

    user = mock(User).as_null_object
    

    but in general this approach means your objects are too large and your tests aren’t granular enough

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a particular web application that like most others, has to account for
I have a particular HTTP response which I don't want cached because it has
I have particular division in my web page. i want to print that div
The JQuery has method effectively selects all elements where they have particular descendants. I
I have a particular PHP page that, for various reasons, needs to save ~200
I have a particular application that needs to calculate something very specific, and while
I have a particular method that is occasionally crashing with an ArgumentException: Destination array
I have one particular FLA that is crashing every time I try to compile
I have a URL in string format that I want to parse to get
I have a class that reads a pop3 email server. I want to write

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.