log-me 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/.travis.yml +1 -2
- data/CHANGELOG.rdoc +3 -0
- data/README.rdoc +25 -1
- data/lib/log-me.rb +6 -5
- data/lib/logme/configuration.rb +1 -0
- data/lib/logme/http_formatter.rb +41 -0
- data/lib/logme/version.rb +2 -1
- data/log-me.gemspec +19 -19
- data/spec/log-me_spec.rb +43 -42
- data/spec/logme/http_formatter_spec.rb +82 -0
- data/spec/spec_helper.rb +2 -1
- metadata +26 -26
- data/lib/logme/net_http_formatter.rb +0 -33
- data/spec/logme/net_http_formatter_spec.rb +0 -40
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
Y2FiMTg0YjYzM2M5NmVjNzBjYTc1NTNiMTQ2ZDg5MzM5ZGQzZDc3YQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MWZhOWRlMzJhNjg2MmUyYjE1NzIxOTU2OGQzMDNhMjI2ZjBlZjMyYQ==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZmYyM2Q0NWQzNTZhY2QzZTFlNTNkM2Q2MDAzNWQ3MWFlMThkMDZlYjYwMmQx
|
10
|
+
OWZmY2Q4MWY1MDMxZTE3ZmU3ZTM3NGY5YmZjYWNlZTExMTY2YTAyMjNmYWY2
|
11
|
+
MWUxYjAyMzZlNmFkMzI4NDA1NjVhM2E4OTE1YzU1ZWU2MDA5NmU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MjdiMmFiOTczNmVkOTc2NWM3ZjAwMTY1Yjg2YmEwOTVkMGZjZjNlYWZhMWIz
|
14
|
+
ZGUxZjhlZTg0MWEwZTU0NTI2ZWExNGUzNjBkYzhlNzM4NzkwODI1Zjg3NTA4
|
15
|
+
YTg2ZDM1YjA0MGE3YTRlZjAxY2YzM2M1NmFmYWZhMWMzZDMwNDU=
|
data/.travis.yml
CHANGED
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
A simple way to configure log in your gem.
|
4
4
|
|
5
|
-
LogMe is especially useful when you need to log Web Service calls or HTTP requests and responses
|
5
|
+
LogMe is especially useful when you need to log Web Service calls or HTTP requests and responses, using Net::HTTP or RestClient.
|
6
6
|
|
7
7
|
{<img src="https://badge.fury.io/rb/log-me.png" alt="Gem Version" />}[http://badge.fury.io/rb/log-me]
|
8
8
|
{<img src="https://travis-ci.org/prodis/log-me.png?branch=master" alt="Build Status" />}[https://travis-ci.org/prodis/log-me]
|
@@ -57,6 +57,30 @@ Logging Net::HTTP requests and responses:
|
|
57
57
|
# Some logic to obtain a Net::HTTP response.
|
58
58
|
response = do_request(request, url)
|
59
59
|
CoolGem.log_response response
|
60
|
+
|
61
|
+
response
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
ws = CoolGem::WebService.new
|
67
|
+
ws.do_something
|
68
|
+
|
69
|
+
Logging RestClient requests and responses:
|
70
|
+
module CoolGem
|
71
|
+
class WebService
|
72
|
+
def do_something
|
73
|
+
args = {
|
74
|
+
method: :post,
|
75
|
+
url: "http://prodis.blog.br",
|
76
|
+
payload: 'param1=value1¶m2=value2'
|
77
|
+
}
|
78
|
+
|
79
|
+
RestClient::Request.execute(args) do |response, request, result|
|
80
|
+
CoolGem.log_request request, args[:url]
|
81
|
+
CoolGem.log_response result
|
82
|
+
response
|
83
|
+
end
|
60
84
|
end
|
61
85
|
end
|
62
86
|
end
|
data/lib/log-me.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require 'logger'
|
2
3
|
require 'logme/configuration'
|
3
|
-
require 'logme/
|
4
|
+
require 'logme/http_formatter'
|
4
5
|
|
5
6
|
module LogMe
|
6
7
|
attr_writer :log_enabled
|
@@ -21,11 +22,11 @@ module LogMe
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def logger
|
24
|
-
@logger ||= ::Logger.new
|
25
|
+
@logger ||= ::Logger.new(STDOUT)
|
25
26
|
end
|
26
27
|
|
27
28
|
def log(message)
|
28
|
-
logger.send
|
29
|
+
logger.send(log_level, "[#{log_label}] #{message}") if log_enabled?
|
29
30
|
end
|
30
31
|
|
31
32
|
def log_request(request, url)
|
@@ -37,12 +38,12 @@ module LogMe
|
|
37
38
|
end
|
38
39
|
|
39
40
|
def self.extended(base)
|
40
|
-
base.send
|
41
|
+
base.send(:extend, LogMe::Configuration)
|
41
42
|
end
|
42
43
|
|
43
44
|
private
|
44
45
|
|
45
46
|
def formatter
|
46
|
-
@formatter ||= LogMe::
|
47
|
+
@formatter ||= LogMe::HttpFormatter.new
|
47
48
|
end
|
48
49
|
end
|
data/lib/logme/configuration.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module LogMe
|
3
|
+
class HttpFormatter
|
4
|
+
def format_request(request, url)
|
5
|
+
message = format_message(request) do
|
6
|
+
message = with_line_break { 'Request:' }
|
7
|
+
message << with_line_break { "#{request.method.to_s.upcase} #{url}" }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def format_response(response)
|
12
|
+
message = format_message(response) do
|
13
|
+
message = with_line_break { 'Response:' }
|
14
|
+
message << with_line_break { "HTTP/#{response.http_version} #{response.code} #{response.message}" }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def format_message(http)
|
21
|
+
message = yield
|
22
|
+
body = extract_body_from(http)
|
23
|
+
message << with_line_break { body } unless blank?(body)
|
24
|
+
message
|
25
|
+
end
|
26
|
+
|
27
|
+
def with_line_break
|
28
|
+
"#{yield}\n"
|
29
|
+
end
|
30
|
+
|
31
|
+
def extract_body_from(http)
|
32
|
+
return http.body if http.respond_to?(:body)
|
33
|
+
return http.args[:payload] if http.respond_to?(:args)
|
34
|
+
return nil
|
35
|
+
end
|
36
|
+
|
37
|
+
def blank?(text)
|
38
|
+
text.to_s.strip.empty?
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/logme/version.rb
CHANGED
data/log-me.gemspec
CHANGED
@@ -2,26 +2,26 @@ lib = File.expand_path('../lib', __FILE__)
|
|
2
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
3
|
require 'logme/version'
|
4
4
|
|
5
|
-
Gem::Specification.new do |
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'log-me'
|
7
|
+
spec.version = LogMe::VERSION
|
8
|
+
spec.authors = ['Prodis a.k.a. Fernando Hamasaki de Amorim']
|
9
|
+
spec.email = ['prodis@gmail.com']
|
10
|
+
spec.summary = 'A simple way to configure log in your spec.'
|
11
|
+
spec.description = 'LogMe is a simple way to configure log in your spec. It is especially useful when you need to log Web Service calls or HTTP requests and responses.'
|
12
|
+
spec.homepage = 'http://github.com/prodis/log-me'
|
13
|
+
spec.licenses = ['MIT']
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
spec.files = `git ls-files`.split($\)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
spec.platform = Gem::Platform::RUBY
|
21
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 1.9.3')
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
spec.add_development_dependency 'coveralls'
|
24
|
+
spec.add_development_dependency 'pry'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.1.0'
|
27
27
|
end
|
data/spec/log-me_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require 'spec_helper'
|
2
3
|
|
3
4
|
module FakeModule
|
@@ -7,49 +8,49 @@ end
|
|
7
8
|
describe LogMe do
|
8
9
|
let(:subject) { FakeModule }
|
9
10
|
|
10
|
-
describe
|
11
|
-
it
|
11
|
+
describe '#log_enabled?' do
|
12
|
+
it 'default is true' do
|
12
13
|
expect(subject).to be_log_enabled
|
13
14
|
end
|
14
15
|
|
15
|
-
context
|
16
|
+
context 'when log is disabled' do
|
16
17
|
around do |example|
|
17
18
|
subject.configure { |config| config.log_enabled = false }
|
18
19
|
example.run
|
19
20
|
subject.configure { |config| config.log_enabled = true }
|
20
21
|
end
|
21
22
|
|
22
|
-
it
|
23
|
+
it 'returns false' do
|
23
24
|
expect(subject).to_not be_log_enabled
|
24
25
|
end
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
|
-
describe
|
29
|
-
it
|
29
|
+
describe '#log_level' do
|
30
|
+
it 'default is info' do
|
30
31
|
expect(subject.log_level).to eq :info
|
31
32
|
end
|
32
33
|
|
33
|
-
context
|
34
|
+
context 'when log level is set' do
|
34
35
|
around do |example|
|
35
36
|
subject.configure { |config| config.log_level = :debug }
|
36
37
|
example.run
|
37
38
|
subject.configure { |config| config.log_level = :info }
|
38
39
|
end
|
39
40
|
|
40
|
-
it
|
41
|
+
it 'returns set level' do
|
41
42
|
expect(subject.log_level).to eq :debug
|
42
43
|
end
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
46
|
-
describe
|
47
|
-
it
|
47
|
+
describe '#log_label' do
|
48
|
+
it 'default is current module name' do
|
48
49
|
expect(subject.log_label).to eq subject.name
|
49
50
|
end
|
50
51
|
|
51
|
-
context
|
52
|
-
let(:label) {
|
52
|
+
context 'when set label' do
|
53
|
+
let(:label) { 'Prodis #15' }
|
53
54
|
|
54
55
|
around do |example|
|
55
56
|
subject.configure { |config| config.log_label = label }
|
@@ -57,19 +58,19 @@ describe LogMe do
|
|
57
58
|
subject.configure { |config| config.log_label = subject.name }
|
58
59
|
end
|
59
60
|
|
60
|
-
it
|
61
|
+
it 'returns label' do
|
61
62
|
expect(subject.log_label).to eq label
|
62
63
|
end
|
63
64
|
end
|
64
65
|
end
|
65
66
|
|
66
|
-
describe
|
67
|
-
it
|
67
|
+
describe '#logger' do
|
68
|
+
it 'default is Logger' do
|
68
69
|
expect(subject.logger).to be_a(::Logger)
|
69
70
|
end
|
70
71
|
|
71
|
-
context
|
72
|
-
it
|
72
|
+
context 'when set logger' do
|
73
|
+
it 'returns set logger' do
|
73
74
|
fake_logger = Class.new
|
74
75
|
subject.configure { |config| config.logger = fake_logger }
|
75
76
|
expect(subject.logger).to eq fake_logger
|
@@ -77,9 +78,9 @@ describe LogMe do
|
|
77
78
|
end
|
78
79
|
end
|
79
80
|
|
80
|
-
describe
|
81
|
+
describe '#log' do
|
81
82
|
let(:log_stream) { StringIO.new }
|
82
|
-
let(:label) {
|
83
|
+
let(:label) { 'Cool Label' }
|
83
84
|
|
84
85
|
before do
|
85
86
|
subject.configure { |config| config.logger = ::Logger.new(log_stream) }
|
@@ -91,71 +92,71 @@ describe LogMe do
|
|
91
92
|
subject.configure { |config| config.log_label = subject.name }
|
92
93
|
end
|
93
94
|
|
94
|
-
context
|
95
|
-
it
|
96
|
-
subject.log
|
97
|
-
expect(log_stream.string).to include "[#{label}] Some message to log
|
95
|
+
context 'when log is enabled' do
|
96
|
+
it 'logs the message' do
|
97
|
+
subject.log 'Some message to log.'
|
98
|
+
expect(log_stream.string).to include "[#{label}] Some message to log."
|
98
99
|
end
|
99
100
|
|
100
|
-
it
|
101
|
-
expect(subject.logger).to receive(:info).with("[#{label}] Some message to log
|
102
|
-
subject.log
|
101
|
+
it 'calls log level method' do
|
102
|
+
expect(subject.logger).to receive(:info).with("[#{label}] Some message to log.")
|
103
|
+
subject.log 'Some message to log.'
|
103
104
|
end
|
104
105
|
end
|
105
106
|
|
106
|
-
context
|
107
|
+
context 'when log is disabled' do
|
107
108
|
around do |example|
|
108
109
|
subject.configure { |config| config.log_enabled = false }
|
109
110
|
example.run
|
110
111
|
subject.configure { |config| config.log_enabled = true }
|
111
112
|
end
|
112
113
|
|
113
|
-
it
|
114
|
-
subject.log
|
114
|
+
it 'does not log the message' do
|
115
|
+
subject.log 'Some message to log.'
|
115
116
|
expect(log_stream.string).to be_empty
|
116
117
|
end
|
117
118
|
end
|
118
119
|
|
119
|
-
context
|
120
|
+
context 'when log level is set' do
|
120
121
|
around do |example|
|
121
122
|
subject.configure { |config| config.log_level = :debug }
|
122
123
|
example.run
|
123
124
|
subject.configure { |config| config.log_level = :info }
|
124
125
|
end
|
125
126
|
|
126
|
-
it
|
127
|
-
expect(subject.logger).to receive(:debug).with("[#{label}] Some message to log
|
128
|
-
subject.log
|
127
|
+
it 'calls log level set method' do
|
128
|
+
expect(subject.logger).to receive(:debug).with("[#{label}] Some message to log.")
|
129
|
+
subject.log 'Some message to log.'
|
129
130
|
end
|
130
131
|
end
|
131
132
|
end
|
132
133
|
|
133
|
-
describe
|
134
|
+
describe '#log_request' do
|
134
135
|
let(:log_stream) { StringIO.new }
|
135
|
-
let(:request) { double
|
136
|
-
let(:url) {
|
136
|
+
let(:request) { double('Request') }
|
137
|
+
let(:url) { 'http://prodis.blog.br' }
|
137
138
|
|
138
139
|
before do
|
139
140
|
subject.configure { |config| config.logger = ::Logger.new(log_stream) }
|
140
141
|
end
|
141
142
|
|
142
|
-
it
|
143
|
-
allow_any_instance_of(LogMe::
|
143
|
+
it 'logs formatted request message' do
|
144
|
+
allow_any_instance_of(LogMe::HttpFormatter).to receive(:format_request).with(request, url).and_return('Request message.')
|
144
145
|
subject.log_request(request, url)
|
145
146
|
expect(log_stream.string).to include "[#{subject.name}] Request message.\n"
|
146
147
|
end
|
147
148
|
end
|
148
149
|
|
149
|
-
describe
|
150
|
+
describe '#log_response' do
|
150
151
|
let(:log_stream) { StringIO.new }
|
151
|
-
let(:response) { double
|
152
|
+
let(:response) { double('Response') }
|
152
153
|
|
153
154
|
before do
|
154
155
|
subject.configure { |config| config.logger = ::Logger.new(log_stream) }
|
155
156
|
end
|
156
157
|
|
157
|
-
it
|
158
|
-
allow_any_instance_of(LogMe::
|
158
|
+
it 'logs formatted response message' do
|
159
|
+
allow_any_instance_of(LogMe::HttpFormatter).to receive(:format_response).with(response).and_return('Response message.')
|
159
160
|
subject.log_response response
|
160
161
|
expect(log_stream.string).to include "[#{subject.name}] Response message.\n"
|
161
162
|
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe LogMe::HttpFormatter do
|
5
|
+
describe '#format_request' do
|
6
|
+
context 'when request has body' do
|
7
|
+
let(:url) { 'http://prodis.blog.br' }
|
8
|
+
|
9
|
+
context 'and responds to body method' do
|
10
|
+
let(:request) do
|
11
|
+
double('Net::HTTP::Post', method: 'POST', body: 'param1=value1¶m2=value2')
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'formats request message including body' do
|
15
|
+
expected_message = "Request:\nPOST #{url}\nparam1=value1¶m2=value2\n"
|
16
|
+
expect(subject.format_request(request, url)).to eq expected_message
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'and responds to args method' do
|
21
|
+
let(:request) do
|
22
|
+
double('RestClient::Request', method: :post, args: { payload: 'param1=value1¶m2=value2' })
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'formats request message including body' do
|
26
|
+
expected_message = "Request:\nPOST #{url}\nparam1=value1¶m2=value2\n"
|
27
|
+
expect(subject.format_request(request, url)).to eq expected_message
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when request does not have body' do
|
33
|
+
let(:url) { 'http://prodis.blog.br?s=logme+gem' }
|
34
|
+
|
35
|
+
context 'and responds to body method' do
|
36
|
+
let(:request) do
|
37
|
+
double('Net::HTTP::Get', method: 'GET', body: nil)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'formats request message without body' do
|
41
|
+
expected_message = "Request:\nGET #{url}\n"
|
42
|
+
expect(subject.format_request(request, url)).to eq expected_message
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'and responds to args method' do
|
47
|
+
let(:request) do
|
48
|
+
double('RestClient::Request', method: :get, args: {})
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'formats request message without body' do
|
52
|
+
expected_message = "Request:\nGET #{url}\n"
|
53
|
+
expect(subject.format_request(request, url)).to eq expected_message
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#format_response' do
|
60
|
+
context 'when response has body' do
|
61
|
+
let(:response) do
|
62
|
+
double('Net::HTTP::OK', http_version: '1.1', code: '200', message: 'OK', body: '<xml><fake />')
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'formats response message' do
|
66
|
+
expected_message = "Response:\nHTTP/1.1 200 OK\n<xml><fake />\n"
|
67
|
+
expect(subject.format_response(response)).to eq expected_message
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'when response does not have body' do
|
72
|
+
let(:response) do
|
73
|
+
double('Net::HTTP::OK', http_version: '1.1', code: '200', message: 'OK', body: nil)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'formats response message' do
|
77
|
+
expected_message = "Response:\nHTTP/1.1 200 OK\n"
|
78
|
+
expect(subject.format_response(response)).to eq expected_message
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,93 +1,93 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: log-me
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Prodis a.k.a. Fernando Hamasaki de Amorim
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: coveralls
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ! '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ! '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: pry
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ! '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ! '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '10'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '10'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 3.1.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
69
|
-
description: LogMe is a simple way to configure log in your
|
70
|
-
when you need to log Web Service calls or HTTP requests and responses.
|
68
|
+
version: 3.1.0
|
69
|
+
description: LogMe is a simple way to configure log in your spec. It is especially
|
70
|
+
useful when you need to log Web Service calls or HTTP requests and responses.
|
71
71
|
email:
|
72
72
|
- prodis@gmail.com
|
73
73
|
executables: []
|
74
74
|
extensions: []
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
|
-
-
|
78
|
-
-
|
79
|
-
-
|
77
|
+
- .gitignore
|
78
|
+
- .rspec
|
79
|
+
- .travis.yml
|
80
80
|
- CHANGELOG.rdoc
|
81
81
|
- Gemfile
|
82
82
|
- README.rdoc
|
83
83
|
- Rakefile
|
84
84
|
- lib/log-me.rb
|
85
85
|
- lib/logme/configuration.rb
|
86
|
-
- lib/logme/
|
86
|
+
- lib/logme/http_formatter.rb
|
87
87
|
- lib/logme/version.rb
|
88
88
|
- log-me.gemspec
|
89
89
|
- spec/log-me_spec.rb
|
90
|
-
- spec/logme/
|
90
|
+
- spec/logme/http_formatter_spec.rb
|
91
91
|
- spec/spec_helper.rb
|
92
92
|
homepage: http://github.com/prodis/log-me
|
93
93
|
licenses:
|
@@ -99,12 +99,12 @@ require_paths:
|
|
99
99
|
- lib
|
100
100
|
required_ruby_version: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- -
|
102
|
+
- - ! '>='
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version: 1.9.
|
104
|
+
version: 1.9.3
|
105
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
106
|
requirements:
|
107
|
-
- -
|
107
|
+
- - ! '>='
|
108
108
|
- !ruby/object:Gem::Version
|
109
109
|
version: '0'
|
110
110
|
requirements: []
|
@@ -112,8 +112,8 @@ rubyforge_project:
|
|
112
112
|
rubygems_version: 2.2.2
|
113
113
|
signing_key:
|
114
114
|
specification_version: 4
|
115
|
-
summary: A simple way to configure log in your
|
115
|
+
summary: A simple way to configure log in your spec.
|
116
116
|
test_files:
|
117
117
|
- spec/log-me_spec.rb
|
118
|
-
- spec/logme/
|
118
|
+
- spec/logme/http_formatter_spec.rb
|
119
119
|
- spec/spec_helper.rb
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module LogMe
|
2
|
-
class NetHttpFormatter
|
3
|
-
def format_request(request, url)
|
4
|
-
message = format_message(request) do
|
5
|
-
message = with_line_break { "Request:" }
|
6
|
-
message << with_line_break { "#{request.method} #{url}" }
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def format_response(response)
|
11
|
-
message = format_message(response) do
|
12
|
-
message = with_line_break { "Response:" }
|
13
|
-
message << with_line_break { "HTTP/#{response.http_version} #{response.code} #{response.message}" }
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def format_message(http)
|
20
|
-
message = yield
|
21
|
-
message << with_line_break { http.body } if has_body?(http)
|
22
|
-
message
|
23
|
-
end
|
24
|
-
|
25
|
-
def with_line_break
|
26
|
-
"#{yield}\n"
|
27
|
-
end
|
28
|
-
|
29
|
-
def has_body?(http)
|
30
|
-
http.body && !http.body.strip.empty?
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe LogMe::NetHttpFormatter do
|
4
|
-
describe "#format_request" do
|
5
|
-
context "when request has body" do
|
6
|
-
let(:request) do
|
7
|
-
double "Net::HTTP::Post", method: "POST", body: "param1=value1¶m2=value2"
|
8
|
-
end
|
9
|
-
let(:url) { "http://prodis.blog.br" }
|
10
|
-
|
11
|
-
it "formats request message including body" do
|
12
|
-
expected_message = "Request:\nPOST #{url}\nparam1=value1¶m2=value2\n"
|
13
|
-
expect(subject.format_request(request, url)).to eq expected_message
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context "when request does not have body" do
|
18
|
-
let(:request) do
|
19
|
-
double "Net::HTTP::Get", method: "GET", body: nil
|
20
|
-
end
|
21
|
-
let(:url) { "http://prodis.blog.br?s=logme+gem" }
|
22
|
-
|
23
|
-
it "formats request message without body" do
|
24
|
-
expected_message = "Request:\nGET #{url}\n"
|
25
|
-
expect(subject.format_request(request, url)).to eq expected_message
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "#format_response" do
|
31
|
-
let(:response) do
|
32
|
-
double "Net::HTTP::OK", http_version: "1.1", code: "200", message: "OK", body: "<xml><fake />"
|
33
|
-
end
|
34
|
-
|
35
|
-
it "formats response message" do
|
36
|
-
expected_message = "Response:\nHTTP/1.1 200 OK\n<xml><fake />\n"
|
37
|
-
expect(subject.format_response(response)).to eq expected_message
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|