Response body Proc only evaluated once #258

rfletcher opened this Issue Feb 28, 2013 · 4 comments


None yet
2 participants

I'm new to WebMock, and was surprised by the behavior demonstrated below:

require "open-uri"
require "webmock"
include WebMock::API

body = "A"

stub_request(:get, "").to_return(
  :body => lambda { |request| body }

puts open("").read
body = "B"
puts open("").read

That script produces:


I expected it to call the lambda twice, not cache the first result. I dug in a little bit and found that version 1.4.0 actually behaved the way I expected, but that was changed in 1.5.0. The changelog for 1.5.0 doesn't explicitly mention this change, so I'm wondering whether it was intentional.

If the change was intentional, how can I ensure the lambda is called for every request?



bblimke commented Mar 1, 2013

That looks like a bug indeed. I'll have a look into that. Thanks.


bblimke commented Mar 1, 2013

It's fixed in master. Cheers.

Great, thanks!

rfletcher closed this Mar 1, 2013


bblimke commented Mar 1, 2013

It's now also released as 1.10.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment