diff options
Diffstat (limited to 'spec/ruby/library/syslog/shared')
| -rw-r--r-- | spec/ruby/library/syslog/shared/log.rb | 39 | ||||
| -rw-r--r-- | spec/ruby/library/syslog/shared/reopen.rb | 40 |
2 files changed, 79 insertions, 0 deletions
diff --git a/spec/ruby/library/syslog/shared/log.rb b/spec/ruby/library/syslog/shared/log.rb new file mode 100644 index 0000000000..98ce4f54b2 --- /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 == false + end + + after :each do + Syslog.opened?.should == 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..f04408e807 --- /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 == false + end + + after :each do + Syslog.opened?.should == false + end + + it "reopens the log" do + Syslog.open + -> { Syslog.send(@method)}.should_not.raise + Syslog.opened?.should == true + Syslog.close + end + + it "fails with RuntimeError if the log is closed" do + -> { Syslog.send(@method)}.should.raise(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 == true + end + Syslog.opened?.should == false + end + + it "returns the module" do + Syslog.open + Syslog.send(@method).should == Syslog + Syslog.close + end + end +end |
