Better mocking API with rspec #161

iafonov opened this Issue Feb 8, 2012 · 1 comment


None yet

2 participants

iafonov commented Feb 8, 2012

For now in my code I'm using the following pattern a lot:

stub_request(:get, "")
client.get(:nodes, :shard2)
a_request(:get, "").should have_been_made

What do you think about providing ability to use lambda syntax for such tests?

lambda {
  client.get(:nodes, :shard2)
}.should make_request(:get, "").with(...)

(BTW: Maybe I'm missing something and it is already possible?)

bblimke commented Feb 8, 2012

WebMock by design follows stub-execute-verify philosophy.
It separates these 3 steps and allows each of them to be performed exclusively.
RSpec combines stub+verify i.e. should_receive, which is ok, but different.

WebMock also uses global stubs and executed requests registry.
To implement this approach, WebMock would require some kind of registry per lambda.

I'm not sure it's obvious that ".should make_request" also stubs the request.

I like this syntax though, so I'd like to add it to WebMock, but only if there is any clear way
to add it to current WebMock's architecture.

@bblimke bblimke closed this May 12, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment