Stub some_lib's behavior and can avoid requesting actually. allow(some_lib).to receive(:request).with(no_args).and_return(expected_boby) end let(:client) { SomeClient.new } # instance_double: # - Can stub methods. # - If you try to stub the undefined method, it would raise an error. let(:some_lib) { instance_double(SomeLib) } let(:expected_body) { ... } let(:expected_json) { JSON.parse expected_body } subject { client.request } # call the subject. it { is_expected.to eq expected_json } end
alternate type of test double that support this pattern by allowing you to expect that a message has been received after the fact, using have_received.
is similar to stub, but represents the specification of the call at tests. set message expectation -> test spy test -> verify message expectation Can write tests more naturally.