notarius 0.1.0 → 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -3,7 +3,7 @@ Notarius
3
3
 
4
4
  Notarius is a logging library with opinions. The word "notarius" is
5
5
  Latin for "shorthand writer". To this end, Notarius does everything
6
- possible to encourage you to write short useful log messages.
6
+ possible to encourage you to write short useful log messages.
7
7
 
8
8
  * Whitespace is converted to spaces.
9
9
  * Lines are truncated to 140 characters.
@@ -66,7 +66,7 @@ NAME is the string you passed to the `configure` method) and call
66
66
  responds to `:message`, `:backtrace`, or `:inspect`.
67
67
 
68
68
  ```ruby
69
- class Player
69
+ class Player
70
70
  include Notarius::BIG
71
71
 
72
72
  def move direction
@@ -116,7 +116,7 @@ this:
116
116
  level [timestamp] message
117
117
  ! backtrace
118
118
  ! backtrace
119
- ! backtrace
119
+ ! backtrace
120
120
  ```
121
121
 
122
122
  This makes it easy to log exceptions. More importantly, it makes it easy
@@ -137,6 +137,12 @@ intend.
137
137
 
138
138
  Notarius tries to make things easier.
139
139
 
140
+ History
141
+ -------
142
+
143
+ See the {file:roadmap.md} for where this is going, and {file:history.md}
144
+ for where it's been.
145
+
140
146
  License
141
147
  -------
142
148
 
@@ -0,0 +1,44 @@
1
+ ### 0.2.6 / 2012-07-15 ###
2
+
3
+ * 1 minor enhancement
4
+ * Adds a "history.md" file to keep track of changes.
5
+
6
+ ### 0.2.5 / 2012-07-14 ###
7
+
8
+ * 2 minor enhancements
9
+ * Adds a "yard" task for generating documentation.
10
+ * Fleshes out documentation of the public API.
11
+
12
+ ### 0.2.4 / 2012-07-08 ###
13
+
14
+ * 1 minor enhancement
15
+ * Cleans up code to improve readability.
16
+
17
+ ### 0.2.3 / 2012-07-07 ###
18
+
19
+ * 1 bug fix
20
+ * Fixes whitespace handling in severity levels.
21
+
22
+ ### 0.2.2 / 2012-07-05 ###
23
+
24
+ * 1 bug fix
25
+ * Fixes message formatting so each line is tweetable.
26
+
27
+ ### 0.2.1 / 2012-07-04 ###
28
+
29
+ * 2 minor enhancements
30
+ * Adds a "flog" task for checking code complexity.
31
+ * Cleans up code to improve readability.
32
+
33
+ ### 0.2.0 / 2012-07-02 ###
34
+
35
+ * 1 minor enhancement
36
+ * Drops custom exception classes in favor of using RuntimeError.
37
+
38
+ * 1 bug fix
39
+ * Fixes specs so they can run with the "-w" flag without warnings.
40
+
41
+ ### 0.1.0 / 2012-07-01 ###
42
+
43
+ * 1 major enhancement
44
+ * Birthday!
@@ -1,15 +1,20 @@
1
1
  require 'notarius/secretary'
2
2
  require 'notarius/config'
3
- require 'notarius/exception'
4
3
  require 'notarius/version'
5
4
 
5
+ ##
6
+ # Notarius is a logging library with opinions.
7
+
6
8
  module Notarius
7
9
  @configs = {}
8
10
 
9
11
  ##
10
- # Configure logging for the named module.
12
+ # Configures a logging module. If a matching module exists, it will be
13
+ # reconfigured. Otherwise, a new module will be created.
11
14
  #
12
- # @yieldparam log [Config]
15
+ # @param [#to_s] name the module's name
16
+ # @yieldparam log [Config] the module's configuration
17
+ # @return [void]
13
18
  #
14
19
  # @example
15
20
  # Notarius.configure 'BIG' do |log|
@@ -19,13 +24,13 @@ module Notarius
19
24
 
20
25
  def self.configure name, &block
21
26
  name = namespace name
22
- @configs[name] = Config.new if @configs[name].nil?
23
- @configs[name].instance_eval(&block) if block_given?
27
+ @configs[name] ||= Config.new
28
+ block.call @configs[name] if block
24
29
  return if self.const_defined? name
25
30
 
26
31
  mod = Module.new do
