I am trying to write some RSpec tests to test my app, but I've stumbled on several problems that I can't find any solution. 1) I am trying to test the update action. Here is my code:
it "email is a new one" do
put :update, id: @user, user: FactoryGirl.attributes_for(:user, :email=>"[email protected]")
@user.reload
@user.email.should == "[email protected]"
puts @user.email
end
Here is the UsersController update action:
def update
@user = User.find(params[:id])
respond_to do |format|
if @user.update_attributes(params[:user])
format.html { redirect_to edit_user_path(@user), :notice => "Your settings were successfully updated."}
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
Here is the error:
Failure/Error: @user.email.should == "[email protected]"
expected: "[email protected]"
got: "[email protected]" (using ==)
It's obvious that the test hasn't changed the email of the user. I took the update action tutorial from here: http://everydayrails.com/2012/04/07/testing-series-rspec-controllers.html . Where I could find the solution?