Sha256: 6d1a019a4d9b12a6a67542e513935fb5773ac4ffc2e53a6c401cbe35f2c8cd1a
Contents?: true
Size: 1.46 KB
Versions: 2
Compression:
Stored size: 1.46 KB
Contents
require File.expand_path(File.dirname(__FILE__) + '/spec_helper') require 'webmock_spec' require 'ostruct' require 'net_http_spec_helper' include NetHTTPSpecHelper describe "Webmock with Net:HTTP" do it_should_behave_like "WebMock" it "should work with block provided" do stub_http_request(:get, "www.example.com").to_return(:body => "abc"*100000) Net::HTTP.start("www.example.com") { |query| query.get("/") }.body.should == "abc"*100000 end it "should yield block on response" do stub_http_request(:get, "www.example.com").to_return(:body => "abc") response_body = "" http_request(:get, "http://www.example.com/") do |response| response_body = response.body end response_body.should == "abc" end it "should handle Net::HTTP::Post#body" do stub_http_request(:post, "www.example.com").with(:body => "my_params").to_return(:body => "abc") req = Net::HTTP::Post.new("/") req.body = "my_params" Net::HTTP.start("www.example.com") { |http| http.request(req)}.body.should == "abc" end it "should behave like Net::HTTP and raise error if both request body and body argument are set" do stub_http_request(:post, "www.example.com").with(:body => "my_params").to_return(:body => "abc") req = Net::HTTP::Post.new("/") req.body = "my_params" lambda { Net::HTTP.start("www.example.com") { |http| http.request(req, "my_params")} }.should raise_error("both of body argument and HTTPRequest#body set") end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
webmock-0.8.2 | spec/net_http_spec.rb |
webmock-0.8.1 | spec/net_http_spec.rb |