[rspec-users] should_receive test unexpectedly failing

ericindc ericmilford at gmail.com
Thu Jul 22 11:48:27 EDT 2010


I'm unsure why this test is still failing.  I've tested it in console
and the code works as expected.  Is there something wrong with how I
have my test written?

****************** error

1) Job selecting the next job to be processed should lock the next job
    Failure/Error: job.should_receive(:update_attribute).with(:locked,
true)
    (#<Job:0x105496488>).update_attribute(:locked, true)
        expected: 1 time
        received: 0 times


****************** job_spec.rb

    it "should lock the next job" do
     job = Factory(:job, :locked => false)
     job.should_receive(:update_attribute).with(:locked, true)
     Job.next
    end


****************** job.rb

    def self.next
      job = incomplete.unlocked.prioritized.limit(1).first
      job.lock! if job
      job
    end

  def lock!
    update_attribute(:locked, true)
  end

  def unlock!
    update_attribute(:locked, false)
  end


More information about the rspec-users mailing list