27
32
  define_method :log do
28
- @secretary = Secretary.new if @secretary.nil?
33
+ @secretary ||= Secretary.new
29
34
  @secretary.configure Notarius.config(name)
30
35
  @secretary
31
36
  end
@@ -34,9 +39,11 @@ module Notarius
34
39
  end
35
40
 
36
41
  ##
37
- # Return a config with the given name. Validates the config first.
38
- # @return [Config, nil] matching config or +nil+ if none found
39
- # @see Notarius.validate
42
+ # Gets the configuration for a module.
43
+ # @private
44
+ # @param [String] name the module's name
45
+ # @return [Config, nil] the module's configuration or +nil+ if none
46
+ # was found
40
47
 
41
48
  def self.config name
42
49
  validate name
@@ -44,19 +51,18 @@ module Notarius
44
51
  end
45
52
 
46
53
  ##
47
- # Validate a config with the given name.
48
- # @param [String] name name of config to validate
49
- # @raise [Exception] when file is already being logged to
54
+ # Validates a module's configuration.
55
+ # @private
56
+ # @param [String] name the module's name
57
+ # @return [void]
58
+ # @raise [RuntimeError] if the module's file is used by another module
50
59
 
51
60
  def self.validate name
52
61
  config = @configs[name]
53
- if config
62
+ if config && config.file
54
63
  @configs.each do |n, c|
55
- if n != name && c.file && c.file == config.file
56
- message = <<EOF
57
- Notarius::#{name} logs to the same file as Notarius::#{n}.
58
- EOF
59
- raise Notarius::Exception.new message
64
+ if n != name && c.file == config.file
65
+ fail "Notarius::#{name} logs to the same file as Notarius::#{n}."
60
66
  end
61
67
  end
62
68
  end
@@ -64,19 +70,17 @@ EOF
64
70
  private_class_method :validate
65
71
 
66
72
  ##
67
- # Convert an +Object+ to a +String+ that can be used as a namespace.
68
- # This has to generate something that matches Ruby's idea of a
69
- # constant.
70
- # @raise [Exception] when +name+ is empty
71
- # @param [#to_s] name name of the namespace
72
- # @return [String] converted namespace
73
+ # Generates a name that can be used for a module.
74
+ # @private
75
+ # @param [#to_s] name the requested name
76
+ # @return [String] the module's name
77
+ # @raise [RuntimeError] if the requested name is empty
73
78
 
74
79
  def self.namespace name
75
80
  name = name.to_s
76
- if name.empty?
77
- raise Notarius::Exception.new "namespaces can't be empty"
78
- end
79
- name[0, 1].upcase + name[1, name.size]
81
+ fail "namespaces can't be empty" if name.empty?
82
+ name[0] = name[0].capitalize
83
+ name
80
84
  end
81
85
  private_class_method :namespace
82
86
  end
@@ -1,6 +1,16 @@
1
1
  module Notarius
2
+ ##
3
+ # Holds the configuration for a logging module.
4
+
2
5
  class Config
6
+ ##
7
+ # Turn console logging on or off. Default is off.
8
+ # @return [Boolean] whether console logging is enabled
3
9
  attr_accessor :console
10
+
11
+ ##
12
+ # Turn file logging on or off. Default is off.
13
+ # @return [String, nil] the path to the file or +nil+ if off
4
14
  attr_accessor :file
5
15
  end
6
16
  end
@@ -2,18 +2,19 @@ require 'time'
2
2
 
3
3
  module Notarius
4
4
  ##
5
- # Handles formatting of log messages. It's compatable with Ruby's
6
- # +Logger::Formatter+ class, but has its own opinions:
5
+ # Handles formatting of log messages. It's compatable with Ruby's
6
+ # +Logger+ class, but has its own opinions:
7
7
  #
8
8
  # * Whitespace in the message is converted to spaces.
9
- # * Output is truncated to 140 characters.
9
+ # * Output is truncated to 140 characters per line.
10
10
  # * Timestamps are formatted as ISO 8601 in UTC.
11
11
  # * Lines in call stacks are prefixed with !'s.
12
12
  # * Any of the arguments to #call can be nil.
13
13
 
14
14
  class Formatter
15
15
  ##
16
- # This is the interface Ruby's +Logger+ class expects.
16
+ # Generates a formatted log statement. This is the interface Ruby's
17
+ # +Logger+ class expects.
17
18
  # @param [String] severity the severity level of the message
18
19
  # @param [Date] timestamp the timestamp for the message
19
20
  # @param [Object] application unused
@@ -22,51 +23,51 @@ module Notarius
22
23
  # @return [String] formatted as "SEVERITY [timestamp] message\\n"
23
24
 
24
25
  def call severity, timestamp, application, message
25
- result = []
26
- result << format_severity(severity) if severity
27
- result << '[' + format_timestamp(timestamp) + ']' if timestamp
28
- result << format_message(message) if message
29
- make_tweetable(result.join(' ')) + "\n"
26
+ lines = []
27
+ lines << format_message(severity, timestamp, message)
28
+ lines << format_backtrace(message)
29
+ lines.flatten!
30
+ lines.map! { |line| make_tweetable(line) }
31
+ "#{lines.join("\n")}\n"
32
+ end
33
+
34
+
35
+ private
36
+
37
+ def format_message severity, timestamp, message
38
+ severity = format_severity severity
39
+ timestamp = format_timestamp timestamp
40
+ message = parse_message message
41
+ "#{severity} #{timestamp} #{message}".strip
42
+ end
43
+
44
+ def format_backtrace message
45
+ trace = message.respond_to?(:backtrace) ? [message.backtrace] : []
46
+ trace.flatten!
47
+ trace.compact!
48
+ trace.map { |line| "! #{clean_message(line)}" }
30
49
  end
31
50
 
32
51
  def format_severity severity
33
- severity.strip.upcase
52
+ severity.upcase.gsub(/\s+/, '') if severity
34
53
  end
35
- private :format_severity
36
54
 
37
- def format_message message
38
- result = []
39
- if message.respond_to?(:message)
40
- result << message.message
41
- else
42
- result << message
43
- end
44
- if message.respond_to?(:backtrace)
45
- backtrace = [message.backtrace]
46
- backtrace.flatten!
47
- backtrace.compact!
48
- result << backtrace.map { |line| "! %s" % clean_message(line) }
49
- end
50
- result.flatten!
51
- result.map! { |line| clean_message(line) }
52
- result.join("\n")
55
+ def parse_message message
56
+ message = message.message if message.respond_to?(:message)
57
+ clean_message(message || '')
53
58
  end
54
- private :format_message
55
59
 
56
60
  def clean_message message
57
61
  message = message.inspect unless message.kind_of?(String)
58
- message.gsub(/[\t\r\n\s]+/, ' ').strip
62
+ message.strip.gsub(/\s+/, ' ')
59
63
  end
60
- private :clean_message
61
64
 
62
- def format_timestamp timestamp
63
- timestamp.utc.iso8601
65
+ def format_timestamp timestamp
66
+ "[#{timestamp.utc.iso8601}]" if timestamp
64
67
  end
65
- private :format_timestamp
66
68
 
67
69
  def make_tweetable message
68
- message.length > 140 ? message[0, 137] + '...' : message
70
+ message.length > 140 ? "#{message[0, 137]}..." : message
69
71
  end
70
- private :make_tweetable
71
72
  end
72
73
  end
@@ -2,9 +2,12 @@ require 'notarius/formatter'
2
2
  require 'logger'
3
3
 
4
4
  module Notarius
5
+ ##
6
+ # Provides an API for logging modules.
7
+
5
8
  class Secretary
6
9
  ##
7
- # Create a new instance of Secretary.
10
+ # Creates a new instance of a Secretary.
8
11
  # @return [Secretary]
9
12
 
10
13
  def initialize
@@ -13,46 +16,48 @@ module Notarius
13
16
  end
14
17
 
15
18
  ##
16
- # Configure a Secretary.
17
- # @param [Config] config the configuration for this Secretary
18
-
19
+ # Configures a Secretary.
20
+ # @param [Config] config the configuration
21
+ # @return [void]
22
+
19
23
  def configure config
20
- if config.console
21
- add :console, logger(config.console, $stdout)
22
- else
23
- delete :console
24
- end
25
- if config.file
26
- add :file, config.file
27
- else
28
- delete :file
29
- end
24
+ update :console, config.console, $stdout
25
+ update :file, config.file
30
26
  end
31
27
 
32
28
  ##
33
- # Log an informative message. Informative messages show up the log
29
+ # Logs an informative message. Informative messages show up the log
34
30
  # with "INFO" at the start of the line.
