Skip to content

@myronmarston /example.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
require 'rubygems'
require 'net/http'
require 'webmock'
original_request_uri = nil
WebMock.after_request do |request, response|
original_request_uri = request.uri
end
host = "encrypted.google.com"
http = Net::HTTP.new(host, 443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
url = "/search?abc=%2B"
WebMock.allow_net_connect!
http.request(Net::HTTP::Post.new(url))
WebMock.disable_net_connect!
WebMock.stub_request(:post, original_request_uri.to_s).to_return(:body => 'stubbed')
http.request(Net::HTTP::Post.new(url))
✗ ruby example.rb
/Users/myron/.rvm/gems/ruby-1.8.7-p334/gems/webmock-1.7.0/lib/webmock/http_lib_adapters/net_http.rb:113:in `request': Real HTTP connections are disabled. Unregistered request: POST https://encrypted.google.com/search?abc=+ with headers {'Accept'=>'*/*'} (WebMock::NetConnectNotAllowedError)
You can stub this request with the following snippet:
stub_request(:post, "https://encrypted.google.com/search?abc=%20").
with(:headers => {'Accept'=>'*/*'}).
to_return(:status => 200, :body => "", :headers => {})
registered request stubs:
stub_request(:post, "https://encrypted.google.com/search?abc=%20")
============================================================
from example.rb:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.