mercredi 23 septembre 2015

How does instance_spy work?

I'm kind of new to this so please bare with me. I currently have a unit test with the following that I'm trying to de-bug:

describe "#issue!" do
  it "delegates to task#issue" do
    t = instance_spy("Task")
    expect(t).to receive(:issue).with(type: 'create_task')
  end
end

the method it's hitting is coming from this:

def issue!
  t = object.tasks.new
  t.issue(type: 'create_task')
  t
end

and when I run rspec I get the following message:

Failure/Error: expect(t).to receive(:issue).with(type: 'create_task') (InstanceDouble(Task) (anonymous)).issue({:type=>"create_task"}) expected: 1 time with arguments: ({:type=>"create_task"}) received: 0 times

Basically, I want to know how does the instance_spy work? Does it create a new object that bypass validation without saving it to the database similar to using .new or does it save it to the database without going through validation (.create!(validate: false))? Been trying to troubleshoot this error for a while now.

I hope this make sense...

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire