Sha256: 76409e604892425b13f58f21edf74f147f7633ca865d005f214d1607317e239c

Contents?: true

Size: 1.88 KB

Versions: 2

Compression:

Stored size: 1.88 KB

Contents

require 'spec_helper'
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(url) }
  let(:request) do
    Net::HTTP.get_response(uri)
  end

  subject do
    _context if defined?(_context)
    request
    File.read(LOGFILE)
  end

  it { should_not be_empty }

  context "when url has escaped chars" do

    let(:url) { "http://google.com?query=a%20b"}

    it { subject.should include("query=a b")}
    
  end

  context "when headers logging is on" do

    before(:each) do
      HttpLogger.log_headers = true
    end

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

    after(:each) do
      HttpLogger.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

  context "with long response body" do

    let(:body) do
      "12,Dodo case,dodo@case.com,tech@dodcase.com,single elimination\n" * 50 +
        "12,Bonobos,bono@bos.com,tech@bonobos.com,double elimination\n" * 50
    end

    let(:url) do
      FakeWeb.register_uri(:get, "http://github.com", :body => body)
      "http://github.com"
    end

    it { should include("12,Dodo case,dodo@case.com,tech@dodcase.com,single elimination\n")}
    it { should include("<some data truncated>") }
    it { should include("12,Bonobos,bono@bos.com,tech@bonobos.com,double elimination\n")}

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
http_logger-0.3.2 spec/http_logger_spec.rb
http_logger-0.3.0 spec/http_logger_spec.rb