diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2024-01-22 15:25:21 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2024-01-22 15:59:40 +0900 |
commit | b5b98546cfb07988051877f08f84233665ab5fcd (patch) | |
tree | 6ebd98f4d59b691f65d4c275a2f11a9042e6595c | |
parent | 029b6d5b76e49d2b5fc1494856e5410d57e5352a (diff) |
spec/mspec/tool/wrap_with_guard.rb 'ruby_version_is ""..."3.4"' spec/ruby/library/syslog/**/*.rb
22 files changed, 606 insertions, 542 deletions
diff --git a/spec/ruby/library/syslog/alert_spec.rb b/spec/ruby/library/syslog/alert_spec.rb index edff789dc9..a3a616bd6d 100644 --- a/spec/ruby/library/syslog/alert_spec.rb +++ b/spec/ruby/library/syslog/alert_spec.rb @@ -1,10 +1,13 @@ require_relative '../../spec_helper' -platform_is_not :windows do - require_relative 'shared/log' - require 'syslog' +ruby_version_is ""..."3.4" do - describe "Syslog.alert" do - it_behaves_like :syslog_log, :alert + platform_is_not :windows do + require_relative 'shared/log' + require 'syslog' + + describe "Syslog.alert" do + it_behaves_like :syslog_log, :alert + end end end diff --git a/spec/ruby/library/syslog/close_spec.rb b/spec/ruby/library/syslog/close_spec.rb index 8c3b67c05b..60866de971 100644 --- a/spec/ruby/library/syslog/close_spec.rb +++ b/spec/ruby/library/syslog/close_spec.rb @@ -1,57 +1,60 @@ require_relative '../../spec_helper' -platform_is_not :windows do - require 'syslog' - - describe "Syslog.close" do - platform_is_not :windows do - - before :each do - Syslog.opened?.should be_false - end - - after :each do - Syslog.opened?.should be_false - end - - it "closes the log" do - Syslog.opened?.should be_false - Syslog.open - Syslog.opened?.should be_true - Syslog.close - Syslog.opened?.should be_false - end - - it "raises a RuntimeError if the log's already closed" do - -> { Syslog.close }.should raise_error(RuntimeError) - end - - it "it does not work inside blocks" do - -> { - Syslog.open { |s| s.close } - }.should raise_error(RuntimeError) - Syslog.should_not.opened? - end - - it "sets the identity to nil" do - Syslog.open("rubyspec") - Syslog.ident.should == "rubyspec" - Syslog.close - Syslog.ident.should be_nil - end - - it "sets the options to nil" do - Syslog.open("rubyspec", Syslog::LOG_PID) - Syslog.options.should == Syslog::LOG_PID - Syslog.close - Syslog.options.should == nil - end - - it "sets the facility to nil" do - Syslog.open - Syslog.facility.should == 8 - Syslog.close - Syslog.facility.should == nil +ruby_version_is ""..."3.4" do + + platform_is_not :windows do + require 'syslog' + + describe "Syslog.close" do + platform_is_not :windows do + + before :each do + Syslog.opened?.should be_false + end + + after :each do + Syslog.opened?.should be_false + end + + it "closes the log" do + Syslog.opened?.should be_false + Syslog.open + Syslog.opened?.should be_true + Syslog.close + Syslog.opened?.should be_false + end + + it "raises a RuntimeError if the log's already closed" do + -> { Syslog.close }.should raise_error(RuntimeError) + end + + it "it does not work inside blocks" do + -> { + Syslog.open { |s| s.close } + }.should raise_error(RuntimeError) + Syslog.should_not.opened? + end + + it "sets the identity to nil" do + Syslog.open("rubyspec") + Syslog.ident.should == "rubyspec" + Syslog.close + Syslog.ident.should be_nil + end + + it "sets the options to nil" do + Syslog.open("rubyspec", Syslog::LOG_PID) + Syslog.options.should == Syslog::LOG_PID + Syslog.close + Syslog.options.should == nil + end + + it "sets the facility to nil" do + Syslog.open + Syslog.facility.should == 8 + Syslog.close + Syslog.facility.should == nil + end end end end diff --git a/spec/ruby/library/syslog/constants_spec.rb b/spec/ruby/library/syslog/constants_spec.rb index 2b9524c53d..d44d67e2de 100644 --- a/spec/ruby/library/syslog/constants_spec.rb +++ b/spec/ruby/library/syslog/constants_spec.rb @@ -1,40 +1,43 @@ require_relative '../../spec_helper' -platform_is_not :windows do - require 'syslog' +ruby_version_is ""..."3.4" do - describe "Syslog::Constants" do - platform_is_not :windows, :solaris, :aix do - before :all do - @constants = %w(LOG_AUTHPRIV LOG_USER LOG_LOCAL2 LOG_NOTICE LOG_NDELAY - LOG_SYSLOG LOG_ALERT LOG_FTP LOG_LOCAL5 LOG_ERR LOG_AUTH - LOG_LOCAL1 LOG_ODELAY LOG_NEWS LOG_DAEMON LOG_LOCAL4 - LOG_CRIT LOG_INFO LOG_PERROR LOG_LOCAL0 LOG_CONS LOG_LPR - LOG_LOCAL7 LOG_WARNING LOG_CRON LOG_LOCAL3 LOG_EMERG - LOG_NOWAIT LOG_UUCP LOG_PID LOG_KERN LOG_MAIL LOG_LOCAL6 - LOG_DEBUG) - end + platform_is_not :windows do + require 'syslog' + + describe "Syslog::Constants" do + platform_is_not :windows, :solaris, :aix do + before :all do + @constants = %w(LOG_AUTHPRIV LOG_USER LOG_LOCAL2 LOG_NOTICE LOG_NDELAY + LOG_SYSLOG LOG_ALERT LOG_FTP LOG_LOCAL5 LOG_ERR LOG_AUTH + LOG_LOCAL1 LOG_ODELAY LOG_NEWS LOG_DAEMON LOG_LOCAL4 + LOG_CRIT LOG_INFO LOG_PERROR LOG_LOCAL0 LOG_CONS LOG_LPR + LOG_LOCAL7 LOG_WARNING LOG_CRON LOG_LOCAL3 LOG_EMERG + LOG_NOWAIT LOG_UUCP LOG_PID LOG_KERN LOG_MAIL LOG_LOCAL6 + LOG_DEBUG) + end - it "includes the Syslog constants" do - @constants.each do |c| - Syslog::Constants.should have_constant(c) + it "includes the Syslog constants" do + @constants.each do |c| + Syslog::Constants.should have_constant(c) + end end end - end - # The masks are defined in <syslog.h> + # The masks are defined in <syslog.h> - describe "Syslog::Constants.LOG_MASK" do - it "returns the mask value for a priority" do - Syslog::Constants.LOG_MASK(Syslog::LOG_DEBUG).should == 128 - Syslog::Constants.LOG_MASK(Syslog::LOG_WARNING).should == 16 + describe "Syslog::Constants.LOG_MASK" do + it "returns the mask value for a priority" do + Syslog::Constants.LOG_MASK(Syslog::LOG_DEBUG).should == 128 + Syslog::Constants.LOG_MASK(Syslog::LOG_WARNING).should == 16 + end end - end - describe "Syslog::Constants.LOG_UPTO" do - it "returns a mask for the priorities up to a given argument" do - Syslog::Constants.LOG_UPTO(Syslog::LOG_ALERT).should == 3 - Syslog::Constants.LOG_UPTO(Syslog::LOG_DEBUG).should == 255 + describe "Syslog::Constants.LOG_UPTO" do + it "returns a mask for the priorities up to a given argument" do + Syslog::Constants.LOG_UPTO(Syslog::LOG_ALERT).should == 3 + Syslog::Constants.LOG_UPTO(Syslog::LOG_DEBUG).should == 255 + end end end end diff --git a/spec/ruby/library/syslog/crit_spec.rb b/spec/ruby/library/syslog/crit_spec.rb index 5d3904f719..d7841ac010 100644 --- a/spec/ruby/library/syslog/crit_spec.rb +++ b/spec/ruby/library/syslog/crit_spec.rb @@ -1,10 +1,13 @@ require_relative '../../spec_helper' -platform_is_not :windows do - require_relative 'shared/log' - require 'syslog' +ruby_version_is ""..."3.4" do - describe "Syslog.crit" do - it_behaves_like :syslog_log, :crit + platform_is_not :windows do + require_relative 'shared/log' + require 'syslog' + + describe "Syslog.crit" do + it_behaves_like :syslog_log, :crit + end end end diff --git a/spec/ruby/library/syslog/debug_spec.rb b/spec/ruby/library/syslog/debug_spec.rb index d03e8a88c9..94e640c741 100644 --- a/spec/ruby/library/syslog/debug_spec.rb +++ b/spec/ruby/library/syslog/debug_spec.rb @@ -1,10 +1,13 @@ require_relative '../../spec_helper' -platform_is_not :windows do - require_relative 'shared/log' - require 'syslog' +ruby_version_is ""..."3.4" do - describe "Syslog.debug" do - it_behaves_like :syslog_log, :debug + platform_is_not :windows do + require_relative 'shared/log' + require 'syslog' + + describe "Syslog.debug" do + it_behaves_like :syslog_log, :debug + end end end diff --git a/spec/ruby/library/syslog/emerg_spec.rb b/spec/ruby/library/syslog/emerg_spec.rb index 2ab4d60291..86938ce889 100644 --- a/spec/ruby/library/syslog/emerg_spec.rb +++ b/spec/ruby/library/syslog/emerg_spec.rb @@ -1,16 +1,19 @@ require_relative '../../spec_helper' -platform_is_not :windows do - require_relative 'shared/log' - require 'syslog' +ruby_version_is ""..."3.4" do - describe "Syslog.emerg" do - # Some way needs do be found to prevent this spec - # from causing output on all open terminals. If this - # is not possible, this spec may need a special guard - # that only runs when requested. - quarantine! do - it_behaves_like :syslog_log, :emerg + platform_is_not :windows do + require_relative 'shared/log' + require 'syslog' + + describe "Syslog.emerg" do + # Some way needs do be found to prevent this spec + # from causing output on all open terminals. If this + # is not possible, this spec may need a special guard + # that only runs when requested. + quarantine! do + it_behaves_like :syslog_log, :emerg + end end end end diff --git a/spec/ruby/library/syslog/err_spec.rb b/spec/ruby/library/syslog/err_spec.rb index 43e876ed37..a7b39ea5c0 100644 --- a/spec/ruby/library/syslog/err_spec.rb +++ b/spec/ruby/library/syslog/err_spec.rb @@ -1,10 +1,13 @@ require_relative '../../spec_helper' -platform_is_not :windows do - require_relative 'shared/log' - require 'syslog' +ruby_version_is ""..."3.4" do - describe "Syslog.err" do - it_behaves_like :syslog_log, :err + platform_is_not :windows do + require_relative 'shared/log' + require 'syslog' + + describe "Syslog.err" do + it_behaves_like :syslog_log, :err + end end end diff --git a/spec/ruby/library/syslog/facility_spec.rb b/spec/ruby/library/syslog/facility_spec.rb index 550ca70b11..1129dd9ee3 100644 --- a/spec/ruby/library/syslog/facility_spec.rb +++ b/spec/ruby/library/syslog/facility_spec.rb @@ -1,47 +1,50 @@ require_relative '../../spec_helper' -platform_is_not :windows do - require 'syslog' - - describe "Syslog.facility" do - platform_is_not :windows do - - before :each do - Syslog.opened?.should be_false - end - - after :each do - Syslog.opened?.should be_false - end - - it "returns the logging facility" do - Syslog.open("rubyspec", 3, Syslog::LOG_MAIL) - Syslog.facility.should == Syslog::LOG_MAIL - Syslog.close - end - - it "returns nil if the log is closed" do - Syslog.opened?.should be_false - Syslog.facility.should == nil - end - - it "defaults to LOG_USER" do - Syslog.open - Syslog.facility.should == Syslog::LOG_USER - Syslog.close - end - - it "resets after each open call" do - Syslog.open - Syslog.facility.should == Syslog::LOG_USER - - Syslog.open!("rubyspec", 3, Syslog::LOG_MAIL) - Syslog.facility.should == Syslog::LOG_MAIL - Syslog.close - - Syslog.open - Syslog.facility.should == Syslog::LOG_USER - Syslog.close +ruby_version_is ""..."3.4" do + + platform_is_not :windows do + require 'syslog' + + describe "Syslog.facility" do + platform_is_not :windows do + + before :each do + Syslog.opened?.should be_false + end + + after :each do + Syslog.opened?.should be_false + end + + it "returns the logging facility" do + Syslog.open("rubyspec", 3, Syslog::LOG_MAIL) + Syslog.facility.should == Syslog::LOG_MAIL + Syslog.close + end + + it "returns nil if the log is closed" do + Syslog.opened?.should be_false + Syslog.facility.should == nil + end + + it "defaults to LOG_USER" do + Syslog.open + Syslog.facility.should == Syslog::LOG_USER + Syslog.close + end + + it "resets after each open call" do + Syslog.open + Syslog.facility.should == Syslog::LOG_USER + + Syslog.open!("rubyspec", 3, Syslog::LOG_MAIL) + Syslog.facility.should == Syslog::LOG_MAIL + Syslog.close + + Syslog.open + Syslog.facility.should == Syslog::LOG_USER + Syslog.close + end end end end diff --git a/spec/ruby/library/syslog/ident_spec.rb b/spec/ruby/library/syslog/ident_spec.rb index 3b08327140..524e560373 100644 --- a/spec/ruby/library/syslog/ident_spec.rb +++ b/spec/ruby/library/syslog/ident_spec.rb @@ -1,34 +1,37 @@ require_relative '../../spec_helper' -platform_is_not :windows do - require 'syslog' +ruby_version_is ""..."3.4" do - describe "Syslog.ident" do - platform_is_not :windows do + platform_is_not :windows do + require 'syslog' - before :each do - Syslog.opened?.should be_false - end + describe "Syslog.ident" do + platform_is_not :windows do - after :each do - Syslog.opened?.should be_false - end + before :each do + Syslog.opened?.should be_false + end - it "returns the logging identity" do - Syslog.open("rubyspec") - Syslog.ident.should == "rubyspec" - Syslog.close - end + after :each do + Syslog.opened?.should be_false + end - it "returns nil if the log is closed" do - Syslog.should_not.opened? - Syslog.ident.should == nil - end + it "returns the logging identity" do + Syslog.open("rubyspec") + Syslog.ident.should == "rubyspec" + Syslog.close + end + + it "returns nil if the log is closed" do + Syslog.should_not.opened? + Syslog.ident.should == nil + end - it "defaults to $0" do - Syslog.open - Syslog.ident.should == $0 - Syslog.close + it "defaults to $0" do + Syslog.open + Syslog.ident.should == $0 + Syslog.close + end end end end diff --git a/spec/ruby/library/syslog/info_spec.rb b/spec/ruby/library/syslog/info_spec.rb index f2d535299c..03bb6f6003 100644 --- a/spec/ruby/library/syslog/info_spec.rb +++ b/spec/ruby/library/syslog/info_spec.rb @@ -1,10 +1,13 @@ require_relative '../../spec_helper' -platform_is_not :windows do - require_relative 'shared/log' - require 'syslog' +ruby_version_is ""..."3.4" do - describe "Syslog.info" do - it_behaves_like :syslog_log, :info + platform_is_not :windows do + require_relative 'shared/log' + require 'syslog' + + describe "Syslog.info" do + it_behaves_like :syslog_log, :info + end end end diff --git a/spec/ruby/library/syslog/inspect_spec.rb b/spec/ruby/library/syslog/inspect_spec.rb index f45231f8e3..5e1e09e86f 100644 --- a/spec/ruby/library/syslog/inspect_spec.rb +++ b/spec/ruby/library/syslog/inspect_spec.rb @@ -1,38 +1,41 @@ require_relative '../../spec_helper' -platform_is_not :windows do - require 'syslog' +ruby_version_is ""..."3.4" do - describe "Syslog.inspect" do - platform_is_not :windows do + platform_is_not :windows do + require 'syslog' - before :each do - Syslog.opened?.should be_false - end + describe "Syslog.inspect" do + platform_is_not :windows do - after :each do - Syslog.opened?.should be_false - end + before :each do + Syslog.opened?.should be_false + end - it "returns a string a closed log" do - Syslog.inspect.should =~ /opened=false/ - end + after :each do + Syslog.opened?.should be_false + end - it "returns a string for an opened log" do - Syslog.open - Syslog.inspect.should =~ /opened=true.*/ - Syslog.close - end + it "returns a string a closed log" do + Syslog.inspect.should =~ /opened=false/ + end + + it "returns a string for an opened log" do + Syslog.open + Syslog.inspect.should =~ /opened=true.*/ + Syslog.close + end - it "includes the ident, options, facility and mask" do - Syslog.open("rubyspec", Syslog::LOG_PID, Syslog::LOG_USER) - inspect_str = Syslog.inspect.split ", " - inspect_str[0].should =~ /opened=true/ - inspect_str[1].should == "ident=\"rubyspec\"" - inspect_str[2].should == "options=#{Syslog::LOG_PID}" - inspect_str[3].should == "facility=#{Syslog::LOG_USER}" - inspect_str[4].should == "mask=255>" - Syslog.close + it "includes the ident, options, facility and mask" do + Syslog.open("rubyspec", Syslog::LOG_PID, Syslog::LOG_USER) + inspect_str = Syslog.inspect.split ", " + inspect_str[0].should =~ /opened=true/ + inspect_str[1].should == "ident=\"rubyspec\"" + inspect_str[2].should == "options=#{Syslog::LOG_PID}" + inspect_str[3].should == "facility=#{Syslog::LOG_USER}" + inspect_str[4].should == "mask=255>" + Syslog.close + end end end end diff --git a/spec/ruby/library/syslog/instance_spec.rb b/spec/ruby/library/syslog/instance_spec.rb index 891296c52d..b7a7d122f0 100644 --- a/spec/ruby/library/syslog/instance_spec.rb +++ b/spec/ruby/library/syslog/instance_spec.rb @@ -1,12 +1,15 @@ require_relative '../../spec_helper' -platform_is_not :windows do - require 'syslog' +ruby_version_is ""..."3.4" do - describe "Syslog.instance" do - platform_is_not :windows do - it "returns the module" do - Syslog.instance.should == Syslog + platform_is_not :windows do + require 'syslog' + + describe "Syslog.instance" do + platform_is_not :windows do + it "returns the module" do + Syslog.instance.should == Syslog + end end end end diff --git a/spec/ruby/library/syslog/log_spec.rb b/spec/ruby/library/syslog/log_spec.rb index 8589fb1f73..749d825c10 100644 --- a/spec/ruby/library/syslog/log_spec.rb +++ b/spec/ruby/library/syslog/log_spec.rb @@ -1,55 +1,58 @@ require_relative '../../spec_helper' -platform_is_not :windows do - require 'syslog' +ruby_version_is ""..."3.4" do - describe "Syslog.log" do - platform_is_not :windows, :darwin, :solaris, :aix, :android do + platform_is_not :windows do + require 'syslog' - before :each do - Syslog.opened?.should be_false - end - - after :each do - Syslog.opened?.should be_false - end + describe "Syslog.log" do + platform_is_not :windows, :darwin, :solaris, :aix, :android do - it "receives a priority as first argument" do - -> { - Syslog.open("rubyspec", Syslog::LOG_PERROR) do |s| - s.log(Syslog::LOG_ALERT, "Hello") - s.log(Syslog::LOG_CRIT, "World") - end - }.should output_to_fd(/\Arubyspec(?::| \d+ - -) Hello\nrubyspec(?::| \d+ - -) World\n\z/, $stderr) - end + before :each do + Syslog.opened?.should be_false + end - it "accepts undefined priorities" do - -> { - Syslog.open("rubyspec", Syslog::LOG_PERROR) do |s| - s.log(1337, "Hello") - end - # use a regex since it'll output unknown facility/priority messages - }.should output_to_fd(/rubyspec(?::| \d+ - -) Hello\n\z/, $stderr) - end + after :each do + Syslog.opened?.should be_false + end - it "fails with TypeError on nil log messages" do - Syslog.open do |s| - -> { s.log(1, nil) }.should raise_error(TypeError) + it "receives a priority as first argument" do + -> { + Syslog.open("rubyspec", Syslog::LOG_PERROR) do |s| + s.log(Syslog::LOG_ALERT, "Hello") + s.log(Syslog::LOG_CRIT, "World") + end + }.should output_to_fd(/\Arubyspec(?::| \d+ - -) Hello\nrubyspec(?::| \d+ - -) World\n\z/, $stderr) end - end - it "fails if the log is closed" do - -> { - Syslog.log(Syslog::LOG_ALERT, "test") - }.should raise_error(RuntimeError) - end + it "accepts undefined priorities" do + -> { + Syslog.open("rubyspec", Syslog::LOG_PERROR) do |s| + s.log(1337, "Hello") + end + # use a regex since it'll output unknown facility/priority messages + }.should output_to_fd(/rubyspec(?::| \d+ - -) Hello\n\z/, $stderr) + end - it "accepts printf parameters" do - -> { - Syslog.open("rubyspec", Syslog::LOG_PERROR) do |s| - s.log(Syslog::LOG_ALERT, "%s x %d", "chunky bacon", 2) + it "fails with TypeError on nil log messages" do + Syslog.open do |s| + -> { s.log(1, nil) }.should raise_error(TypeError) end - }.should output_to_fd(/rubyspec(?::| \d+ - -) chunky bacon x 2\n\z/, $stderr) + end + + it "fails if the log is closed" do + -> { + Syslog.log(Syslog::LOG_ALERT, "test") + }.should raise_error(RuntimeError) + end + + it "accepts printf parameters" do + -> { + Syslog.open("rubyspec", Syslog::LOG_PERROR) do |s| + s.log(Syslog::LOG_ALERT, "%s x %d", "chunky bacon", 2) + end + }.should output_to_fd(/rubyspec(?::| \d+ - -) chunky bacon x 2\n\z/, $stderr) + end end end end diff --git a/spec/ruby/library/syslog/mask_spec.rb b/spec/ruby/library/syslog/mask_spec.rb index b3f1250b24..05c64ceec8 100644 --- a/spec/ruby/library/syslog/mask_spec.rb +++ b/spec/ruby/library/syslog/mask_spec.rb @@ -1,111 +1,114 @@ require_relative '../../spec_helper' -platform_is_not :windows do - require 'syslog' +ruby_version_is ""..."3.4" do - describe "Syslog.mask" do - platform_is_not :windows do + platform_is_not :windows do + require 'syslog' - before :each do - Syslog.opened?.should be_false - end + describe "Syslog.mask" do + platform_is_not :windows do - after :each do - Syslog.opened?.should be_false - # make sure we return the mask to the default value - Syslog.open { |s| s.mask = 255 } - end + before :each do + Syslog.opened?.should be_false + end - it "returns the log priority mask" do - Syslog.open("rubyspec") do - Syslog.mask.should == 255 - Syslog.mask = 3 - Syslog.mask.should == 3 - Syslog.mask = 255 + after :each do + Syslog.opened?.should be_false + # make sure we return the mask to the default value + Syslog.open { |s| s.mask = 255 } end - end - it "defaults to 255" do - Syslog.open do |s| - s.mask.should == 255 + it "returns the log priority mask" do + Syslog.open("rubyspec") do + Syslog.mask.should == 255 + Syslog.mask = 3 + Syslog.mask.should == 3 + Syslog.mask = 255 + end end - end - it "returns nil if the log is closed" do - Syslog.should_not.opened? - Syslog.mask.should == nil - end + it "defaults to 255" do + Syslog.open do |s| + s.mask.should == 255 + end + end - platform_is :darwin do - it "resets if the log is reopened" do - Syslog.open - Syslog.mask.should == 255 - Syslog.mask = 64 + it "returns nil if the log is closed" do + Syslog.should_not.opened? + Syslog.mask.should == nil + end - Syslog.reopen("rubyspec") do + platform_is :darwin do + it "resets if the log is reopened" do + Syslog.open Syslog.mask.should == 255 - end + Syslog.mask = 64 - Syslog.open do - Syslog.mask.should == 255 + Syslog.reopen("rubyspec") do + Syslog.mask.should == 255 + end + + Syslog.open do + Syslog.mask.should == 255 + end end end - end - platform_is_not :darwin do - it "persists if the log is reopened" do - Syslog.open - Syslog.mask.should == 255 - Syslog.mask = 64 + platform_is_not :darwin do + it "persists if the log is reopened" do + Syslog.open + Syslog.mask.should == 255 + Syslog.mask = 64 - Syslog.reopen("rubyspec") do - Syslog.mask.should == 64 - end + Syslog.reopen("rubyspec") do + Syslog.mask.should == 64 + end - Syslog.open do - Syslog.mask.should == 64 + Syslog.open do + Syslog.mask.should == 64 + end end end end end - end - describe "Syslog.mask=" do - platform_is_not :windows do + describe "Syslog.mask=" do + platform_is_not :windows do - before :each do - Syslog.opened?.should be_false - end + before :each do + Syslog.opened?.should be_false + end - after :each do - Syslog.opened?.should be_false - # make sure we return the mask to the default value - Syslog.open { |s| s.mask = 255 } - end + after :each do + Syslog.opened?.should be_false + # make sure we return the mask to the default value + Syslog.open { |s| s.mask = 255 } + end - it "sets the log priority mask" do - Syslog.open do - Syslog.mask = 64 - Syslog.mask.should == 64 + it "sets the log priority mask" do + Syslog.open do + Syslog.mask = 64 + Syslog.mask.should == 64 + end end - end - it "raises an error if the log is closed" do - -> { Syslog.mask = 1337 }.should raise_error(RuntimeError) - end + it "raises an error if the log is closed" do + -> { Syslog.mask = 1337 }.should raise_error(RuntimeError) + end - it "only accepts numbers" do - Syslog.open do + it "only accepts numbers" do + Syslog.open do - Syslog.mask = 1337 - Syslog.mask.should == 1337 + Syslog.mask = 1337 + Syslog.mask.should == 1337 - Syslog.mask = 3.1416 - Syslog.mask.should == 3 + Syslog.mask = 3.1416 + Syslog.mask.should == 3 - -> { Syslog.mask = "oh hai" }.should raise_error(TypeError) - -> { Syslog.mask = "43" }.should raise_error(TypeError) + -> { Syslog.mask = "oh hai" }.should raise_error(TypeError) + -> { Syslog.mask = "43" }.should raise_error(TypeError) + end end end end diff --git a/spec/ruby/library/syslog/notice_spec.rb b/spec/ruby/library/syslog/notice_spec.rb index a2134e0140..41c175cb49 100644 --- a/spec/ruby/library/syslog/notice_spec.rb +++ b/spec/ruby/library/syslog/notice_spec.rb @@ -1,10 +1,13 @@ require_relative '../../spec_helper' -platform_is_not :windows do - require_relative 'shared/log' - require 'syslog' +ruby_version_is ""..."3.4" do - describe "Syslog.notice" do - it_behaves_like :syslog_log, :notice + platform_is_not :windows do + require_relative 'shared/log' + require 'syslog' + + describe "Syslog.notice" do + it_behaves_like :syslog_log, :notice + end end end diff --git a/spec/ruby/library/syslog/open_spec.rb b/spec/ruby/library/syslog/open_spec.rb index 543f5d418b..9cd65cda4a 100644 --- a/spec/ruby/library/syslog/open_spec.rb +++ b/spec/ruby/library/syslog/open_spec.rb @@ -1,92 +1,95 @@ require_relative '../../spec_helper' -platform_is_not :windows do - require_relative 'shared/reopen' - require 'syslog' +ruby_version_is ""..."3.4" do - describe "Syslog.open" do - platform_is_not :windows do + platform_is_not :windows do + require_relative 'shared/reopen' + require 'syslog' - before :each do - Syslog.opened?.should be_false - end + describe "Syslog.open" do + platform_is_not :windows do - after :each do - Syslog.opened?.should be_false - end + before :each do + Syslog.opened?.should be_false + end - it "returns the module" do - Syslog.open.should == Syslog - Syslog.close - Syslog.open("Test", 5, 9).should == Syslog - Syslog.close - end + after :each do + Syslog.opened?.should be_false + end - it "receives an identity as first argument" do - Syslog.open("rubyspec") - Syslog.ident.should == "rubyspec" - Syslog.close - end + it "returns the module" do + Syslog.open.should == Syslog + Syslog.close + Syslog.open("Test", 5, 9).should == Syslog + Syslog.close + end - it "defaults the identity to $0" do - Syslog.open - Syslog.ident.should == $0 - Syslog.close - end + it "receives an identity as first argument" do + Syslog.open("rubyspec") + Syslog.ident.should == "rubyspec" + Syslog.close + end - it "receives the logging options as second argument" do - Syslog.open("rubyspec", Syslog::LOG_PID) - Syslog.options.should == Syslog::LOG_PID - Syslog.close - end + it "defaults the identity to $0" do + Syslog.open + Syslog.ident.should == $0 + Syslog.close + end - it "defaults the logging options to LOG_PID | LOG_CONS" do - Syslog.open - Syslog.options.should == Syslog::LOG_PID | Syslog::LOG_CONS - Syslog.close - end + it "receives the logging options as second argument" do + Syslog.open("rubyspec", Syslog::LOG_PID) + Syslog.options.should == Syslog::LOG_PID + Syslog.close + end - it "receives a facility as third argument" do - Syslog.open("rubyspec", Syslog::LOG_PID, 0) - Syslog.facility.should == 0 - Syslog.close - end + it "defaults the logging options to LOG_PID | LOG_CONS" do + Syslog.open + Syslog.options.should == Syslog::LOG_PID | Syslog::LOG_CONS + Syslog.close + end - it "defaults the facility to LOG_USER" do - Syslog.open - Syslog.facility.should == Syslog::LOG_USER - Syslog.close - end + it "receives a facility as third argument" do + Syslog.open("rubyspec", Syslog::LOG_PID, 0) + Syslog.facility.should == 0 + Syslog.close + end + + it "defaults the facility to LOG_USER" do + Syslog.open + Syslog.facility.should == Syslog::LOG_USER + Syslog.close + end - it "receives a block and calls it with the module" do - Syslog.open("rubyspec", 3, 8) do |s| - s.should == Syslog - s.ident.should == "rubyspec" - s.options.should == 3 - s.facility.should == Syslog::LOG_USER + it "receives a block and calls it with the module" do + Syslog.open("rubyspec", 3, 8) do |s| + s.should == Syslog + s.ident.should == "rubyspec" + s.options.should == 3 + s.facility.should == Syslog::LOG_USER + end end - end - it "closes the log if after it receives a block" do - Syslog.open{ } - Syslog.opened?.should be_false - end + it "closes the log if after it receives a block" do + Syslog.open{ } + Syslog.opened?.should be_false + end - it "raises an error if the log is opened" do - Syslog.open - -> { + it "raises an error if the log is opened" do Syslog.open - }.should raise_error(RuntimeError, /syslog already open/) - -> { + -> { + Syslog.open + }.should raise_error(RuntimeError, /syslog already open/) + -> { + Syslog.close + Syslog.open + }.should_not raise_error Syslog.close - Syslog.open - }.should_not raise_error - Syslog.close + end end end - end - describe "Syslog.open!" do - it_behaves_like :syslog_reopen, :open! + describe "Syslog.open!" do + it_behaves_like :syslog_reopen, :open! + end end end diff --git a/spec/ruby/library/syslog/opened_spec.rb b/spec/ruby/library/syslog/opened_spec.rb index 94432e65a4..ee7a884a50 100644 --- a/spec/ruby/library/syslog/opened_spec.rb +++ b/spec/ruby/library/syslog/opened_spec.rb @@ -1,38 +1,41 @@ require_relative '../../spec_helper' -platform_is_not :windows do - require 'syslog' +ruby_version_is ""..."3.4" do - describe "Syslog.opened?" do - platform_is_not :windows do + platform_is_not :windows do + require 'syslog' - before :each do - Syslog.opened?.should be_false - end - - after :each do - Syslog.opened?.should be_false - end + describe "Syslog.opened?" do + platform_is_not :windows do - it "returns true if the log is opened" do - Syslog.open - Syslog.opened?.should be_true - Syslog.close - end + before :each do + Syslog.opened?.should be_false + end - it "returns false otherwise" do - Syslog.opened?.should be_false - Syslog.open - Syslog.close - Syslog.opened?.should be_false - end + after :each do + Syslog.opened?.should be_false + end - it "works inside a block" do - Syslog.open do |s| - s.opened?.should be_true + it "returns true if the log is opened" do + Syslog.open Syslog.opened?.should be_true + Syslog.close + end + + it "returns false otherwise" do + Syslog.opened?.should be_false + Syslog.open + Syslog.close + Syslog.opened?.should be_false + end + + it "works inside a block" do + Syslog.open do |s| + s.opened?.should be_true + Syslog.opened?.should be_true + end + Syslog.opened?.should be_false end - Syslog.opened?.should be_false end end end diff --git a/spec/ruby/library/syslog/options_spec.rb b/spec/ruby/library/syslog/options_spec.rb index 83ba43503e..814f7daee6 100644 --- a/spec/ruby/library/syslog/options_spec.rb +++ b/spec/ruby/library/syslog/options_spec.rb @@ -1,47 +1,50 @@ require_relative '../../spec_helper' -platform_is_not :windows do - require 'syslog' - - describe "Syslog.options" do - platform_is_not :windows do - - before :each do - Syslog.opened?.should be_false - end - - after :each do - Syslog.opened?.should be_false - end - - it "returns the logging options" do - Syslog.open("rubyspec", Syslog::LOG_PID) - Syslog.options.should == Syslog::LOG_PID - Syslog.close - end - - it "returns nil when the log is closed" do - Syslog.opened?.should be_false - Syslog.options.should == nil - end - - it "defaults to LOG_PID | LOG_CONS" do - Syslog.open - Syslog.options.should == Syslog::LOG_PID | Syslog::LOG_CONS - Syslog.close - end - - it "resets after each open call" do - Syslog.open - Syslog.options.should == Syslog::LOG_PID | Syslog::LOG_CONS - - Syslog.open!("rubyspec", Syslog::LOG_PID) - Syslog.options.should == Syslog::LOG_PID - Syslog.close - - Syslog.open - Syslog.options.should == Syslog::LOG_PID | Syslog::LOG_CONS - Syslog.close +ruby_version_is ""..."3.4" do + + platform_is_not :windows do + require 'syslog' + + describe "Syslog.options" do + platform_is_not :windows do + + before :each do + Syslog.opened?.should be_false + end + + after :each do + Syslog.opened?.should be_false + end + + it "returns the logging options" do + Syslog.open("rubyspec", Syslog::LOG_PID) + Syslog.options.should == Syslog::LOG_PID + Syslog.close + end + + it "returns nil when the log is closed" do + Syslog.opened?.should be_false + Syslog.options.should == nil + end + + it "defaults to LOG_PID | LOG_CONS" do + Syslog.open + Syslog.options.should == Syslog::LOG_PID | Syslog::LOG_CONS + Syslog.close + end + + it "resets after each open call" do + Syslog.open + Syslog.options.should == Syslog::LOG_PID | Syslog::LOG_CONS + + Syslog.open!("rubyspec", Syslog::LOG_PID) + Syslog.options.should == Syslog::LOG_PID + Syslog.close + + Syslog.open + Syslog.options.should == Syslog::LOG_PID | Syslog::LOG_CONS + Syslog.close + end end end end diff --git a/spec/ruby/library/syslog/reopen_spec.rb b/spec/ruby/library/syslog/reopen_spec.rb index a78529fa1f..47861bc1c0 100644 --- a/spec/ruby/library/syslog/reopen_spec.rb +++ b/spec/ruby/library/syslog/reopen_spec.rb @@ -1,10 +1,13 @@ require_relative '../../spec_helper' -platform_is_not :windows do - require_relative 'shared/reopen' - require 'syslog' +ruby_version_is ""..."3.4" do - describe "Syslog.reopen" do - it_behaves_like :syslog_reopen, :reopen + platform_is_not :windows do + require_relative 'shared/reopen' + require 'syslog' + + describe "Syslog.reopen" do + it_behaves_like :syslog_reopen, :reopen + end end end diff --git a/spec/ruby/library/syslog/shared/log.rb b/spec/ruby/library/syslog/shared/log.rb index 12e4ea8366..d6daf3cc67 100644 --- a/spec/ruby/library/syslog/shared/log.rb +++ b/spec/ruby/library/syslog/shared/log.rb @@ -1,39 +1,41 @@ -describe :syslog_log, shared: true do - platform_is_not :windows, :darwin, :solaris, :aix, :android do - before :each do - Syslog.opened?.should be_false - end +ruby_version_is ""..."3.4" do + describe :syslog_log, shared: true do + platform_is_not :windows, :darwin, :solaris, :aix, :android do + before :each do + Syslog.opened?.should be_false + end - after :each do - Syslog.opened?.should be_false - end + after :each do + Syslog.opened?.should be_false + end - it "logs a message" do - -> { - Syslog.open("rubyspec", Syslog::LOG_PERROR) do - Syslog.send(@method, "Hello") - end - }.should output_to_fd(/\Arubyspec(?::| \d+ - -) Hello\n\z/, $stderr) - end + it "logs a message" do + -> { + Syslog.open("rubyspec", Syslog::LOG_PERROR) do + Syslog.send(@method, "Hello") + end + }.should output_to_fd(/\Arubyspec(?::| \d+ - -) Hello\n\z/, $stderr) + end - it "accepts sprintf arguments" do - -> { - Syslog.open("rubyspec", Syslog::LOG_PERROR) do - Syslog.send(@method, "Hello %s", "world") - Syslog.send(@method, "%d dogs", 2) - end - }.should output_to_fd(/\Arubyspec(?::| \d+ - -) Hello world\nrubyspec(?::| \d+ - -) 2 dogs\n\z/, $stderr) - end + it "accepts sprintf arguments" do + -> { + Syslog.open("rubyspec", Syslog::LOG_PERROR) do + Syslog.send(@method, "Hello %s", "world") + Syslog.send(@method, "%d dogs", 2) + end + }.should output_to_fd(/\Arubyspec(?::| \d+ - -) Hello world\nrubyspec(?::| \d+ - -) 2 dogs\n\z/, $stderr) + end - it "works as an alias for Syslog.log" do - level = Syslog.const_get "LOG_#{@method.to_s.upcase}" - -> { - Syslog.open("rubyspec", Syslog::LOG_PERROR) do - Syslog.send(@method, "Hello") - Syslog.log(level, "Hello") - end - # make sure the same thing is written to $stderr. - }.should output_to_fd(/\A(?:rubyspec(?::| \d+ - -) Hello\n){2}\z/, $stderr) + it "works as an alias for Syslog.log" do + level = Syslog.const_get "LOG_#{@method.to_s.upcase}" + -> { + Syslog.open("rubyspec", Syslog::LOG_PERROR) do + Syslog.send(@method, "Hello") + Syslog.log(level, "Hello") + end + # make sure the same thing is written to $stderr. + }.should output_to_fd(/\A(?:rubyspec(?::| \d+ - -) Hello\n){2}\z/, $stderr) + end end end end diff --git a/spec/ruby/library/syslog/shared/reopen.rb b/spec/ruby/library/syslog/shared/reopen.rb index 621437a01d..935349010b 100644 --- a/spec/ruby/library/syslog/shared/reopen.rb +++ b/spec/ruby/library/syslog/shared/reopen.rb @@ -1,40 +1,42 @@ -describe :syslog_reopen, shared: true do - platform_is_not :windows do - before :each do - Syslog.opened?.should be_false - end +ruby_version_is ""..."3.4" do + describe :syslog_reopen, shared: true do + platform_is_not :windows do + before :each do + Syslog.opened?.should be_false + end - after :each do - Syslog.opened?.should be_false - end + after :each do + Syslog.opened?.should be_false + end - it "reopens the log" do - Syslog.open - -> { Syslog.send(@method)}.should_not raise_error - Syslog.opened?.should be_true - Syslog.close - end + it "reopens the log" do + Syslog.open + -> { Syslog.send(@method)}.should_not raise_error + Syslog.opened?.should be_true + Syslog.close + end - it "fails with RuntimeError if the log is closed" do - -> { Syslog.send(@method)}.should raise_error(RuntimeError) - end + it "fails with RuntimeError if the log is closed" do + -> { Syslog.send(@method)}.should raise_error(RuntimeError) + end - it "receives the same parameters as Syslog.open" do - Syslog.open - Syslog.send(@method, "rubyspec", 3, 8) do |s| - s.should == Syslog - s.ident.should == "rubyspec" - s.options.should == 3 - s.facility.should == Syslog::LOG_USER - s.opened?.should be_true + it "receives the same parameters as Syslog.open" do + Syslog.open + Syslog.send(@method, "rubyspec", 3, 8) do |s| + s.should == Syslog + s.ident.should == "rubyspec" + s.options.should == 3 + s.facility.should == Syslog::LOG_USER + s.opened?.should be_true + end + Syslog.opened?.should be_false end - Syslog.opened?.should be_false - end - it "returns the module" do - Syslog.open - Syslog.send(@method).should == Syslog - Syslog.close + it "returns the module" do + Syslog.open + Syslog.send(@method).should == Syslog + Syslog.close + end end end end diff --git a/spec/ruby/library/syslog/warning_spec.rb b/spec/ruby/library/syslog/warning_spec.rb index eeca603136..cf0f7d0dc2 100644 --- a/spec/ruby/library/syslog/warning_spec.rb +++ b/spec/ruby/library/syslog/warning_spec.rb @@ -1,10 +1,13 @@ require_relative '../../spec_helper' -platform_is_not :windows do - require_relative 'shared/log' - require 'syslog' +ruby_version_is ""..."3.4" do - describe "Syslog.warning" do - it_behaves_like :syslog_log, :warning + platform_is_not :windows do + require_relative 'shared/log' + require 'syslog' + + describe "Syslog.warning" do + it_behaves_like :syslog_log, :warning + end end end |