Sha256: 154c74e38b7128688473d42f9bfb5b0de806cde766816f08b6303244f6960256

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
require 'webmock_spec'
require 'ostruct'

def http_request(method, uri, options = {})
  begin
    uri = URI.parse(uri)
  rescue
    uri = Addressable::URI.heuristic_parse(uri)
  end
  response = nil
  clazz = Net::HTTP.const_get("#{method.to_s.capitalize}")
  req = clazz.new("#{uri.path}#{uri.query ? '?' : ''}#{uri.query}", options[:headers])
  req.basic_auth uri.user, uri.password if uri.user
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true if uri.scheme == "https"
  response = http.start {|http|
    http.request(req, options[:body])
  }
  OpenStruct.new({
    :body => response.body,
    :headers => response,
    :status => response.code })
end

describe "Webmock with Net:HTTP" do
  
  it_should_behave_like "WebMock"
  
  it "should work with block provided" do
    stub_http_request(:get, "www.google.com").to_return(:body => "abc"*100000)
    Net::HTTP.start("www.google.com") { |query| query.get("/") }.body.should == "abc"*100000
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
webmock-0.7.3 spec/net_http_spec.rb
webmock-0.7.2 spec/net_http_spec.rb