Skip to content

Instantly share code, notes, and snippets.

@ashmoran
Created September 14, 2011 15:19
Show Gist options
  • Save ashmoran/1216852 to your computer and use it in GitHub Desktop.
Save ashmoran/1216852 to your computer and use it in GitHub Desktop.
WebMock weirdness
it "satisfies: The Content-Length MUST be specified and correct according to the guidelines and rules laid out in Section 4.4, 'Message Length', of the HTTP specification" do
ascii_data = "This > O < is a snowman"
utf8_data = "This > ☃ < is a snowman"
post_request(method: ascii_data)
content_length = nil
request.with { |actual_request|
(content_length = actual_request.headers["Content-Length"].to_i) > 0
}.should have_been_requested
ascii_request_size = content_length # WebMock appears to be running the block above twice(!)
post_request(method: utf8_data)
request.with(headers: { "Content-Length" => (ascii_request_size + 2) }).should have_been_requested
end
def post_request(overrides = { })
post({id: "foo", method: "method"}.merge(overrides))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment