File: mask_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 (98 lines) | stat: -rw-r--r-- 2,026 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
require File.dirname(__FILE__) + '/../../spec_helper'
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
    end

    # make sure we return the mask to the default value
    after :all do
      Syslog.open { |s| s.mask = 255 }
    end

    it "returns the log priority mask" do
      Syslog.open("rubyspec")
      Syslog.mask.should == 255
      Syslog.mask = 3
      Syslog.mask.should == 3
      Syslog.mask = 255
      Syslog.close
    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.opened?.should == false
      Syslog.mask.should == nil
    end

    it "persists if the log is reopened" do
      Syslog.open
      Syslog.mask.should == 255
      Syslog.mask = 64

      Syslog.reopen("rubyspec")
      Syslog.mask.should == 64
      Syslog.close

      Syslog.open
      Syslog.mask.should == 64
      Syslog.close
    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
    end

    # make sure we return the mask to the default value
    after :all do
      Syslog.open { |s| s.mask = 255 }
    end

    it "sets the log priority mask" do
      Syslog.open
      Syslog.mask = 64
      Syslog.mask.should == 64
      Syslog.close
    end
    
    it "raises an error if the log is closed" do
      lambda { Syslog.mask = 1337 }.should raise_error(RuntimeError)
    end

    it "only accepts numbers" do
      Syslog.open

      Syslog.mask = 1337
      Syslog.mask.should == 1337

      Syslog.mask = 3.1416
      Syslog.mask.should == 3

      lambda { Syslog.mask = "oh hai" }.should raise_error(TypeError)
      lambda { Syslog.mask = "43" }.should raise_error(TypeError)

      Syslog.close
    end
  end
end