Follow Along as I Stumble on the Path to Learning RoR

Checking Instance Variable in RSpec After Update

I was having trouble getting one of my RSpecs to pass which I knew should be passing.  The problem was that when I did the check, the instance variable still held the old value.

For example:

it “should update status to in progress” do

  issue = FactoryGirl.create(:issue, status: “new”)

  Issue.method_to_update_status

  issue.status.should eq “in progress”

end

I knew  that the status was updating, but for some reason the test kept failing.  I found the answer with this SO question.

In order to get the issue record to reflect the new value, I had to add reload after it.

it “should update status to in progress” do

  issue = FactoryGirl.create(:issue, status: “new”)

  Issue.method_to_update_status

  issue.reload.status.should eq “in progress”

end

Advertisements

Comments are closed.