Sha256: e6d339e69e8efecfdfff4ea17ba835ca471faec41ad38de4a0feeb8ae9ef20c7

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

require 'spec_helper'
require 'fakeweb'
require "uri"

describe "HttpLogger" do

  before do
    # flush log
    f = File.open(LOGFILE, "w")
    f.close
  end

  let(:url) { "http://google.com/" }
  let(:uri) { URI.parse("http://google.com/") }
  let(:request) do
    Net::HTTP.get_response(uri)
  end

  subject do
    request
    File.read(LOGFILE)
  end

  it { should_not be_empty }

  context "when headers logging is on" do

    before(:each) do
      Net::HTTP.log_headers = true
    end

    it { should include("HTTP response header") }
    it { should include("HTTP request header") }

    after(:each) do
      Net::HTTP.log_headers = false
    end
    
  end

  describe "post request" do
    let(:request) do
      Net::HTTP.post_form(uri, {:a => 'hello', :b => 1})
    end

    it {should include("POST params")}
    it {should include("a=hello&b=1")}
  end
  describe "put request" do
    let(:request) do
      http = Net::HTTP.new(uri.host, uri.port)
      request = Net::HTTP::Put.new(uri.path)
      request.set_form_data(:a => 'hello', :b => 1)
      http.request(request)
    end

    it {should include("a=hello&b=1")}
    it {should include("PUT params")}
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
http_logger-0.2.1 spec/http_logger_spec.rb