1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Move spec/rubyspec to spec/ruby for consistency

* Other ruby implementations use the spec/ruby directory.
  [Misc #13792] [ruby-core:82287]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2017-09-20 20:18:52 +00:00
parent 75bfc6440d
commit 1d15d5f080
4370 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,22 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/common', __FILE__)
describe "Logger::LogDevice#close" do
before :each do
@file_path = tmp("test_log.log")
@log_file = File.open(@file_path, "w+")
# Avoid testing this with STDERR, we don't want to be closing that.
@device = Logger::LogDevice.new(@log_file)
end
after :each do
@log_file.close unless @log_file.closed?
rm_r @file_path
end
it "closes the LogDevice's stream" do
@device.close
lambda { @device.write("Test") }.should complain(/\Alog writing failed\./)
end
end

View file

@ -0,0 +1,47 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/common', __FILE__)
describe "Logger::LogDevice#new" do
before :each do
@file_path = tmp("test_log.log")
@log_file = File.open(@file_path, "w+")
end
after :each do
@log_file.close unless @log_file.closed?
rm_r @file_path
end
it "creates a new log device" do
l = Logger::LogDevice.new(@log_file)
l.dev.should be_kind_of(File)
end
it "receives an IO object to log there as first argument" do
@log_file.should be_kind_of(IO)
l = Logger::LogDevice.new(@log_file)
l.write("foo")
@log_file.rewind
@log_file.readlines.first.should == "foo"
end
it "creates a File if the IO object does not exist" do
path = tmp("test_logger_file")
l = Logger::LogDevice.new(path)
l.write("Test message")
l.close
File.exist?(path).should be_true
File.open(path) do |f|
f.readlines.should_not be_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
end
end

View file

@ -0,0 +1,42 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/common', __FILE__)
describe "Logger::LogDevice#write" do
before :each do
@file_path = tmp("test_log.log")
@log_file = File.open(@file_path, "w+")
# Avoid testing this with STDERR, we don't want to be closing that.
@device = Logger::LogDevice.new(@log_file)
end
after :each do
@log_file.close unless @log_file.closed?
rm_r @file_path
end
it "writes a message to the device" do
@device.write "This is a test message"
@log_file.rewind
@log_file.readlines.first.should == "This is a test message"
end
it "can create a file and writes empty message" do
path = tmp("you_should_not_see_me")
logdevice = Logger::LogDevice.new(path)
logdevice.write("")
logdevice.close
File.open(path) do |f|
messages = f.readlines
messages.size.should == 1
messages.first.should =~ /#.*/ # only a comment
end
rm_r path
end
it "fails if the device is already closed" do
@device.close
lambda { @device.write "foo" }.should complain(/\Alog writing failed\./)
end
end

View file

@ -0,0 +1,9 @@
require 'logger'
module LoggerSpecs
def self.strip_date(str)
str.gsub(/[A-Z].*\[.*\]/, "").lstrip
end
end

View file

@ -0,0 +1,81 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/common', __FILE__)
describe "Logger#add" do
before :each do
@path = tmp("test_log.log")
@log_file = File.open(@path, "w+")
@logger = Logger.new(@path)
end
after :each do
@logger.close
@log_file.close unless @log_file.closed?
rm_r @path
end
it "writes a new message to the logger" do
@logger.add(Logger::WARN, "Test")
@log_file.rewind
message = @log_file.readlines.last
LoggerSpecs.strip_date(message).should == "WARN -- : Test\n"
end
it "receives a severity" do
@logger.log(Logger::INFO, "Info message")
@logger.log(Logger::DEBUG, "Debug message")
@logger.log(Logger::WARN, "Warn message")
@logger.log(Logger::ERROR, "Error message")
@logger.log(Logger::FATAL, "Fatal message")
@log_file.rewind
info, debug, warn, error, fatal = @log_file.readlines
LoggerSpecs.strip_date(info).should == "INFO -- : Info message\n"
LoggerSpecs.strip_date(debug).should == "DEBUG -- : Debug message\n"
LoggerSpecs.strip_date(warn).should == "WARN -- : Warn message\n"
LoggerSpecs.strip_date(error).should == "ERROR -- : Error message\n"
LoggerSpecs.strip_date(fatal).should == "FATAL -- : Fatal message\n"
end
it "receives a message" do
@logger.log(nil, "test")
@log_file.rewind
LoggerSpecs.strip_date(@log_file.readline).should == "ANY -- : test\n"
end
it "receives a program name" do
@logger.log(nil, "test", "TestApp")
@log_file.rewind
LoggerSpecs.strip_date(@log_file.readline).should == "ANY -- TestApp: test\n"
end
it "receives a block" do
lambda {
@logger.log(nil, "test", "TestApp") do
1+1
end
}.should_not raise_error
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
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
temp.should == 0
end
end

View file

@ -0,0 +1,20 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/common', __FILE__)
describe "Logger#close" do
before :each do
@path = tmp("test_log.log")
@log_file = File.open(@path, "w+")
@logger = Logger.new(@path)
end
after :each do
@log_file.close unless @log_file.closed?
rm_r @path
end
it "closes the logging device" do
@logger.close
lambda { @logger.add(nil, "Foo") }.should complain(/\Alog writing failed\./)
end
end

View file

@ -0,0 +1,60 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/common', __FILE__)
describe "Logger#datetime_format" do
before :each do
@path = tmp("test_log.log")
@log_file = File.open(@path, "w+")
@logger = Logger.new(@path)
end
after :each do
@logger.close
@log_file.close unless @log_file.closed?
rm_r @path
end
it "returns the date format used for the logs" do
format = "%Y-%d"
@logger.datetime_format = format
@logger.datetime_format.should == format
end
it "returns nil logger is using the default date format" do
@logger.datetime_format.should == nil
end
end
describe "Logger#datetime_format=" do
before :each do
@path = tmp("test_log.log")
@log_file = File.open(@path, "w+")
@logger = Logger.new(@path)
end
after :each do
@logger.close
@log_file.close unless @log_file.closed?
rm_r @path
end
it "sets the date format for the logs" do
@logger.datetime_format = "%Y"
@logger.datetime_format.should == "%Y"
@logger.add(Logger::WARN, "Test message")
@log_file.rewind
regex = /2[0-9]{3}.*Test message/
@log_file.readlines.first.should =~ regex
end
it "follows the Time#strftime format" do
lambda { @logger.datetime_format = "%Y-%m" }.should_not raise_error
regex = /\d{4}-\d{2}-\d{2}oo-\w+ar/
@logger.datetime_format = "%Foo-%Bar"
@logger.add(nil, "Test message")
@log_file.rewind
@log_file.readlines.first.should =~ regex
end
end

View file

@ -0,0 +1,52 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/common', __FILE__)
describe "Logger#debug?" do
before :each do
@path = tmp("test_log.log")
@log_file = File.open(@path, "w+")
@logger = Logger.new(@path)
end
after :each do
@logger.close
@log_file.close unless @log_file.closed?
rm_r @path
end
it "returns true if severity level allows debug messages" do
@logger.level = Logger::DEBUG
@logger.debug?.should == true
end
it "returns false if severity level does not allow debug messages" do
@logger.level = Logger::WARN
@logger.debug?.should == false
end
end
describe "Logger#debug" do
before :each do
@path = tmp("test_log.log")
@log_file = File.open(@path, "w+")
@logger = Logger.new(@path)
end
after :each do
@logger.close
@log_file.close unless @log_file.closed?
rm_r @path
end
it "logs a DEBUG message" do
@logger.debug("test")
@log_file.rewind
LoggerSpecs.strip_date(@log_file.readlines.first).should == "DEBUG -- : test\n"
end
it "accepts an application name with a block" do
@logger.debug("MyApp") { "Test message" }
@log_file.rewind
LoggerSpecs.strip_date(@log_file.readlines.first).should == "DEBUG -- MyApp: Test message\n"
end
end

View file

@ -0,0 +1,53 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/common', __FILE__)
describe "Logger#error?" do
before :each do
@path = tmp("test_log.log")
@log_file = File.open(@path, "w+")
@logger = Logger.new(@path)
end
after :each do
@logger.close
@log_file.close unless @log_file.closed?
rm_r @path
end
it "returns true if severity level allows printing errors" do
@logger.level = Logger::INFO
@logger.error?.should == true
end
it "returns false if severity level does not allow errors" do
@logger.level = Logger::FATAL
@logger.error?.should == false
end
end
describe "Logger#error" do
before :each do
@path = tmp("test_log.log")
@log_file = File.open(@path, "w+")
@logger = Logger.new(@path)
end
after :each do
@logger.close
@log_file.close unless @log_file.closed?
rm_r @path
end
it "logs a ERROR message" do
@logger.error("test")
@log_file.rewind
LoggerSpecs.strip_date(@log_file.readlines.first).should == "ERROR -- : test\n"
end
it "accepts an application name with a block" do
@logger.error("MyApp") { "Test message" }
@log_file.rewind
LoggerSpecs.strip_date(@log_file.readlines.first).should == "ERROR -- MyApp: Test message\n"
end
end

View file

@ -0,0 +1,53 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/common', __FILE__)
describe "Logger#fatal?" do
before :each do
@path = tmp("test_log.log")
@log_file = File.open(@path, "w+")
@logger = Logger.new(@path)
end
after :each do
@logger.close
@log_file.close unless @log_file.closed?
rm_r @path
end
it "returns true if severity level allows fatal messages" do
@logger.level = Logger::FATAL
@logger.fatal?.should == true
end
it "returns false if severity level does not allow fatal messages" do
@logger.level = Logger::UNKNOWN
@logger.fatal?.should == false
end
end
describe "Logger#fatal" do
before :each do
@path = tmp("test_log.log")
@log_file = File.open(@path, "w+")
@logger = Logger.new(@path)
end
after :each do
@logger.close
@log_file.close unless @log_file.closed?
rm_r @path
end
it "logs a FATAL message" do
@logger.fatal("test")
@log_file.rewind
LoggerSpecs.strip_date(@log_file.readlines.first).should == "FATAL -- : test\n"
end
it "accepts an application name with a block" do
@logger.fatal("MyApp") { "Test message" }
@log_file.rewind
LoggerSpecs.strip_date(@log_file.readlines.first).should == "FATAL -- MyApp: Test message\n"
end
end

View file

@ -0,0 +1,53 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/common', __FILE__)
describe "Logger#info?" do
before :each do
@path = tmp("test_log.log")
@log_file = File.open(@path, "w+")
@logger = Logger.new(@path)
end
after :each do
@logger.close
@log_file.close unless @log_file.closed?
rm_r @path
end
it "returns true if severity level allows info messages" do
@logger.level = Logger::INFO
@logger.info?.should == true
end
it "returns false if severity level does not allow info messages" do
@logger.level = Logger::FATAL
@logger.info?.should == false
end
end
describe "Logger#info" do
before :each do
@path = tmp("test_log.log")
@log_file = File.open(@path, "w+")
@logger = Logger.new(@path)
end
after :each do
@logger.close
@log_file.close unless @log_file.closed?
rm_r @path
end
it "logs a INFO message" do
@logger.info("test")
@log_file.rewind
LoggerSpecs.strip_date(@log_file.readlines.first).should == "INFO -- : test\n"
end
it "accepts an application name with a block" do
@logger.info("MyApp") { "Test message" }
@log_file.rewind
LoggerSpecs.strip_date(@log_file.readlines.first).should == "INFO -- MyApp: Test message\n"
end
end

View file

@ -0,0 +1,63 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/common', __FILE__)
describe "Logger#new" do
before :each do
@file_path = tmp("test_log.log")
@log_file = File.open(@file_path, "w+")
end
after :each do
@log_file.close unless @log_file.closed?
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 "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
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
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
end
it "receivs 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")
l = Logger.new(path, 2, 5)
l.add Logger::WARN, "foo"
l.add Logger::WARN, "bar"
File.exist?(path).should be_true
File.exist?(path + ".0").should be_true
# first line will be a comment so we'll have to skip it.
f = File.open(path)
f1 = File.open("#{path}.0")
LoggerSpecs.strip_date(f1.readlines.last).should == "WARN -- : foo\n"
LoggerSpecs.strip_date(f.readlines.last).should == "WARN -- : bar\n"
l.close
f.close
f1.close
rm_r path, "#{path}.0"
end
end

View file

@ -0,0 +1,36 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/common', __FILE__)
describe "Logger#unknown" do
before :each do
@path = tmp("test_log.log")
@log_file = File.open(@path, "w+")
@logger = Logger.new(@path)
end
after :each do
@logger.close
@log_file.close unless @log_file.closed?
rm_r @path
end
it "logs a message with unknown severity" do
@logger.unknown "Test"
@log_file.rewind
LoggerSpecs.strip_date(@log_file.readlines.first).should == "ANY -- : Test\n"
end
it "defaults the priority value to 5 and text value to ANY" do
@logger.unknown "Test"
@log_file.rewind
message = LoggerSpecs.strip_date(@log_file.readlines.first)[0..2]
message.should == "ANY"
Logger::UNKNOWN.should == 5
end
it "receives empty messages" do
lambda { @logger.unknown("") }.should_not raise_error
@log_file.rewind
LoggerSpecs.strip_date(@log_file.readlines.first).should == "ANY -- : \n"
end
end

View file

@ -0,0 +1,53 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/common', __FILE__)
describe "Logger#warn?" do
before :each do
@path = tmp("test_log.log")
@log_file = File.open(@path, "w+")
@logger = Logger.new(@path)
end
after :each do
@logger.close
@log_file.close unless @log_file.closed?
rm_r @path
end
it "returns true if severity level allows printing warn messages" do
@logger.level = Logger::WARN
@logger.warn?.should == true
end
it "returns false if severity level does not allow printing warn messages" do
@logger.level = Logger::FATAL
@logger.warn?.should == false
end
end
describe "Logger#warn" do
before :each do
@path = tmp("test_log.log")
@log_file = File.open(@path, "w+")
@logger = Logger.new(@path)
end
after :each do
@logger.close
@log_file.close unless @log_file.closed?
rm_r @path
end
it "logs a WARN message" do
@logger.warn("test")
@log_file.rewind
LoggerSpecs.strip_date(@log_file.readlines.first).should == "WARN -- : test\n"
end
it "accepts an application name with a block" do
@logger.warn("MyApp") { "Test message" }
@log_file.rewind
LoggerSpecs.strip_date(@log_file.readlines.first).should == "WARN -- MyApp: Test message\n"
end
end

View file

@ -0,0 +1,13 @@
require File.expand_path('../../../spec_helper', __FILE__)
require 'logger'
describe "Logger::Severity" do
it "defines Logger severity constants" do
Logger::DEBUG.should == 0
Logger::INFO.should == 1
Logger::WARN.should == 2
Logger::ERROR.should == 3
Logger::FATAL.should == 4
Logger::UNKNOWN.should == 5
end
end