summaryrefslogtreecommitdiff
path: root/spec/ruby/library/syslog
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/syslog')
-rw-r--r--spec/ruby/library/syslog/alert_spec.rb10
-rw-r--r--spec/ruby/library/syslog/close_spec.rb58
-rw-r--r--spec/ruby/library/syslog/constants_spec.rb41
-rw-r--r--spec/ruby/library/syslog/crit_spec.rb10
-rw-r--r--spec/ruby/library/syslog/debug_spec.rb10
-rw-r--r--spec/ruby/library/syslog/emerg_spec.rb16
-rw-r--r--spec/ruby/library/syslog/err_spec.rb10
-rw-r--r--spec/ruby/library/syslog/facility_spec.rb48
-rw-r--r--spec/ruby/library/syslog/ident_spec.rb35
-rw-r--r--spec/ruby/library/syslog/info_spec.rb10
-rw-r--r--spec/ruby/library/syslog/inspect_spec.rb39
-rw-r--r--spec/ruby/library/syslog/instance_spec.rb13
-rw-r--r--spec/ruby/library/syslog/log_spec.rb56
-rw-r--r--spec/ruby/library/syslog/mask_spec.rb113
-rw-r--r--spec/ruby/library/syslog/notice_spec.rb10
-rw-r--r--spec/ruby/library/syslog/open_spec.rb92
-rw-r--r--spec/ruby/library/syslog/opened_spec.rb39
-rw-r--r--spec/ruby/library/syslog/options_spec.rb48
-rw-r--r--spec/ruby/library/syslog/reopen_spec.rb10
-rw-r--r--spec/ruby/library/syslog/shared/log.rb39
-rw-r--r--spec/ruby/library/syslog/shared/reopen.rb40
-rw-r--r--spec/ruby/library/syslog/warning_spec.rb10
22 files changed, 757 insertions, 0 deletions
diff --git a/spec/ruby/library/syslog/alert_spec.rb b/spec/ruby/library/syslog/alert_spec.rb
new file mode 100644
index 0000000000..edff789dc9
--- /dev/null
+++ b/spec/ruby/library/syslog/alert_spec.rb
@@ -0,0 +1,10 @@
+require_relative '../../spec_helper'
+
+platform_is_not :windows do
+ require_relative 'shared/log'
+ require 'syslog'
+
+ describe "Syslog.alert" do
+ it_behaves_like :syslog_log, :alert
+ end
+end
diff --git a/spec/ruby/library/syslog/close_spec.rb b/spec/ruby/library/syslog/close_spec.rb
new file mode 100644
index 0000000000..8c3b67c05b
--- /dev/null
+++ b/spec/ruby/library/syslog/close_spec.rb
@@ -0,0 +1,58 @@
+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
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/syslog/constants_spec.rb b/spec/ruby/library/syslog/constants_spec.rb
new file mode 100644
index 0000000000..fc9db47dd8
--- /dev/null
+++ b/spec/ruby/library/syslog/constants_spec.rb
@@ -0,0 +1,41 @@
+require_relative '../../spec_helper'
+
+platform_is_not :windows do
+ require 'syslog'
+
+ describe "Syslog::Constants" do
+ platform_is_not :windows, :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)
+ end
+ end
+ end
+
+ # 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
+ 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
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/syslog/crit_spec.rb b/spec/ruby/library/syslog/crit_spec.rb
new file mode 100644
index 0000000000..5d3904f719
--- /dev/null
+++ b/spec/ruby/library/syslog/crit_spec.rb
@@ -0,0 +1,10 @@
+require_relative '../../spec_helper'
+
+platform_is_not :windows do
+ require_relative 'shared/log'
+ require 'syslog'
+
+ describe "Syslog.crit" do
+ it_behaves_like :syslog_log, :crit
+ end
+end
diff --git a/spec/ruby/library/syslog/debug_spec.rb b/spec/ruby/library/syslog/debug_spec.rb
new file mode 100644
index 0000000000..d03e8a88c9
--- /dev/null
+++ b/spec/ruby/library/syslog/debug_spec.rb
@@ -0,0 +1,10 @@
+require_relative '../../spec_helper'
+
+platform_is_not :windows do
+ require_relative 'shared/log'
+ require 'syslog'
+
+ describe "Syslog.debug" do
+ it_behaves_like :syslog_log, :debug
+ end
+end
diff --git a/spec/ruby/library/syslog/emerg_spec.rb b/spec/ruby/library/syslog/emerg_spec.rb
new file mode 100644
index 0000000000..2ab4d60291
--- /dev/null
+++ b/spec/ruby/library/syslog/emerg_spec.rb
@@ -0,0 +1,16 @@
+require_relative '../../spec_helper'
+
+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
diff --git a/spec/ruby/library/syslog/err_spec.rb b/spec/ruby/library/syslog/err_spec.rb
new file mode 100644
index 0000000000..43e876ed37
--- /dev/null
+++ b/spec/ruby/library/syslog/err_spec.rb
@@ -0,0 +1,10 @@
+require_relative '../../spec_helper'
+
+platform_is_not :windows do
+ require_relative 'shared/log'
+ require 'syslog'
+
+ describe "Syslog.err" do
+ it_behaves_like :syslog_log, :err
+ end
+end
diff --git a/spec/ruby/library/syslog/facility_spec.rb b/spec/ruby/library/syslog/facility_spec.rb
new file mode 100644
index 0000000000..550ca70b11
--- /dev/null
+++ b/spec/ruby/library/syslog/facility_spec.rb
@@ -0,0 +1,48 @@
+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
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/syslog/ident_spec.rb b/spec/ruby/library/syslog/ident_spec.rb
new file mode 100644
index 0000000000..3b08327140
--- /dev/null
+++ b/spec/ruby/library/syslog/ident_spec.rb
@@ -0,0 +1,35 @@
+require_relative '../../spec_helper'
+
+platform_is_not :windows do
+ require 'syslog'
+
+ describe "Syslog.ident" 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 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
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/syslog/info_spec.rb b/spec/ruby/library/syslog/info_spec.rb
new file mode 100644
index 0000000000..f2d535299c
--- /dev/null
+++ b/spec/ruby/library/syslog/info_spec.rb
@@ -0,0 +1,10 @@
+require_relative '../../spec_helper'
+
+platform_is_not :windows do
+ require_relative 'shared/log'
+ require 'syslog'
+
+ describe "Syslog.info" do
+ it_behaves_like :syslog_log, :info
+ end
+end
diff --git a/spec/ruby/library/syslog/inspect_spec.rb b/spec/ruby/library/syslog/inspect_spec.rb
new file mode 100644
index 0000000000..f45231f8e3
--- /dev/null
+++ b/spec/ruby/library/syslog/inspect_spec.rb
@@ -0,0 +1,39 @@
+require_relative '../../spec_helper'
+
+platform_is_not :windows do
+ require 'syslog'
+
+ describe "Syslog.inspect" 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 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
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/syslog/instance_spec.rb b/spec/ruby/library/syslog/instance_spec.rb
new file mode 100644
index 0000000000..891296c52d
--- /dev/null
+++ b/spec/ruby/library/syslog/instance_spec.rb
@@ -0,0 +1,13 @@
+require_relative '../../spec_helper'
+
+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
new file mode 100644
index 0000000000..0c855b8257
--- /dev/null
+++ b/spec/ruby/library/syslog/log_spec.rb
@@ -0,0 +1,56 @@
+require_relative '../../spec_helper'
+
+platform_is_not :windows do
+ require 'syslog'
+
+ describe "Syslog.log" do
+ platform_is_not :windows, :darwin, :aix, :android do
+
+ before :each do
+ Syslog.opened?.should be_false
+ end
+
+ after :each do
+ Syslog.opened?.should be_false
+ end
+
+ 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
+
+ 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 "fails with TypeError on nil log messages" do
+ Syslog.open do |s|
+ -> { s.log(1, nil) }.should raise_error(TypeError)
+ end
+ 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
new file mode 100644
index 0000000000..b3f1250b24
--- /dev/null
+++ b/spec/ruby/library/syslog/mask_spec.rb
@@ -0,0 +1,113 @@
+require_relative '../../spec_helper'
+
+platform_is_not :windows do
+ require 'syslog'
+
+ describe "Syslog.mask" do
+ platform_is_not :windows do
+
+ 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
+
+ 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
+
+ it "defaults to 255" do
+ Syslog.open do |s|
+ s.mask.should == 255
+ end
+ end
+
+ it "returns nil if the log is closed" do
+ Syslog.should_not.opened?
+ Syslog.mask.should == nil
+ end
+
+ platform_is :darwin do
+ it "resets if the log is reopened" do
+ Syslog.open
+ Syslog.mask.should == 255
+ Syslog.mask = 64
+
+ Syslog.reopen("rubyspec") do
+ Syslog.mask.should == 255
+ end
+
+ Syslog.open do
+ Syslog.mask.should == 255
+ 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
+
+ Syslog.reopen("rubyspec") do
+ Syslog.mask.should == 64
+ end
+
+ Syslog.open do
+ Syslog.mask.should == 64
+ end
+ end
+ end
+ end
+ end
+
+ describe "Syslog.mask=" do
+ platform_is_not :windows do
+
+ 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
+
+ it "sets the log priority mask" do
+ Syslog.open do
+ Syslog.mask = 64
+ Syslog.mask.should == 64
+ end
+ 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
+
+ Syslog.mask = 1337
+ Syslog.mask.should == 1337
+
+ Syslog.mask = 3.1416
+ Syslog.mask.should == 3
+
+ -> { Syslog.mask = "oh hai" }.should raise_error(TypeError)
+ -> { Syslog.mask = "43" }.should raise_error(TypeError)
+
+ end
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/syslog/notice_spec.rb b/spec/ruby/library/syslog/notice_spec.rb
new file mode 100644
index 0000000000..a2134e0140
--- /dev/null
+++ b/spec/ruby/library/syslog/notice_spec.rb
@@ -0,0 +1,10 @@
+require_relative '../../spec_helper'
+
+platform_is_not :windows do
+ require_relative 'shared/log'
+ require 'syslog'
+
+ describe "Syslog.notice" do
+ it_behaves_like :syslog_log, :notice
+ end
+end
diff --git a/spec/ruby/library/syslog/open_spec.rb b/spec/ruby/library/syslog/open_spec.rb
new file mode 100644
index 0000000000..543f5d418b
--- /dev/null
+++ b/spec/ruby/library/syslog/open_spec.rb
@@ -0,0 +1,92 @@
+require_relative '../../spec_helper'
+
+platform_is_not :windows do
+ require_relative 'shared/reopen'
+ require 'syslog'
+
+ describe "Syslog.open" 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 module" do
+ Syslog.open.should == Syslog
+ Syslog.close
+ Syslog.open("Test", 5, 9).should == Syslog
+ Syslog.close
+ end
+
+ it "receives an identity as first argument" do
+ Syslog.open("rubyspec")
+ Syslog.ident.should == "rubyspec"
+ Syslog.close
+ end
+
+ it "defaults the identity to $0" do
+ Syslog.open
+ Syslog.ident.should == $0
+ 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 logging options to LOG_PID | LOG_CONS" do
+ Syslog.open
+ Syslog.options.should == Syslog::LOG_PID | Syslog::LOG_CONS
+ 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
+ end
+ 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
+ -> {
+ Syslog.open
+ }.should raise_error(RuntimeError, /syslog already open/)
+ -> {
+ Syslog.close
+ Syslog.open
+ }.should_not raise_error
+ Syslog.close
+ end
+ end
+ end
+
+ describe "Syslog.open!" do
+ it_behaves_like :syslog_reopen, :open!
+ end
+end
diff --git a/spec/ruby/library/syslog/opened_spec.rb b/spec/ruby/library/syslog/opened_spec.rb
new file mode 100644
index 0000000000..94432e65a4
--- /dev/null
+++ b/spec/ruby/library/syslog/opened_spec.rb
@@ -0,0 +1,39 @@
+require_relative '../../spec_helper'
+
+platform_is_not :windows do
+ require 'syslog'
+
+ describe "Syslog.opened?" 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 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
+ end
+ end
+end
diff --git a/spec/ruby/library/syslog/options_spec.rb b/spec/ruby/library/syslog/options_spec.rb
new file mode 100644
index 0000000000..83ba43503e
--- /dev/null
+++ b/spec/ruby/library/syslog/options_spec.rb
@@ -0,0 +1,48 @@
+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
+ end
+ end
+ end
+end
diff --git a/spec/ruby/library/syslog/reopen_spec.rb b/spec/ruby/library/syslog/reopen_spec.rb
new file mode 100644
index 0000000000..a78529fa1f
--- /dev/null
+++ b/spec/ruby/library/syslog/reopen_spec.rb
@@ -0,0 +1,10 @@
+require_relative '../../spec_helper'
+
+platform_is_not :windows do
+ require_relative 'shared/reopen'
+ require 'syslog'
+
+ describe "Syslog.reopen" do
+ it_behaves_like :syslog_reopen, :reopen
+ end
+end
diff --git a/spec/ruby/library/syslog/shared/log.rb b/spec/ruby/library/syslog/shared/log.rb
new file mode 100644
index 0000000000..9f9302b214
--- /dev/null
+++ b/spec/ruby/library/syslog/shared/log.rb
@@ -0,0 +1,39 @@
+describe :syslog_log, shared: true do
+ platform_is_not :windows, :darwin, :aix, :android do
+ before :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 "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)
+ end
+ end
+end
diff --git a/spec/ruby/library/syslog/shared/reopen.rb b/spec/ruby/library/syslog/shared/reopen.rb
new file mode 100644
index 0000000000..621437a01d
--- /dev/null
+++ b/spec/ruby/library/syslog/shared/reopen.rb
@@ -0,0 +1,40 @@
+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
+
+ 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 "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
+
+ it "returns the module" do
+ Syslog.open
+ Syslog.send(@method).should == Syslog
+ Syslog.close
+ end
+ end
+end
diff --git a/spec/ruby/library/syslog/warning_spec.rb b/spec/ruby/library/syslog/warning_spec.rb
new file mode 100644
index 0000000000..eeca603136
--- /dev/null
+++ b/spec/ruby/library/syslog/warning_spec.rb
@@ -0,0 +1,10 @@
+require_relative '../../spec_helper'
+
+platform_is_not :windows do
+ require_relative 'shared/log'
+ require 'syslog'
+
+ describe "Syslog.warning" do
+ it_behaves_like :syslog_log, :warning
+ end
+end