Before I ask my question: Thank you all very much for making Upcase such a great service. I’ve learned so much already and have definitely leveled up my testing skills as a result. Thank you!
I just read A Closer Look at Test Spies a few different times and noticed the reference to this video, which I’ve watched a few times: Stubs, Mocks, Spies, and Fakes | Online Video Tutorial by thoughtbot. The video references spies but doesn’t use Rspec’s spy
method. Also, the post on the blog doesn’t use the spy
method in context (I don’t see the entire test, just the one line change). From the blog post, is this the correct use of spy
?
describe "updating credit card details" do
it "saves the credit card with Stripe" do
stripe_customer = spy("Stripe::Customer")
token = "fake token"
post :update, stripe_token: token
expect(stripe_customer).to have_received(:card=).with(token)
expect(stripe_customer).to have_received(:save)
end
end