31
+ # @param [String, #message, #backtrace, #inspect] message
32
+ # @return [void]
35
33
 
36
34
  def info message
37
35
  log Logger::INFO, message
38
36
  end
39
37
 
40
38
  ##
41
- # Log a warning message. Warning messages show up in the log with
39
+ # Logs a warning message. Warning messages show up in the log with
42
40
  # "WARN" at the start of the line.
41
+ # @param [String, #message, #backtrace, #inspect] message
42
+ # @return [void]
43
43
 
44
44
  def warn message
45
45
  log Logger::WARN, message
46
46
  end
47
47
 
48
48
  ##
49
- # Log an error message. Error messages show up in the log with
49
+ # Logs an error message. Error messages show up in the log with
50
50
  # "ERROR" at the start of the line.
51
+ # @param [String, #message, #backtrace, #inspect] message
52
+ # @return [void]
51
53
 
52
54
  def error message
53
55
  log Logger::ERROR, message
54
56
  end
55
57
 
58
+
59
+ private
60
+
56
61
  def log severity, message
57
62
  @loggers.each do |key, logger|
58
63
  if message != @messages[key]
@@ -61,28 +66,32 @@ module Notarius
61
66
  end
62
67
  end
63
68
  end
64
- private :log
69
+
70
+ def update key, stream, default = nil
71
+ if stream
72
+ add key, logger(stream, default)
73
+ else
74
+ delete key
75
+ end
76
+ end
65
77
 
66
78
  def add key, stream
67
79
  @loggers[key] = Logger.new stream
68
80
  @loggers[key].formatter = Formatter.new
69
81
  end
70
- private :add
71
82
 
72
83
  def delete key
73
84
  logger = @loggers.delete(key)
74
- logger.close rescue nil
85
+ logger.close unless logger.nil?
75
86
  end
76
- private :delete
77
87
 
78
88
  def logger *args
79
89
  args.find { |arg| loggable?(arg) }
80
90
  end
81
- private :logger
82
91
 
83
92
  def loggable? stream
84
- stream.respond_to?(:write) && stream.respond_to?(:close)
93
+ io = stream.respond_to?(:write) && stream.respond_to?(:close)
94
+ io || stream.kind_of?(String)
85
95
  end
86
- private :loggable?
87
96
  end
88
97
  end
@@ -2,5 +2,5 @@ module Notarius
2
2
  ##
3
3
  # Semantic versioning makes life easier.
4
4
 
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.6'
6
6
  end
@@ -10,7 +10,9 @@ desc 'Run specs.'
10
10
  task :default => :spec
11
11
 
12
12
  desc 'Run specs.'
13
- RSpec::Core::RakeTask.new :spec
13
+ RSpec::Core::RakeTask.new :spec do |t|
14
+ t.ruby_opts = ['-w']
15
+ end
14
16
 
15
17
  desc 'Generate SimpleCov spec coverage.'
16
18
  RSpec::Core::RakeTask.new :coverage do |t|
@@ -22,16 +24,38 @@ task :build do
22
24
  sh "gem build #{name}.gemspec"
23
25
  end
24
26
 
25
- desc 'Install the gem'
27
+ desc 'Install the gem.'
26
28
  task :install do
27
29
  sh "gem install ./#{name}-#{version}.gem"
28
30
  end
29
31
 
30
- desc 'Uninstall the gem'
32
+ desc 'Uninstall the gem.'
31
33
  task :uninstall do
32
34
  sh "gem uninstall #{name}"
33
35
  end
34
36
 
37
+ begin
38
+ gem 'flog'
39
+ desc 'Flog the code.'
40
+ task :flog, [:flags] do |t, args|
41
+ flags = args[:flags] ? "-#{args[:flags]}" : ''
42
+ files = FileList['lib/**/*.rb'].join(' ')
43
+ sh "flog #{flags} #{files}"
44
+ end
45
+ rescue Gem::LoadError
46
+ end
47
+
48
+ begin
49
+ gem 'yard'
50
+ desc 'Generate documentation with YARD.'
51
+ task :yard, [:options] => :clean do |t, args|
52
+ options = args[:options] || ''
53
+ options += ' --reload' if options.include? 'server'
54
+ sh "yard #{options}"
55
+ end
56
+ rescue Gem::LoadError
57
+ end
58
+
35
59
  def name
