logger-application 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b5318c8d1ae14ac5f406e3893bdb700f8793d24
4
- data.tar.gz: 46662688e0c14845c0578d0802df89cd4a024eac
3
+ metadata.gz: 497e3190592c9b159503d6a61f8aabd96ed65da2
4
+ data.tar.gz: 54bda7e810ab58a54bcfa36e0385d36e09f9f389
5
5
  SHA512:
6
- metadata.gz: fe0bee8f6ae57d925e28b3aa4ef9665bcc2c832f4e5327fa89100af3e3940aa610372d2a300246283c4b882a8b04de6f5f027fac5b221237418678c2cc557ca3
7
- data.tar.gz: 818a73bd5d68588ff3e3c2f052ba5d66ce0a70750ddc7f25ec85c08ec5a634db2a6b23c660de02cedca43d001d6a06a85fa5db12203e73feafd0015695e6cc07
6
+ metadata.gz: b21b3d8e38a5928538f19bb913bdffefa29849c5ed8874ee651683e3cdd889f49e004c033586fd70e42743f02a5e31065a4ffe643e4bac2ab25976dc70296d9f
7
+ data.tar.gz: eaf0ccfc4c2a9cb33a06bf9c909954119ff1bac71f897635b7a7ed86b77e39d820a9e261ef9e49aee3336d16ade3871fbb26814842117d482cc218d9caa238de
@@ -5,4 +5,4 @@ rvm:
5
5
  - 2.1
6
6
  - ruby-head
7
7
 
