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!