mini_logger 0.5.2 → 0.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/version.rb +1 -1
- data/test/test_mini_logger.rb +35 -62
- data/test/unit_extensions.rb +23 -0
- metadata +7 -17
data/lib/version.rb
CHANGED
data/test/test_mini_logger.rb
CHANGED
@@ -1,23 +1,23 @@
|
|
1
|
-
$:.unshift(File.dirname(__FILE__))
|
1
|
+
$:.unshift(File.join(File.dirname(__FILE__), '..'))
|
2
|
+
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
3
|
+
|
2
4
|
|
3
5
|
require 'rubygems'
|
4
6
|
require 'tmpdir'
|
5
|
-
require '
|
7
|
+
require 'delorean'
|
6
8
|
require 'file/tail'
|
7
9
|
require 'mini_logger'
|
8
|
-
require '
|
10
|
+
require 'test/unit_extensions'
|
11
|
+
require 'test/helpers/tail_file_helper'
|
9
12
|
|
10
13
|
|
11
14
|
class TestMiniLogger < Test::Unit::TestCase
|
12
15
|
|
13
|
-
|
14
|
-
|
15
|
-
TEST_WARN_MESSAGE = "warn"
|
16
|
-
TEST_ERROR_MESSAGE = "error"
|
17
|
-
TEST_FATAL_MESSAGE = "fatal"
|
16
|
+
TEST_DATE_TIME = "05/11/1970 00:00"
|
17
|
+
TEST_MESSAGE = "message"
|
18
18
|
|
19
19
|
|
20
|
-
|
20
|
+
must "validate loglevel" do
|
21
21
|
|
22
22
|
[:debug, 'info', :warn, 'error', :fatal].each do |l|
|
23
23
|
assert(MiniLogger.validate_log_level?(l), "Log level:'#{l} not validated")
|
@@ -29,7 +29,7 @@ class TestMiniLogger < Test::Unit::TestCase
|
|
29
29
|
end
|
30
30
|
|
31
31
|
|
32
|
-
|
32
|
+
must "standarize log level" do
|
33
33
|
|
34
34
|
['debug', 'DEBUG', 'DeBuG'].all? { |l| l == MiniLogger::DEBUG }
|
35
35
|
['debug', 'DEBUG', 'DeBuG'].map { |l| l.to_sym }.all? { |l| l == MiniLogger::DEBUG }
|
@@ -48,7 +48,7 @@ class TestMiniLogger < Test::Unit::TestCase
|
|
48
48
|
end
|
49
49
|
|
50
50
|
|
51
|
-
|
51
|
+
must "create a logger in debug level by default" do
|
52
52
|
|
53
53
|
##
|
54
54
|
# New configuration interface
|
@@ -72,7 +72,7 @@ class TestMiniLogger < Test::Unit::TestCase
|
|
72
72
|
end
|
73
73
|
|
74
74
|
|
75
|
-
|
75
|
+
must "raise and argument error" do
|
76
76
|
|
77
77
|
[:this, 'set', :of, 'log', :levels, 'are', :evil].each do |l|
|
78
78
|
assert_raise(ArgumentError) { MiniLogger.configure(:level=>l) }
|
@@ -80,14 +80,14 @@ class TestMiniLogger < Test::Unit::TestCase
|
|
80
80
|
end
|
81
81
|
|
82
82
|
|
83
|
-
|
83
|
+
must "create a logger from a configuration file" do
|
84
84
|
|
85
85
|
assert_equal(MiniLogger.configure(File.join(File.dirname(__FILE__), %w[fixtures test_config.yml])).level, MiniLogger::ERROR)
|
86
86
|
assert_raise(Errno::ENOENT) { MiniLogger.configure("ThisFileDoNotExist.yml") }
|
87
87
|
end
|
88
88
|
|
89
89
|
|
90
|
-
|
90
|
+
must "confire various loggers" do
|
91
91
|
|
92
92
|
test_logger = MiniLogger.configure
|
93
93
|
assert(test_logger.debug?)
|
@@ -115,7 +115,7 @@ class TestMiniLogger < Test::Unit::TestCase
|
|
115
115
|
end
|
116
116
|
|
117
117
|
|
118
|
-
|
118
|
+
must "change log levels" do
|
119
119
|
|
120
120
|
test_logger = MiniLogger.configure(:dev=>STDERR, :level=>:debug)
|
121
121
|
assert(test_logger.debug?)
|
@@ -132,7 +132,7 @@ class TestMiniLogger < Test::Unit::TestCase
|
|
132
132
|
end
|
133
133
|
|
134
134
|
|
135
|
-
|
135
|
+
must "not change to invalid log level" do
|
136
136
|
|
137
137
|
test_logger = MiniLogger.configure
|
138
138
|
|
@@ -148,59 +148,32 @@ class TestMiniLogger < Test::Unit::TestCase
|
|
148
148
|
end
|
149
149
|
|
150
150
|
|
151
|
-
|
151
|
+
must "write messages in diferents log levels" do
|
152
152
|
|
153
153
|
log_file_name = File.join(Dir.tmpdir, 'mini_logger_test.log')
|
154
154
|
test_logger = MiniLogger.configure(:dev=>log_file_name, :level=>:debug)
|
155
155
|
log_file = TailFileHelper.new(log_file_name)
|
156
156
|
|
157
|
-
|
157
|
+
Delorean.time_travel_to(TEST_DATE_TIME)
|
158
|
+
test_logger.debug(TEST_MESSAGE)
|
159
|
+
assert(log_file.get_log_line =~ /^D\, \[1970\-05\-11T00:00:\d{2}\.\d{6} #\d(.+){1} DEBUG \-\- : #{TEST_MESSAGE}/)
|
158
160
|
|
159
|
-
|
161
|
+
Delorean.time_travel_to(TEST_DATE_TIME)
|
162
|
+
test_logger.info(TEST_MESSAGE)
|
163
|
+
assert(log_file.get_log_line =~ /^I\, \[1970\-05\-11T00:00:\d{2}\.\d{6} #\d(.+){1} INFO \-\- : #{TEST_MESSAGE}/)
|
160
164
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
assert(
|
173
|
-
line =~ /^I\, \[\d{4}\-\d{2}\-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6} #\d\] INFO \-\- : #{TEST_INFO_MESSAGE}/,
|
174
|
-
"The line is:'#{line}'"
|
175
|
-
)
|
176
|
-
|
177
|
-
test_logger.warn(TEST_WARN_MESSAGE)
|
178
|
-
|
179
|
-
line = log_file.get_log_line
|
180
|
-
|
181
|
-
assert(
|
182
|
-
line =~ /^W\, \[\d{4}\-\d{2}\-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6} #\d\] WARN \-\- : #{TEST_WARN_MESSAGE}/,
|
183
|
-
"The line is:'#{line}'"
|
184
|
-
)
|
185
|
-
|
186
|
-
test_logger.error(TEST_ERROR_MESSAGE)
|
187
|
-
|
188
|
-
line = log_file.get_log_line
|
189
|
-
|
190
|
-
assert(
|
191
|
-
line =~ /^E\, \[\d{4}\-\d{2}\-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6} #\d\] ERROR \-\- : #{TEST_ERROR_MESSAGE}/,
|
192
|
-
"The line is:'#{line}'"
|
193
|
-
)
|
194
|
-
|
195
|
-
test_logger.fatal(TEST_FATAL_MESSAGE)
|
196
|
-
|
197
|
-
line = log_file.get_log_line
|
198
|
-
|
199
|
-
assert(
|
200
|
-
line =~ /^F\, \[\d{4}\-\d{2}\-\d{2}T\d{2}:\d{2}:\d{2}\.\d{6} #\d\] FATAL \-\- : #{TEST_FATAL_MESSAGE}/,
|
201
|
-
"The line is:'#{line}'"
|
202
|
-
)
|
165
|
+
Delorean.time_travel_to(TEST_DATE_TIME)
|
166
|
+
test_logger.warn(TEST_MESSAGE)
|
167
|
+
assert(log_file.get_log_line =~ /^W\, \[1970\-05\-11T00:00:\d{2}\.\d{6} #\d(.+){1} WARN \-\- : #{TEST_MESSAGE}/)
|
168
|
+
|
169
|
+
Delorean.time_travel_to(TEST_DATE_TIME)
|
170
|
+
test_logger.error(TEST_MESSAGE)
|
171
|
+
assert(log_file.get_log_line =~ /^E\, \[1970\-05\-11T00:00:\d{2}\.\d{6} #\d(.+){1} ERROR \-\- : #{TEST_MESSAGE}/)
|
172
|
+
|
173
|
+
Delorean.time_travel_to(TEST_DATE_TIME)
|
174
|
+
test_logger.fatal(TEST_MESSAGE)
|
175
|
+
assert(log_file.get_log_line =~ /^F\, \[1970\-05\-11T00:00:\d{2}\.\d{6} #\d(.+){1} FATAL \-\- : #{TEST_MESSAGE}/)
|
203
176
|
|
204
|
-
File.delete(
|
177
|
+
File.delete(log_file_name) if File.exist? log_file_name
|
205
178
|
end
|
206
179
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require'test/unit'
|
3
|
+
|
4
|
+
|
5
|
+
module Test::Unit
|
6
|
+
|
7
|
+
class TestCase
|
8
|
+
|
9
|
+
def self.must(name, &block)
|
10
|
+
|
11
|
+
test_name = "test_#{name.gsub(/\s+/,'_')}".to_sym
|
12
|
+
defined = instance_method(test_name) rescue false
|
13
|
+
|
14
|
+
raise "#{test_name} is already defined in #{self}" if defined
|
15
|
+
|
16
|
+
if block_given?
|
17
|
+
define_method(test_name, &block)
|
18
|
+
else
|
19
|
+
define_method(test_name) { flunk "No implementation provided for #{name}" }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-07-
|
12
|
+
date: 2011-07-03 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: jeweler
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152283520 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,21 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
25
|
-
- !ruby/object:Gem::Dependency
|
26
|
-
name: file-tail
|
27
|
-
requirement: &2152469360 !ruby/object:Gem::Requirement
|
28
|
-
none: false
|
29
|
-
requirements:
|
30
|
-
- - ! '>='
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '0'
|
33
|
-
type: :development
|
34
|
-
prerelease: false
|
35
|
-
version_requirements: *2152469360
|
24
|
+
version_requirements: *2152283520
|
36
25
|
- !ruby/object:Gem::Dependency
|
37
26
|
name: rcov
|
38
|
-
requirement: &
|
27
|
+
requirement: &2152281720 !ruby/object:Gem::Requirement
|
39
28
|
none: false
|
40
29
|
requirements:
|
41
30
|
- - ! '>='
|
@@ -43,7 +32,7 @@ dependencies:
|
|
43
32
|
version: '0'
|
44
33
|
type: :development
|
45
34
|
prerelease: false
|
46
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152281720
|
47
36
|
description: A minimal standard Logger wrapper perfect for CLI applications
|
48
37
|
email: javier.juarez@gmail.com
|
49
38
|
executables: []
|
@@ -55,6 +44,7 @@ files:
|
|
55
44
|
- lib/version.rb
|
56
45
|
- test/helpers/tail_file_helper.rb
|
57
46
|
- test/test_mini_logger.rb
|
47
|
+
- test/unit_extensions.rb
|
58
48
|
- README.rdoc
|
59
49
|
homepage: http://github.com/jjuarez/mini_logger
|
60
50
|
licenses:
|