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 8163547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:05:12+00:00 2026-06-06T19:05:12+00:00

Basically what is happening is when I’m doing the integration testing in my rspec

  • 0

Basically what is happening is when I’m doing the integration testing in my rspec specifications I’m testing the reset password functionality, and I’m using a third party api call to send out the email. I want to trust the third party api to send out the email and ignore the response entirely.

Here is the code that I’m using right now, but it is still sending out the email as well as failing because the call to send_password_reset (which is where the third party api call is contained) is “not” being called according to Mocha

before(:each) do
  @client = Factory(:user_with_clients).clients.first
end

it 'should send out the email(mock) set a temporary password and take them back to the login page' do
  # WHEN THE MOCK WAS MOVED HERE THE SPEC PASSSED
  visit '/client_portal/reset_password/new'
  fill_in 'email', with: @client.email
  click_button 'Send password reset'
  # THIS NEEDED TO BE MOVED TO THE TOP OF THE FUNCTION
  Client.expects(:send_password_reset).returns(true)
  current_path.should eq('/client_portal/login')
  page.should have_content('Check your email')
  @client.reload
  @client.tmp_password.should_not eq(nil)
end

I don’t think posting the factories used to create this will reveal anything else, but you think that would help you help me I’ll do it.

I have also tried to change the Cilent.expects to @client.expects and I still have the same issue. I’m not tied to the Mocha framework since this is actually my first mock I’ve ever done.

I’ve also read that I’m not supposed to be mocking objects in integration testing, but I don’t know of a way to not send out the email when the test is called.

Just thought that I should add the controller action in there as well in case I should be changing something in there…

def create
    client = Client.find_by_email(params[:email])
    if client
      client.set_tmp_password
      if client.send_password_reset
        redirect_to '/client_portal/login', notice: 'Check your email for the password reset link'
      else
        redirect_to '/client_portal/login', notice: 'There was an error resetting your password. Please try one more time, and contact support if it doesn\'t work'
      end
    else
      flash.now[:notice] = 'No account with that email address was found'
      render :new
    end
  end

Im receiving this error when I run the test

  1) Reset a users password user is not logged in valid email address supplied should send out the email(mock) set a temporary password and take them back to the login page
     Failure/Error: Client.any_instance.expects(:send_password_reset).returns(true)
     Mocha::ExpectationError:
       not all expectations were satisfied
       unsatisfied expectations:
       - expected exactly once, not yet invoked: #<AnyInstance:Client(id: integer, first_name: string, last_name: string, email: string, password_digest: string, signup_charge: decimal, monthly_charge: decimal, active: boolean, created_at: datetime, updated_at: datetime, monthly_charge_day: integer, sold_by_user_id: integer, tmp_password: string)>.send_password_reset(any_parameters)
     # ./spec/requests/client_portal/reset_password_spec.rb:14:in `block (4 levels) in <top (required)>'

SOLUTION

Using the code below from @Veraticus and moving it to the top of the spec solved the issue.

  • 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-06T19:05:14+00:00Added an answer on June 6, 2026 at 7:05 pm

    The problem is that you’re not calling the send_password_reset method on the class; you’re calling it on an instance of that class. Use this:

     Client.any_instance.expects(:send_password_reset).returns(true)
    

    The client found by Client.find_by_email will have the expectation set up on it correctly.

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

Sidebar

Related Questions

I'm having a problem using UpdateModel(theModelToUpdate) causing concurrency issues. Basically whats happening is, there
Basically, I'm doing a lot with Visual Studio lately and in my quest to
Basically what's happening is that I need to download a whole bunch of files
Im having some major problems with an site im developing, basically whats happening is
Basically what's happening is that the XML nodes themselves aren't changing position. So I
I am finding something odd happening with my program. This program basically is used
Basically, I'm using WebGrid and I need to filter the results. The first problem
I've got this weird bug happening. I'm basically just adding a few minutes to
So I have this problem, which I don't see how it's happening. Basically I
Basically whats happening is I can create a new item that gets saved to

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.