bblimke/webmock — pull request #273 by jure (2013-04-03 23:44:17+00:00)
Title: Raise WriteError if returning -1 from on_body callback, just like real Curl

So we have code that goes something like this:
```
curl.on_body do |data|
total_size += data.size
if disallowed_content_type
# Do this here instead of on-header to allow for redirects
-1
elsif total_size > 30_000_000
-1
else
file << data
data.size
end
end
```

And in production (or outside of tests), this raises a Curl::Err::WriteError

```
req = Curl::Easy.new('http://www.microsoft.com')
=> #
req.on_body do |data|
-1
end
=> nil
req.perform
Curl::Err::WriteError: Curl::Err::WriteError
from /Users/jure/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/curb-0.8.3/lib/curl/easy.rb:60:in `perform'
from (irb):6
from /Users/jure/.rbenv/versions/2.0.0-p0/bin/irb:12:in `

'
req.last_result
=> 23
```

But when using WebMock, there is no WriteError, which makes it impossible to test for those situations.

Curl raises this error from here:
[](https://github.com/taf2/curb/blob/master/lib/curl/easy.rb#L58-L60)

I have no idea how to get a realistic last_result in WebMock (right now it seems to vary wildly, probably because it's not really defined?), but the attached code worked well for my case and is what we're using right now.

I'm happy to debate this further and improve it.