File: open_spec.rb

package info (click to toggle)
dlr-languages 20090805%2Bgit.e6b28d27%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 51,484 kB
  • ctags: 59,257
  • sloc: cs: 298,829; ruby: 159,643; xml: 19,872; python: 2,820; yacc: 1,960; makefile: 96; sh: 65
file content (84 lines) | stat: -rw-r--r-- 2,072 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
require File.dirname(__FILE__) + '/../../spec_helper'
require File.dirname(__FILE__) + '/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
      lambda { Syslog.open}.should raise_error
      lambda { Syslog.close; Syslog.open }.should_not raise_error
      Syslog.close
    end
  end
end

describe "Syslog.open!" do
  it_behaves_like :syslog_reopen, :open!
end