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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:07:13+00:00 2026-05-16T01:07:13+00:00

I am testing a simple password reset action and would like RSpec’s change matcher

  • 0

I am testing a simple password reset action and would like RSpec’s “change” matcher for lambdas. But it doesn’t work for this controller action. Everything works fine without that matcher. Here is the spec:

  describe "#update" do
it "Updates the password and resets the token" do
  @user = Factory :user
  getter = lambda{
    get :edit, :id => @user.perishable_token, :user => {:password_confirmation => "new_password",
                                                      :password => "new_password"}
    @user.reload
  }
  getter.should change(@user, :password)
  getter.should change(@user, :perishable_token)
end

it "Updates the password and resets the token" do
  @user = Factory :user
  old_password = @user.password
  old_token = @user.perishable_token
  get :edit, :id => @user.perishable_token, :user => {:password_confirmation => "new_password",
                                                      :password => "new_password"}        
  @user.reload.password.should != old_password
  @user.perishable_token.should != old_token
end
end

The second it-block works, the first one doesn’t. I tried to print the values inside the lambda and they indeed aren’t changed.

Thank you very much for any ideas on this 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-05-16T01:07:14+00:00Added an answer on May 16, 2026 at 1:07 am

    So as it turns out the Change-matcher calls the proc. So that wasn’t the problem. However, I was calling Edit and not Update. So nothing was supposed to change. In addition Password only exists on User objects where the password was just set and that where not retrieved from the DB since the clear text password is not saved. Here is the now working code:

    describe "#update" do
    it "Updates the password and resets the token" do
      @user = Factory.create :user
      getter = lambda{
        post :update, :id => @user.perishable_token, :user => {:password_confirmation => "new_password",
                                                                :password => "new_password"}
        @user.reload
      }
      getter.should change(@user, :crypted_password)
      getter.should change(@user, :perishable_token)
    end
    end
    

    I thought it would turn out to be a silly error, but two in one…

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

Sidebar

Related Questions

I am testing a simple query to get data from an AS400 database. I
I have a simple website I'm testing. It's running on localhost and I can
I'm storing a simple java.util.date in an Oracle XE database via hibernate. When testing
Unit testing sounds great to me, but I'm not sure I should spend any
So, I'm trying to learn the rspec BDD testing framework in the context of
I am testing a simple threadpool solution before I put it in my application,
I have the following JUnit test. The method that I'm testing is quite simple,
i have a weird problem with my local Testing-Setup of a simple Java URL
Testing: return request.getCookies() == null; is not an appropriate way test. Is there another
Unit testing and ASP.NET web applications are an ambiguous point in my group. More

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.