ruby - What is the difference between double and spy? -


i'm reading spies , can't see de difference between this:

rspec.describe "have_received"   "passes when message has been received"     invitation = spy('invitation', deliver: "ok")     invitation.deliver     expect(invitation).to have_received(:deliver)   end end 

and this:

rspec.describe "have_received"   "passes when message has been received"     invitation = double('invitation', deliver: "ok")     invitation.deliver     expect(invitation).to have_received(:deliver)   end end 

both examples passes without problem. can't see advantage using spy

as @max said in comments, difference can use spy without deliver: "ok". so, running this:

rspec.describe "have_received"   "passes when message has been received"     invitation = spy('invitation')     invitation.deliver     expect(invitation).to have_received(:deliver)   end end  rspec.describe "have_received"   "passes when message has been received"     invitation = double('invitation')     invitation.deliver     expect(invitation).to have_received(:deliver)   end end 

the first example pass not second.

enter image description here

now understand means...

"you can use test double (or partial double) spy, double must setup spy on messages care about. spies automatically spy on messages, or can allow message spy on it."


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -