ruby on rails - Avoiding multiple API Calls in Rspec tests -


i trying test "scan" method have. within scan method, make api call (among other things).

how can test method without triggering unneeded api calls?

one approach stub out call api:

allow(thing).to receive(:action).and_return(response) 

another approach allow api call go through, intercept , return mock response using vcr. "record" request , "play back".

vcr handy when need handle the entire response in test subject. run test against real api 1 time, subsequent tests can use vcr "cassette". otoh slower stubbing call, if need mock status , not entire response.

tl:dr, stub if can, don't hesitate use vcr when saves work.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -