Sha256: 129cedac4a079db575487f6f3f9788b111954be43b63ec2ad502572d842de4b5
Contents?: true
Size: 1.57 KB
Versions: 2
Compression:
Stored size: 1.57 KB
Contents
# frozen_string_literal: true require "logger" RSpec.describe HTTP::Features::Logging do subject(:feature) do logger = Logger.new(logdev) logger.formatter = ->(severity, _, _, message) { format("** %s **\n%s\n", severity, message) } described_class.new(:logger => logger) end let(:logdev) { StringIO.new } describe "logging the request" do let(:request) do HTTP::Request.new( :verb => :post, :uri => "https://example.com/", :headers => {:accept => "application/json"}, :body => '{"hello": "world!"}' ) end it "should log the request" do feature.wrap_request(request) expect(logdev.string).to eq <<~OUTPUT ** INFO ** > POST https://example.com/ ** DEBUG ** Accept: application/json Host: example.com User-Agent: http.rb/#{HTTP::VERSION} {"hello": "world!"} OUTPUT end end describe "logging the response" do let(:response) do HTTP::Response.new( :version => "1.1", :uri => "https://example.com", :status => 200, :headers => {:content_type => "application/json"}, :body => '{"success": true}', :request => HTTP::Request.new(:verb => :get, :uri => "https://example.com") ) end it "should log the response" do feature.wrap_response(response) expect(logdev.string).to eq <<~OUTPUT ** INFO ** < 200 OK ** DEBUG ** Content-Type: application/json {"success": true} OUTPUT end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
http-5.0.1 | spec/lib/http/features/logging_spec.rb |
http-5.0.0 | spec/lib/http/features/logging_spec.rb |