8
- script: bundle exec rake test
8
+ script: bundle exec rake test spec
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Logger::Application
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/logger-application.png)](http://badge.fury.io/rb/logger-application)
4
+ [![Build Status](https://secure.travis-ci.org/hsbt/logger-application.png)](http://travis-ci.org/hsbt/logger-application)
5
+
3
6
  ## Description
4
7
 
5
8
  Add logging support to your application.
data/Rakefile CHANGED
@@ -1,7 +1,12 @@
1
1
  require 'rake'
2
2
  require 'rake/testtask'
3
+ require 'rspec/core/rake_task'
3
4
  require "bundler/gem_tasks"
4
5
 
5
6
  Rake::TestTask.new do |t|
6
7
  t.test_files = Dir.glob('test/**/test_*.rb')
7
8
  end
9
+
10
+ RSpec::Core::RakeTask.new(:spec) do |t|
11
+ t.pattern = "spec/**/*_spec.rb"
12
+ end
@@ -1,7 +1,7 @@
1
1
  require 'logger'
2
2
  require "logger/application/version"
3
3
 
4
- module Logger
4
+ class Logger
5
5
  #
6
6
  # == Description
7
7
  #
@@ -1,5 +1,5 @@
1
1
  class Logger
2
2
  class Application
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -21,4 +21,6 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.6"
22
22
  spec.add_development_dependency "rake"
23
23
  spec.add_development_dependency "test-unit"
24
+ spec.add_development_dependency "rspec", "~> 2.14.1"
25
+ spec.add_development_dependency "mspec"
24
26
  end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Logger::Application#level=" do
4
+ before :each do
5
+ @file_path = tmp("test_log.log")
6
+ @log_file = File.open(@file_path, "w+")
7
+ @app = LoggerSpecs::TestApp.new("TestApp", @log_file)
8
+
9
+ end
10
+
11
+ after :each do
12
+ @log_file.close unless @log_file.closed?
13
+ rm_r @file_path
14
+ end
15
+
16
+ it "sets the logging threshold" do
17
+ @app.level = Logger::ERROR
18
+ @app.start
19
+ @app.log(Logger::WARN, "Don't show me")
20
+ @app.log(Logger::ERROR, "Show me")
21
+ @log_file.rewind
22
+ messages = @log_file.readlines
23
+ messages.length.should == 1
24
+ LoggerSpecs::strip_date(messages.first).should == "ERROR -- TestApp: Show me\n"
25
+ end
26
+
27
+ it "can set the threshold to unknown values" do
28
+ @app.level = 10
29
+ @app.start
30
+ @app.log(Logger::INFO, "Info message")
31
+ @app.log(Logger::DEBUG, "Debug message")
32
+ @app.log(Logger::WARN, "Warn message")
33
+ @app.log(Logger::ERROR, "Error message")
34
+ @app.log(Logger::FATAL, "Fatal message")
35
+ @log_file.rewind
36
+ @log_file.readlines.should be_empty
37
+ end
38
+ end
@@ -0,0 +1,73 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Logger::Application#log" do
4
+ before :each do
5
+ @file_path = tmp("test_log.log")
6
+ @log_file = File.open(@file_path, "w+")
7
+ @app = LoggerSpecs::TestApp.new("TestApp", @log_file)
8
+ @app.start
9
+ end
10
+
11
+ after :each do
12
+ @log_file.close unless @log_file.closed?
13
+ rm_r @file_path
14
+ end
15
+
16
+ it "logs a message" do
17
+ @app.log(Logger::WARN, "Test message")
18
+ @log_file.rewind
19
+ message = @log_file.readlines.last
20
+ LoggerSpecs::strip_date(message).should == "WARN -- TestApp: Test message\n"
21
+ end
22
+
23
+ it "receives a severity" do
24
+ @app.log(Logger::INFO, "Info message")
25
+ @app.log(Logger::DEBUG, "Debug message")
26
+ @app.log(Logger::WARN, "Warn message")
27
+ @app.log(Logger::ERROR, "Error message")
28
+ @app.log(Logger::FATAL, "Fatal message")
29
+ @log_file.rewind
30
+ messages = @log_file.readlines[3..-1] # remove default messages
31
+
32
+ LoggerSpecs::strip_date(messages[0]).should == "INFO -- TestApp: Info message\n"
33
+ LoggerSpecs::strip_date(messages[1]).should == "DEBUG -- TestApp: Debug message\n"
34
+ LoggerSpecs::strip_date(messages[2]).should == "WARN -- TestApp: Warn message\n"
35
+ LoggerSpecs::strip_date(messages[3]).should == "ERROR -- TestApp: Error message\n"
36
+ LoggerSpecs::strip_date(messages[4]).should == "FATAL -- TestApp: Fatal message\n"
37
+ end
38
+
39
+ it "uses app name for Application Name" do
40
+ @app.log(Logger::INFO, "Info message")
41
+ @log_file.rewind
42
+ test_message = @log_file.readlines.last
43
+ Regexp.new(/TestApp/).should =~ LoggerSpecs::strip_date(test_message)
44
+ end
45
+
46
+ it "receives a block and calls it if message is nil" do
47
+ temp = 0
48
+ @app.log(Logger::INFO, nil) { temp = 1 }
49
+ temp.should == 1
50
+ end
51
+ end
52
+
53
+ describe "Logger::Application#log=" do
54
+ before :each do
55
+ @file_path = tmp("test_log.log")
56
+ @log_file = File.open(@file_path, "w+")
57
+ @app = LoggerSpecs::TestApp.new("TestApp", @log_file)
58
+ @app.start
59
+ end
60
+
61
+ after :all do
62
+ if @log_file
63
+ @log_file.close
64
+ rm_r @file_path
65
+ end
66
+ end
67
+
68
+ it "sets the log device" do
69
+ regex = /STDERR Message/
70
+ @app.log = STDERR
71
+ lambda { @app.log(Logger::WARN, "STDERR Message") }.should output_to_fd(regex, STDERR)
72
+ end
73
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Logger::Application.new" do
4
+ before :each do
5
+ @file_path = tmp("test_log.log")
6
+ @log_file = File.open(@file_path, "w+")
7
+ end
8
+
9
+ after :each do
10
+ @log_file.close unless @log_file.closed?
11
+ rm_r @file_path
12
+ end
13
+
14
+ it "starts the logger on a new application" do
15
+ LoggerSpecs::TestApp.new("TestApp", @log_file).start
16
+ @log_file.rewind # go back to the beginning to read the contents
17
+
18
+ first, second, third = @log_file.readlines
19
+ LoggerSpecs::strip_date(first).should == "INFO -- TestApp: Start of TestApp.\n"
20
+ LoggerSpecs::strip_date(second).should == "WARN -- TestApp: Test log message\n"
21
+ LoggerSpecs::strip_date(third).should == "INFO -- TestApp: End of TestApp. (status: true)\n"
22
+ end
23
+
24
+ it "defaults application name to ''" do
25
+ LoggerSpecs::TestApp.new(nil, @log_file).start
26
+ @log_file.rewind
27
+
28
+ first, second, third = @log_file.readlines
29
+ LoggerSpecs::strip_date(first).should == "INFO -- : Start of .\n"
30
+ LoggerSpecs::strip_date(second).should == "WARN -- : Test log message\n"
31
+ LoggerSpecs::strip_date(third).should == "INFO -- : End of . (status: true)\n"
32
+ end
33
+
34
+ it "defaults logs to STDERR" do
35
+ regex = /INFO.*WARN.*INFO.*/m
36
+ lambda { LoggerSpecs::TestApp.new(nil, nil).start }.should output_to_fd(regex, STDERR)
37
+ @log_file.rewind
38
+ end
39
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Logger::Application#set_log"do
4
+ before :each do
5
+ @file_path = tmp("test_log.log")
6
+ @log_file = File.open(@file_path, "w+")
7
+ @app = LoggerSpecs::TestApp.new("TestApp", @log_file)
8
+ end
9
+
10
+ after :each do
11
+ @log_file.close unless @log_file.closed?
12
+ rm_r @file_path
13
+ end
14
+
15
+ it "sets the log device for the logger" do
16
+ regex = /STDERR Message/
17
+ @app.set_log(STDERR)
18
+ lambda { @app.log(Logger::WARN, "STDERR Message") }.should output_to_fd(regex, STDERR)
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+ require 'logger/application'
2
+ require 'mspec/matchers/output_to_fd'
3
+ require 'tempfile'
4
+ require 'fileutils'
5
+
6
+ include FileUtils
7
+
8
+ def tmp(path)
9
+ Tempfile.create(path)
10
+ end
11
+
12
+ module LoggerSpecs
13
+
14
+ def self.strip_date(str)
15
+ str.gsub(/[A-Z].*\[.*\]/, "").lstrip
16
+ end
17
+
18
+ class TestApp < Logger::Application
19
+ def initialize(appname, log_file=nil)
20
+ super(appname)
21
+ self.set_log(log_file) if log_file
22
+ end
23
+
24
+ def run
25
+ log(WARN, "Test log message")
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Logger::Application#start" do
4
+ before :each do
5
+ @file_path = tmp("test_log.log")
6
+ @log_file = File.open(@file_path, "w+")
7
+ @app = LoggerSpecs::TestApp.new("TestApp", @log_file)
8
+ end
9
+
10
+ after :each do
11
+ @log_file.close unless @log_file.closed?
12
+ rm_r @file_path
13
+ end
14
+
15
+
16
+ it "starts the application logging start/end messages" do
17
+ @app.start
18
+ @log_file.rewind
19
+ app_start, discard, app_end = @log_file.readlines
20
+ LoggerSpecs::strip_date(app_start).should == "INFO -- TestApp: Start of TestApp.\n"
21
+ LoggerSpecs::strip_date(app_end).should == "INFO -- TestApp: End of TestApp. (status: true)\n"
22
+ end
23
+
24
+ it "returns the status code" do
25
+ code = @app.start
26
+ @log_file.rewind
27
+ app_end = @log_file.readlines.last
28
+ /true/.should =~ LoggerSpecs::strip_date(app_end)
29
+ code.should == true
30
+ end
31
+
32
+ end
@@ -1,6 +1,6 @@
1
1
  # coding: US-ASCII
2
2
  require 'test/unit'
3
- require 'logger'
3
+ require 'logger/application'
4
4
  require 'tempfile'
5
5
 
6
6
  class TestLoggerApplication < Test::Unit::TestCase
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logger-application
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - SHIBATA Hiroshi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-02 00:00:00.000000000 Z
11
+ date: 2014-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.14.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.14.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: mspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  description: Add logging support to your application.
56
84
  email:
57
85
  - hsbt@ruby-lang.org
@@ -70,6 +98,12 @@ files:
70
98
  - lib/logger/application.rb
71
99
  - lib/logger/application/version.rb
72
100
  - logger-application.gemspec
101
+ - spec/level_spec.rb
102
+ - spec/log_spec.rb
103
+ - spec/new_spec.rb
104
+ - spec/set_log_spec.rb
105
+ - spec/spec_helper.rb
106
+ - spec/start_spec.rb
73
107
  - test/test_application.rb
74
108
  homepage: ''
75
109
  licenses:
@@ -96,5 +130,11 @@ signing_key:
96
130
  specification_version: 4
97
131
  summary: Add logging support to your application.
98
132
  test_files:
133
+ - spec/level_spec.rb
134
+ - spec/log_spec.rb
135
+ - spec/new_spec.rb
136
+ - spec/set_log_spec.rb
137
+ - spec/spec_helper.rb
138
+ - spec/start_spec.rb
99
139
  - test/test_application.rb
100
140
  has_rdoc: