Today I Learned

Different values with every call from stubbed method

Today I needed to get two different responses from called client to test it. To do this you just stub method classic way but you provide multiple arguments:

allow(Service).to receive(:call).and_return('1', '2')

When service is called for first time it returns '1' and for second time it’s returning '2'.

It also works with WebMock :

stub_request(:get, "www.example.com").to_return({body: "abc"}, {body: "def"})