diff options
Diffstat (limited to 'spec/ruby/library/logger')
| -rw-r--r-- | spec/ruby/library/logger/device/close_spec.rb | 6 | ||||
| -rw-r--r-- | spec/ruby/library/logger/device/new_spec.rb | 18 | ||||
| -rw-r--r-- | spec/ruby/library/logger/device/write_spec.rb | 6 | ||||
| -rw-r--r-- | spec/ruby/library/logger/logger/add_spec.rb | 16 | ||||
| -rw-r--r-- | spec/ruby/library/logger/logger/close_spec.rb | 6 | ||||
| -rw-r--r-- | spec/ruby/library/logger/logger/datetime_format_spec.rb | 6 | ||||
| -rw-r--r-- | spec/ruby/library/logger/logger/debug_spec.rb | 8 | ||||
| -rw-r--r-- | spec/ruby/library/logger/logger/error_spec.rb | 8 | ||||
| -rw-r--r-- | spec/ruby/library/logger/logger/fatal_spec.rb | 8 | ||||
| -rw-r--r-- | spec/ruby/library/logger/logger/info_spec.rb | 8 | ||||
| -rw-r--r-- | spec/ruby/library/logger/logger/new_spec.rb | 118 | ||||
| -rw-r--r-- | spec/ruby/library/logger/logger/unknown_spec.rb | 6 | ||||
| -rw-r--r-- | spec/ruby/library/logger/logger/warn_spec.rb | 8 | ||||
| -rw-r--r-- | spec/ruby/library/logger/severity_spec.rb | 2 |
14 files changed, 111 insertions, 113 deletions
diff --git a/spec/ruby/library/logger/device/close_spec.rb b/spec/ruby/library/logger/device/close_spec.rb index 777b20baf0..1db5d582a7 100644 --- a/spec/ruby/library/logger/device/close_spec.rb +++ b/spec/ruby/library/logger/device/close_spec.rb @@ -1,5 +1,5 @@ -require File.expand_path('../../../../spec_helper', __FILE__) -require File.expand_path('../../fixtures/common', __FILE__) +require_relative '../../../spec_helper' +require_relative '../fixtures/common' describe "Logger::LogDevice#close" do before :each do @@ -17,6 +17,6 @@ describe "Logger::LogDevice#close" do it "closes the LogDevice's stream" do @device.close - lambda { @device.write("Test") }.should complain(/\Alog writing failed\./) + -> { @device.write("Test") }.should complain(/\Alog shifting failed\./) end end diff --git a/spec/ruby/library/logger/device/new_spec.rb b/spec/ruby/library/logger/device/new_spec.rb index 0e08b743ed..c943e7fbe2 100644 --- a/spec/ruby/library/logger/device/new_spec.rb +++ b/spec/ruby/library/logger/device/new_spec.rb @@ -1,5 +1,5 @@ -require File.expand_path('../../../../spec_helper', __FILE__) -require File.expand_path('../../fixtures/common', __FILE__) +require_relative '../../../spec_helper' +require_relative '../fixtures/common' describe "Logger::LogDevice#new" do before :each do @@ -14,11 +14,11 @@ describe "Logger::LogDevice#new" do it "creates a new log device" do l = Logger::LogDevice.new(@log_file) - l.dev.should be_kind_of(File) + l.dev.should.is_a?(File) end it "receives an IO object to log there as first argument" do - @log_file.should be_kind_of(IO) + @log_file.should.is_a?(IO) l = Logger::LogDevice.new(@log_file) l.write("foo") @log_file.rewind @@ -31,17 +31,17 @@ describe "Logger::LogDevice#new" do l.write("Test message") l.close - File.exist?(path).should be_true + File.should.exist?(path) File.open(path) do |f| - f.readlines.should_not be_empty + f.readlines.should_not.empty? end rm_r path end it "receives options via a hash as second argument" do - lambda { Logger::LogDevice.new(STDERR, - { shift_age: 8, shift_size: 10 - })}.should_not raise_error + -> { + Logger::LogDevice.new(STDERR, shift_age: 8, shift_size: 10) + }.should_not.raise end end diff --git a/spec/ruby/library/logger/device/write_spec.rb b/spec/ruby/library/logger/device/write_spec.rb index e3ddd61b1f..87ecf2ad6a 100644 --- a/spec/ruby/library/logger/device/write_spec.rb +++ b/spec/ruby/library/logger/device/write_spec.rb @@ -1,5 +1,5 @@ -require File.expand_path('../../../../spec_helper', __FILE__) -require File.expand_path('../../fixtures/common', __FILE__) +require_relative '../../../spec_helper' +require_relative '../fixtures/common' describe "Logger::LogDevice#write" do before :each do @@ -37,6 +37,6 @@ describe "Logger::LogDevice#write" do it "fails if the device is already closed" do @device.close - lambda { @device.write "foo" }.should complain(/\Alog writing failed\./) + -> { @device.write "foo" }.should complain(/\Alog shifting failed\./) end end diff --git a/spec/ruby/library/logger/logger/add_spec.rb b/spec/ruby/library/logger/logger/add_spec.rb index 235247e9e8..98ac88f64f 100644 --- a/spec/ruby/library/logger/logger/add_spec.rb +++ b/spec/ruby/library/logger/logger/add_spec.rb @@ -1,5 +1,5 @@ -require File.expand_path('../../../../spec_helper', __FILE__) -require File.expand_path('../../fixtures/common', __FILE__) +require_relative '../../../spec_helper' +require_relative '../fixtures/common' describe "Logger#add" do before :each do @@ -52,30 +52,30 @@ describe "Logger#add" do end it "receives a block" do - lambda { + -> { @logger.log(nil, "test", "TestApp") do 1+1 end - }.should_not raise_error + }.should_not.raise end it "calls the block if message is nil" do temp = 0 - lambda { + -> { @logger.log(nil, nil, "TestApp") do temp = 1+1 end - }.should_not raise_error + }.should_not.raise temp.should == 2 end it "ignores the block if the message is not nil" do temp = 0 - lambda { + -> { @logger.log(nil, "not nil", "TestApp") do temp = 1+1 end - }.should_not raise_error + }.should_not.raise temp.should == 0 end end diff --git a/spec/ruby/library/logger/logger/close_spec.rb b/spec/ruby/library/logger/logger/close_spec.rb index a4c006150b..81aac2a6cd 100644 --- a/spec/ruby/library/logger/logger/close_spec.rb +++ b/spec/ruby/library/logger/logger/close_spec.rb @@ -1,5 +1,5 @@ -require File.expand_path('../../../../spec_helper', __FILE__) -require File.expand_path('../../fixtures/common', __FILE__) +require_relative '../../../spec_helper' +require_relative '../fixtures/common' describe "Logger#close" do before :each do @@ -15,6 +15,6 @@ describe "Logger#close" do it "closes the logging device" do @logger.close - lambda { @logger.add(nil, "Foo") }.should complain(/\Alog writing failed\./) + -> { @logger.add(nil, "Foo") }.should complain(/\Alog writing failed\./) end end diff --git a/spec/ruby/library/logger/logger/datetime_format_spec.rb b/spec/ruby/library/logger/logger/datetime_format_spec.rb index 2bc1f867c3..75a7f6cc03 100644 --- a/spec/ruby/library/logger/logger/datetime_format_spec.rb +++ b/spec/ruby/library/logger/logger/datetime_format_spec.rb @@ -1,5 +1,5 @@ -require File.expand_path('../../../../spec_helper', __FILE__) -require File.expand_path('../../fixtures/common', __FILE__) +require_relative '../../../spec_helper' +require_relative '../fixtures/common' describe "Logger#datetime_format" do before :each do @@ -49,7 +49,7 @@ describe "Logger#datetime_format=" do end it "follows the Time#strftime format" do - lambda { @logger.datetime_format = "%Y-%m" }.should_not raise_error + -> { @logger.datetime_format = "%Y-%m" }.should_not.raise regex = /\d{4}-\d{2}-\d{2}oo-\w+ar/ @logger.datetime_format = "%Foo-%Bar" diff --git a/spec/ruby/library/logger/logger/debug_spec.rb b/spec/ruby/library/logger/logger/debug_spec.rb index 2260587b23..9375ab0cc6 100644 --- a/spec/ruby/library/logger/logger/debug_spec.rb +++ b/spec/ruby/library/logger/logger/debug_spec.rb @@ -1,5 +1,5 @@ -require File.expand_path('../../../../spec_helper', __FILE__) -require File.expand_path('../../fixtures/common', __FILE__) +require_relative '../../../spec_helper' +require_relative '../fixtures/common' describe "Logger#debug?" do before :each do @@ -16,12 +16,12 @@ describe "Logger#debug?" do it "returns true if severity level allows debug messages" do @logger.level = Logger::DEBUG - @logger.debug?.should == true + @logger.should.debug? end it "returns false if severity level does not allow debug messages" do @logger.level = Logger::WARN - @logger.debug?.should == false + @logger.should_not.debug? end end diff --git a/spec/ruby/library/logger/logger/error_spec.rb b/spec/ruby/library/logger/logger/error_spec.rb index e165396bab..42f1dbd883 100644 --- a/spec/ruby/library/logger/logger/error_spec.rb +++ b/spec/ruby/library/logger/logger/error_spec.rb @@ -1,5 +1,5 @@ -require File.expand_path('../../../../spec_helper', __FILE__) -require File.expand_path('../../fixtures/common', __FILE__) +require_relative '../../../spec_helper' +require_relative '../fixtures/common' describe "Logger#error?" do before :each do @@ -16,12 +16,12 @@ describe "Logger#error?" do it "returns true if severity level allows printing errors" do @logger.level = Logger::INFO - @logger.error?.should == true + @logger.should.error? end it "returns false if severity level does not allow errors" do @logger.level = Logger::FATAL - @logger.error?.should == false + @logger.should_not.error? end end diff --git a/spec/ruby/library/logger/logger/fatal_spec.rb b/spec/ruby/library/logger/logger/fatal_spec.rb index ebbe8a04a5..f12fa3a89f 100644 --- a/spec/ruby/library/logger/logger/fatal_spec.rb +++ b/spec/ruby/library/logger/logger/fatal_spec.rb @@ -1,5 +1,5 @@ -require File.expand_path('../../../../spec_helper', __FILE__) -require File.expand_path('../../fixtures/common', __FILE__) +require_relative '../../../spec_helper' +require_relative '../fixtures/common' describe "Logger#fatal?" do before :each do @@ -16,12 +16,12 @@ describe "Logger#fatal?" do it "returns true if severity level allows fatal messages" do @logger.level = Logger::FATAL - @logger.fatal?.should == true + @logger.should.fatal? end it "returns false if severity level does not allow fatal messages" do @logger.level = Logger::UNKNOWN - @logger.fatal?.should == false + @logger.should_not.fatal? end end diff --git a/spec/ruby/library/logger/logger/info_spec.rb b/spec/ruby/library/logger/logger/info_spec.rb index 7f299ea0da..eb5dca48dd 100644 --- a/spec/ruby/library/logger/logger/info_spec.rb +++ b/spec/ruby/library/logger/logger/info_spec.rb @@ -1,5 +1,5 @@ -require File.expand_path('../../../../spec_helper', __FILE__) -require File.expand_path('../../fixtures/common', __FILE__) +require_relative '../../../spec_helper' +require_relative '../fixtures/common' describe "Logger#info?" do before :each do @@ -16,12 +16,12 @@ describe "Logger#info?" do it "returns true if severity level allows info messages" do @logger.level = Logger::INFO - @logger.info?.should == true + @logger.should.info? end it "returns false if severity level does not allow info messages" do @logger.level = Logger::FATAL - @logger.info?.should == false + @logger.should_not.info? end end diff --git a/spec/ruby/library/logger/logger/new_spec.rb b/spec/ruby/library/logger/logger/new_spec.rb index b3eed42f00..b311c96132 100644 --- a/spec/ruby/library/logger/logger/new_spec.rb +++ b/spec/ruby/library/logger/logger/new_spec.rb @@ -1,5 +1,5 @@ -require File.expand_path('../../../../spec_helper', __FILE__) -require File.expand_path('../../fixtures/common', __FILE__) +require_relative '../../../spec_helper' +require_relative '../fixtures/common' describe "Logger#new" do @@ -13,31 +13,31 @@ describe "Logger#new" do rm_r @file_path end - it "creates a new logger object" do - l = Logger.new(STDERR) - lambda { l.add(Logger::WARN, "Foo") }.should output_to_fd(/Foo/, STDERR) - end + it "creates a new logger object" do + l = Logger.new(STDERR) + -> { l.add(Logger::WARN, "Foo") }.should output_to_fd(/Foo/, STDERR) + end - it "receives a logging device as first argument" do - l = Logger.new(@log_file) - l.add(Logger::WARN, "Test message") + it "receives a logging device as first argument" do + l = Logger.new(@log_file) + l.add(Logger::WARN, "Test message") - @log_file.rewind - LoggerSpecs.strip_date(@log_file.readline).should == "WARN -- : Test message\n" - l.close - end + @log_file.rewind + LoggerSpecs.strip_date(@log_file.readline).should == "WARN -- : Test message\n" + l.close + end it "receives a frequency rotation as second argument" do - lambda { Logger.new(@log_file, "daily") }.should_not raise_error - lambda { Logger.new(@log_file, "weekly") }.should_not raise_error - lambda { Logger.new(@log_file, "monthly") }.should_not raise_error + -> { Logger.new(@log_file, "daily") }.should_not.raise + -> { Logger.new(@log_file, "weekly") }.should_not.raise + -> { Logger.new(@log_file, "monthly") }.should_not.raise end it "also receives a number of log files to keep as second argument" do - lambda { Logger.new(@log_file, 1).close }.should_not raise_error + -> { Logger.new(@log_file, 1).close }.should_not.raise end - it "receivs a maximum logfile size as third argument" do + it "receives a maximum logfile size as third argument" do # This should create 2 small log files, logfile_test and logfile_test.0 # in /tmp, each one with a different message. path = tmp("logfile_test.log") @@ -46,8 +46,8 @@ describe "Logger#new" do l.add Logger::WARN, "foo" l.add Logger::WARN, "bar" - File.exist?(path).should be_true - File.exist?(path + ".0").should be_true + File.should.exist?(path) + File.should.exist?(path + ".0") # first line will be a comment so we'll have to skip it. f = File.open(path) @@ -61,60 +61,58 @@ describe "Logger#new" do rm_r path, "#{path}.0" end - ruby_version_is "2.4" do - it "receives level symbol as keyword argument" do - logger = Logger.new(STDERR, level: :info) - logger.level.should == Logger::INFO - end + it "receives level symbol as keyword argument" do + logger = Logger.new(STDERR, level: :info) + logger.level.should == Logger::INFO + end - it "receives level as keyword argument" do - logger = Logger.new(STDERR, level: Logger::INFO) - logger.level.should == Logger::INFO - end + it "receives level as keyword argument" do + logger = Logger.new(STDERR, level: Logger::INFO) + logger.level.should == Logger::INFO + end - it "receives progname as keyword argument" do - progname = "progname" + it "receives progname as keyword argument" do + progname = "progname" - logger = Logger.new(STDERR, progname: progname) - logger.progname.should == progname - end + logger = Logger.new(STDERR, progname: progname) + logger.progname.should == progname + end - it "receives datetime_format as keyword argument" do - datetime_format = "%H:%M:%S" + it "receives datetime_format as keyword argument" do + datetime_format = "%H:%M:%S" - logger = Logger.new(STDERR, datetime_format: datetime_format) - logger.datetime_format.should == datetime_format - end + logger = Logger.new(STDERR, datetime_format: datetime_format) + logger.datetime_format.should == datetime_format + end - it "receives formatter as keyword argument" do - formatter = Class.new do - def call(_severity, _time, _progname, _msg); end - end.new + it "receives formatter as keyword argument" do + formatter = Class.new do + def call(_severity, _time, _progname, _msg); end + end.new - logger = Logger.new(STDERR, formatter: formatter) - logger.formatter.should == formatter - end + logger = Logger.new(STDERR, formatter: formatter) + logger.formatter.should == formatter + end - it "receives shift_period_suffix " do - shift_period_suffix = "%Y-%m-%d" - path = tmp("shift_period_suffix_test.log") - now = Time.now - tomorrow = Time.at(now.to_i + 60 * 60 * 24) - logger = Logger.new(path, 'daily', shift_period_suffix: shift_period_suffix) + it "receives shift_period_suffix" do + shift_period_suffix = "%Y-%m-%d" + path = tmp("shift_period_suffix_test.log") + now = Time.now + tomorrow = Time.at(now.to_i + 60 * 60 * 24) + logger = Logger.new(path, 'daily', shift_period_suffix: shift_period_suffix) - logger.add Logger::INFO, 'message' + logger.add Logger::INFO, 'message' - Time.stub!(:now).and_return(tomorrow) - logger.add Logger::INFO, 'second message' + Time.stub!(:now).and_return(tomorrow) + logger.add Logger::INFO, 'second message' - shifted_path = "#{path}.#{now.strftime(shift_period_suffix)}" + shifted_path = "#{path}.#{now.strftime(shift_period_suffix)}" - File.exist?(shifted_path).should == true + File.should.exist?(shifted_path) - logger.close + logger.close - rm_r path, shifted_path - end + rm_r path, shifted_path end end diff --git a/spec/ruby/library/logger/logger/unknown_spec.rb b/spec/ruby/library/logger/logger/unknown_spec.rb index 5ef9659a9c..4d37c9797e 100644 --- a/spec/ruby/library/logger/logger/unknown_spec.rb +++ b/spec/ruby/library/logger/logger/unknown_spec.rb @@ -1,5 +1,5 @@ -require File.expand_path('../../../../spec_helper', __FILE__) -require File.expand_path('../../fixtures/common', __FILE__) +require_relative '../../../spec_helper' +require_relative '../fixtures/common' describe "Logger#unknown" do before :each do @@ -29,7 +29,7 @@ describe "Logger#unknown" do end it "receives empty messages" do - lambda { @logger.unknown("") }.should_not raise_error + -> { @logger.unknown("") }.should_not.raise @log_file.rewind LoggerSpecs.strip_date(@log_file.readlines.first).should == "ANY -- : \n" end diff --git a/spec/ruby/library/logger/logger/warn_spec.rb b/spec/ruby/library/logger/logger/warn_spec.rb index d34f19fb8e..0bca34824a 100644 --- a/spec/ruby/library/logger/logger/warn_spec.rb +++ b/spec/ruby/library/logger/logger/warn_spec.rb @@ -1,5 +1,5 @@ -require File.expand_path('../../../../spec_helper', __FILE__) -require File.expand_path('../../fixtures/common', __FILE__) +require_relative '../../../spec_helper' +require_relative '../fixtures/common' describe "Logger#warn?" do before :each do @@ -16,12 +16,12 @@ describe "Logger#warn?" do it "returns true if severity level allows printing warn messages" do @logger.level = Logger::WARN - @logger.warn?.should == true + @logger.should.warn? end it "returns false if severity level does not allow printing warn messages" do @logger.level = Logger::FATAL - @logger.warn?.should == false + @logger.should_not.warn? end end diff --git a/spec/ruby/library/logger/severity_spec.rb b/spec/ruby/library/logger/severity_spec.rb index a4219365dd..e9bc850c33 100644 --- a/spec/ruby/library/logger/severity_spec.rb +++ b/spec/ruby/library/logger/severity_spec.rb @@ -1,4 +1,4 @@ -require File.expand_path('../../../spec_helper', __FILE__) +require_relative '../../spec_helper' require 'logger' describe "Logger::Severity" do |