36
60
  @name ||= Dir['*.gemspec'].first.split('.').first
37
61
  end
@@ -0,0 +1,43 @@
1
+ Notarius
2
+ ========
3
+
4
+ Notarius releases are named after Latin [book sizes][]. We go from
5
+ something large and course, _folio_, to someting fine and specific,
6
+ _duodecimo_. In a similar fashion to the [git flow][] branching model,
7
+ releases are unversioned. This is a general timeline for what gets
8
+ worked on when.
9
+
10
+ The current release, version 0.2.6, corresponds to the _quarto_ stage.
11
+
12
+ folio
13
+ -----
14
+
15
+ Initial API design, including configuration syntax and how namespaces
16
+ work with each other. Support for logging to the console (STDOUT) and
17
+ logging to a file. Basic documentation in YARD, and most code covered
18
+ in RSpec.
19
+
20
+ quarto
21
+ ------
22
+
23
+ Clean up of YARD and RSpec documentation so it looks and feels
24
+ consistant. Most code is documented. Tightening of specs to reduce code
25
+ duplication and cover more edge cases. Migration of code to private
26
+ classes and methods to keep the API clean.
27
+
28
+ octavo
29
+ ------
30
+
31
+ Elmination of Ruby headers in log files. All code is documented. Support
32
+ for setting logging level per logger. Ability to log blocks with delayed
33
+ evaluation. Stripping of color codes from file logging.
34
+
35
+ duodecimo
36
+ ---------
37
+
38
+ Syslog support, both local and remote. Ability to specify stream (STDOUT
39
+ or STDERR) when logging to console. Handle internationalization (multi
40
+ byte log messages) nicely.
41
+
42
+ [book sizes]: http://en.wikipedia.org/wiki/Book_size "Book size on Wikipedia"
43
+ [git flow]: http://nvie.com/posts/a-successful-git-branching-model/ "A successful Git branching model >> nvie.com"
@@ -14,7 +14,7 @@ describe Notarius::Config do
14
14
  it 'lets you configure a console' do
15
15
  config.should respond_to(:console=)
16
16
  end
17
-
17
+
18
18
  it 'lets you configure a file' do
19
19
  config.should respond_to(:file=)
20
20
  end
@@ -1,9 +1,14 @@
1
1
  require 'notarius/formatter'
2
2
 
3
3
  describe Notarius::Formatter do
4
- describe 'call' do
4
+ describe '#call' do
5
5
  let(:formatter) { Notarius::Formatter.new }
6
6
 
7
+ it 'allows all arguments to be nil' do
8
+ message = formatter.call(nil, nil, nil, nil)
9
+ message.should == "\n"
10
+ end
11
+
7
12
  it 'converts whitespace to spaces' do
8
13
  message = "\sMessage\r\nwith\twhitespace "
9
14
  message = formatter.call(nil, nil, nil, message)
@@ -21,9 +26,10 @@ describe Notarius::Formatter do
21
26
  message.should == "INFO\n"
22
27
  end
23
28
 
24
- it 'removes extra whitespace from severity' do
25
- message = formatter.call("\swarn\s", nil, nil, nil)
26
- message.should == "WARN\n"
29
+ it 'removes whitespace from severity' do
30
+ timestamp = Time.parse('2012-07-07 16:20:29 -0400')
31
+ message = formatter.call("\s\rWA\tRN\n", timestamp, nil, nil)
32
+ message.should == "WARN [2012-07-07T20:20:29Z]\n"
27
33
  end
28
34
 
29
35
  it 'ignores program name field' do
@@ -37,9 +43,30 @@ describe Notarius::Formatter do
37
43
  be more than 140 characters so that Notarius can trim it
38
44
  down to something more reasonable in length.
39
45
  EOF
40
- message.length.should > 140
41
- message = formatter.call(nil, nil, nil, message)
42
- message.strip.length.should == 140
46
+ message.should have_at_least(141).characters
47
+ message = formatter.call('INFO', nil, nil, message)
48
+ message.strip.should have(140).characters
49
+ end
50
+
51
+ it 'makes exceptions tweetable' do
52
+ message = <<-EOF
53
+ This is a really, really long message that needs to
54
+ be more than 140 characters so that Notarius can trim it
55
+ down to something more reasonable in length.
56
+ EOF
57
+ message.should have_at_least(141).characters
58
+
59
+ backtrace = <<-EOF
60
+ This is a really, really long backtrace that needs to
61
+ be more than 140 characters so that Notarius can trim it
62
+ down to something more reasonable in length.
63
+ EOF
64
+ backtrace.should have_at_least(141).characters
65
+
66
+ exception = Exception.new(message)
67
+ exception.set_backtrace [backtrace]
68
+ lines = formatter.call('INFO', nil, nil, exception).split("\n")
69
+ lines.each { |line| line.should have(140).characters }
43
70
  end
44
71
 
45
72
  it 'formats messages as "LEVEL [timestamp] message\n"' do
@@ -55,11 +82,9 @@ describe Notarius::Formatter do
55
82
 
56
83
  it 'formats exceptions nicely' do
57
84
  exception = Exception.new('message')
58
- exception.set_backtrace ['trace this line', 'back to here']
85
+ exception.set_backtrace ['trace this line', 'back to here']
59
86
  lines = formatter.call(nil, nil, nil, exception).split("\n")
60
- lines[0].should == 'message'
61
- lines[1].should == '! trace this line'
62
- lines[2].should == '! back to here'
87
+ lines.should == ['message', '! trace this line', '! back to here']
63
88
  end
64
89
 
65
90
  it 'formats objects nicely' do
@@ -99,8 +124,7 @@ describe Notarius::Formatter do
99
124
  end
100
125
  end
101
126
  lines = formatter.call(nil, nil, nil, exception.new).split("\n")
102
- lines[0].should == 'message'
103
- lines[1].should == '! backtrace'
127
+ lines.should == ['message', '! backtrace']
104
128
  end
105
129
  end
106
130
  end
@@ -2,7 +2,7 @@ require 'notarius'
2
2
  require 'tempfile'
3
3
 
4
4
  describe Notarius do
5
- def tempfiles *prefixes
5
+ def tempfiles *prefixes
6
6
  files = prefixes.map { |prefix| Tempfile.new prefix }
7
7
  begin
8
8
  paths = files.map { |file| file.path }
@@ -91,7 +91,7 @@ describe Notarius do
91
91
  end
92
92
  end
93
93
 
94
- expect { monster.new }.to raise_error(Notarius::Exception)
94
+ expect { monster.new }.to raise_error(RuntimeError)
95
95
  end
96
96
  end
97
97
 
@@ -104,13 +104,13 @@ describe Notarius do
104
104
  it 'throws an error if a namespace is empty' do
105
105
  expect do
106
106
  Notarius.configure ''
107
- end.to raise_error(Notarius::Exception)
107
+ end.to raise_error(RuntimeError)
108
108
  end
109
109
 
110
110
  it 'throws an error if a namespace is nil' do
111
111
  expect do
112
112
  Notarius.configure nil
113
- end.to raise_error(Notarius::Exception)
113
+ end.to raise_error(RuntimeError)
114
114
  end
115
115
  end
116
116
  end
@@ -1,7 +1,12 @@
1
1
  require 'notarius/secretary'
2
+ require 'notarius/config'
2
3
  require 'stringio'
3
4
 
4
5
  describe Notarius::Secretary do
6
+ def match_message level, message
7
+ match(/^#{level.upcase} \[[^\]]+\] #{message}\n$/)
8
+ end
9
+
5
10
  describe 'logging' do
6
11
  let(:logger) { StringIO.new }
7
12
  let(:secretary) do
@@ -12,24 +17,17 @@ describe Notarius::Secretary do
12
17
  s
13
18
  end
14
19
 
15
- before :each do
20
+ before do
16
21
  logger.truncate 0
17
22
  logger.rewind
18
23
  end
19
24
 
20
- it 'can log info messages' do
21
- secretary.info 'info message'
22
- logger.string.should match(/^INFO \[[^\]]+\] info message\n$/)
23
- end
24
-
25
- it 'can log warning messages' do
26
- secretary.warn 'warning message'
27
- logger.string.should match(/^WARN \[[^\]]+\] warning message\n$/)
28
- end
29
-
30
- it 'can log error messages' do
31
- secretary.error 'error message'
32
- logger.string.should match(/^ERROR \[[^\]]+\] error message\n$/)
25
+ %w{info warn error}.each do |level|
26
+ it "can log #{level} messages" do
27
+ message = "#{level} message"
28
+ secretary.send(level.to_sym, message)
29
+ logger.string.should match_message(level, message)
30
+ end
33
31
  end
34
32
  end
35
33
 
@@ -46,8 +44,8 @@ describe Notarius::Secretary do
46
44
  secretary.configure config
47
45
 
48
46
  secretary.info 'info message'
49
- io1.string.should match(/^INFO \[[^\]]+\] info message\n$/)
50
- io2.string.should match(/^INFO \[[^\]]+\] info message\n$/)
47
+ io1.string.should match_message(:INFO, 'info message')
48
+ io2.string.should match_message(:INFO, 'info message')
51
49
  end
52
50
 
53
51
  it 'defaults console to stdout' do
@@ -62,10 +60,10 @@ describe Notarius::Secretary do
62
60
  secretary.configure config
63
61
  secretary.info 'message'
64
62
  ensure
65
- $stdout = stdout
63
+ $stdout = stdout
66
64
  end
67
65
 
68
- output.string.should match(/^INFO \[[^\]]+\] message\n$/)
66
+ output.string.should match_message(:INFO, 'message')
69
67
  end
70
68
 
71
69
  it 'removes a logger when no longer referenced' do
@@ -79,25 +77,25 @@ describe Notarius::Secretary do
79
77
  secretary = Notarius::Secretary.new
80
78
  secretary.configure config1
81
79
  secretary.info 'noodles'
82
- io1.string.should match(/^INFO \[[^\]]+\] noodles\n$/)
83
- io2.string.should match(/^INFO \[[^\]]+\] noodles\n$/)
80
+ io1.string.should match_message(:INFO, 'noodles')
81
+ io2.string.should match_message(:INFO, 'noodles')
84
82
 
85
- secretary.configure Notarius::Config.new
83
+ secretary.configure Notarius::Config.new
86
84
  secretary.info 'pasta'
87
- io1.string.should_not match(/^INFO \[[^\]]+\] pasta\n$/)
88
- io2.string.should_not match(/^INFO \[[^\]]+\] pasta\n$/)
85
+ io1.string.should_not match_message(:INFO, 'pasta')
86
+ io2.string.should_not match_message(:INFO, 'pasta')
89
87
  end
90
88
 
91
89
  it 'closes a logger when it removes it' do
92
90
  config = Notarius::Config.new
93
- config.console = StringIO.new
91
+ config.console = StringIO.new
94
92
 
95
93
  secretary = Notarius::Secretary.new
96
94
  secretary.configure config
97
95
  secretary.info 'noodles'
98
- config.console.string.should match(/^INFO \[[^\]]+\] noodles\n$/)
96
+ config.console.string.should match_message(:INFO, 'noodles')
99
97
 
100
- secretary.configure Notarius::Config.new
98
+ secretary.configure Notarius::Config.new
101
99
  secretary.info 'pasta'
102
100
  config.console.should be_closed
103
101
  end
@@ -122,7 +120,7 @@ describe Notarius::Secretary do
122
120
 
123
121
  secretary.info 'same message'
124
122
 
125
- io1.string.should_not match(/^INFO \[[^\]]+\] same message\n$/)
126
- io2.string.should match(/^INFO \[[^\]]+\] same message\n$/)
123
+ io1.string.should_not match_message(:INFO, 'same message')
124
+ io2.string.should match_message(:INFO, 'same message')
127
125
  end
128
126
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: notarius
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-02 00:00:00.000000000 Z
12
+ date: 2012-07-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -73,14 +73,15 @@ extra_rdoc_files: []
73
73
  files:
74
74
  - LICENSE.md
75
75
  - README.md
76
+ - history.md
76
77
  - lib/notarius.rb
77
78
  - lib/notarius/config.rb
78
- - lib/notarius/exception.rb
79
79
  - lib/notarius/formatter.rb
80
80
  - lib/notarius/secretary.rb
81
81
  - lib/notarius/version.rb
82
82
  - notarius.gemspec
83
83
  - rakefile.rb
84
+ - roadmap.md
84
85
  - spec/config_spec.rb
85
86
  - spec/formatter_spec.rb
86
87
  - spec/notarius_spec.rb
@@ -1,4 +0,0 @@
1
- module Notarius
2
- class Exception < ::Exception
3
- end
4
- end