-
Notifications
You must be signed in to change notification settings - Fork 319
/
logging_spec.rb
68 lines (56 loc) · 1.57 KB
/
logging_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# frozen_string_literal: true
require "logger"
RSpec.describe HTTP::Features::Logging do
subject(:feature) do
logger = Logger.new(logdev)
logger.formatter = ->(severity, _, _, message) do
format("** %s **\n%s\n", severity, message)
end
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