Response body Proc only evaluated once #258

Closed
rfletcher opened this Issue Feb 28, 2013 · 4 comments

Comments

Projects
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, "http://example.com").to_return(
  :body => lambda { |request| body }
)

puts open("http://example.com").read
body = "B"
puts open("http://example.com").read

That script produces:

A
A

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?

Thanks!

Owner

bblimke commented Mar 1, 2013

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

Owner

bblimke commented Mar 1, 2013

It's fixed in master. Cheers.

Great, thanks!

rfletcher closed this Mar 1, 2013

Owner

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