nagios_check 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,7 +9,7 @@ module NagiosCheck
9
9
  unless tokens
10
10
  raise RuntimeError, "Pattern should be of form [@][~][min]:max"
11
11
  end
12
- @exclusive = true if tokens.include? "@"
12
+ @inverse = true if tokens.include? "@"
13
13
  case tokens[2]
14
14
  when nil, "" then @min = 0
15
15
  when '~' then @min = nil
@@ -19,11 +19,8 @@ module NagiosCheck
19
19
  end
20
20
 
21
21
  def include?(value)
22
- if @exclusive
23
- (@min.nil? || value > @min) && (@max.nil? || value < @max)
24
- else
25
- (@min.nil? || value >= @min) && (@max.nil? || value <= @max)
26
- end
22
+ result = (@min.nil? || value >= @min) && (@max.nil? || value <= @max)
23
+ @inverse ? not(result) : result
27
24
  end
28
25
 
29
26
  def ===(value)
@@ -1,3 +1,3 @@
1
1
  module NagiosCheck
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/spec/range_spec.rb CHANGED
@@ -12,119 +12,145 @@ describe NagiosCheck::Range do
12
12
  end
13
13
 
14
14
  context "when pattern is 10" do
15
- it { should_not contain -1 }
16
- it { should contain 0 }
17
- it { should contain 0.1 }
18
- it { should contain 1 }
19
- it { should contain 9 }
20
- it { should contain 9.9 }
21
- it { should contain 10 }
22
- it { should contain 10.0 }
23
- it { should_not contain 10.1 }
15
+ it { should alert_if -1 }
16
+ it { should_not alert_if 0 }
17
+ it { should_not alert_if 0.1 }
18
+ it { should_not alert_if 1 }
19
+ it { should_not alert_if 9 }
20
+ it { should_not alert_if 9.9 }
21
+ it { should_not alert_if 10 }
22
+ it { should_not alert_if 10.0 }
23
+ it { should alert_if 10.1 }
24
24
  end
25
25
 
26
26
  context "when pattern is :10" do
27
- it { should_not contain -1 }
28
- it { should contain 0 }
29
- it { should contain 0.1 }
30
- it { should contain 1 }
31
- it { should contain 9 }
32
- it { should contain 9.9 }
33
- it { should contain 10 }
34
- it { should contain 10.0 }
35
- it { should_not contain 10.1 }
27
+ it { should alert_if -1 }
28
+ it { should_not alert_if 0 }
29
+ it { should_not alert_if 0.1 }
30
+ it { should_not alert_if 1 }
31
+ it { should_not alert_if 9 }
32
+ it { should_not alert_if 9.9 }
33
+ it { should_not alert_if 10 }
34
+ it { should_not alert_if 10.0 }
35
+ it { should alert_if 10.1 }
36
36
  end
37
37
 
38
38
  context "when pattern is @:10" do
39
- it { should_not contain -1 }
40
- it { should_not contain 0 }
41
- it { should contain 5 }
42
- it { should_not contain 10 }
43
- it { should_not contain 10.0 }
44
- it { should_not contain 11 }
39
+ it { should_not alert_if -1 }
40
+ it { should alert_if 0 }
41
+ it { should alert_if 5 }
42
+ it { should alert_if 10 }
43
+ it { should alert_if 10.0 }
44
+ it { should_not alert_if 11 }
45
45
  end
46
46
 
47
47
  context "when pattern is 10:" do
48
- it { should_not contain -1 }
49
- it { should_not contain 1 }
50
- it { should_not contain 9.9 }
51
- it { should contain 10 }
52
- it { should contain 10.0 }
53
- it { should contain 10.1 }
54
- it { should contain 11 }
48
+ it { should alert_if -1 }
49
+ it { should alert_if 1 }
50
+ it { should alert_if 9.9 }
51
+ it { should_not alert_if 10 }
52
+ it { should_not alert_if 10.0 }
53
+ it { should_not alert_if 10.1 }
54
+ it { should_not alert_if 11 }
55
55
  end
56
56
 
57
57
  context "when pattern is @10:" do
58
- it { should_not contain -1 }
59
- it { should_not contain 1 }
60
- it { should_not contain 9.9 }
61
- it { should_not contain 10 }
62
- it { should_not contain 10.0 }
63
- it { should contain 10.1 }
64
- it { should contain 11 }
58
+ it { should_not alert_if -1 }
59
+ it { should_not alert_if 1 }
60
+ it { should_not alert_if 9.9 }
61
+ it { should alert_if 10 }
62
+ it { should alert_if 10.0 }
63
+ it { should alert_if 10.1 }
64
+ it { should alert_if 11 }
65
65
  end
66
66
 
67
67
  context "when pattern is 10:11" do
68
- it { should_not contain -1 }
69
- it { should_not contain 1 }
70
- it { should_not contain 9.9 }
71
- it { should contain 10 }
72
- it { should contain 10.0 }
73
- it { should contain 10.1 }
74
- it { should contain 10.9 }
75
- it { should contain 11 }
76
- it { should_not contain 11.1 }
77
- it { should_not contain 12 }
68
+ it { should alert_if -1 }
69
+ it { should alert_if 1 }
70
+ it { should alert_if 9.9 }
71
+ it { should_not alert_if 10 }
72
+ it { should_not alert_if 10.0 }
73
+ it { should_not alert_if 10.1 }
74
+ it { should_not alert_if 10.9 }
75
+ it { should_not alert_if 11 }
76
+ it { should alert_if 11.1 }
77
+ it { should alert_if 12 }
78
78
  end
79
79
 
80
+ context "when pattern is 10:10" do
81
+ it { should alert_if -1 }
82
+ it { should alert_if 1 }
83
+ it { should alert_if 9.9 }
84
+ it { should_not alert_if 10 }
85
+ it { should_not alert_if 10.0 }
86
+ it { should alert_if 10.1 }
87
+ it { should alert_if 10.9 }
88
+ it { should alert_if 11 }
89
+ it { should alert_if 11.1 }
90
+ it { should alert_if 12 }
91
+ end
92
+
93
+ context "when pattern is @10:10" do
94
+ it { should_not alert_if -1 }
95
+ it { should_not alert_if 1 }
96
+ it { should_not alert_if 9.9 }
97
+ it { should alert_if 10 }
98
+ it { should alert_if 10.0 }
99
+ it { should_not alert_if 10.1 }
100
+ it { should_not alert_if 10.9 }
101
+ it { should_not alert_if 11 }
102
+ it { should_not alert_if 11.1 }
103
+ it { should_not alert_if 12 }
104
+ end
105
+
80
106
  context "when pattern is @10:11" do
81
- it { should_not contain -1 }
82
- it { should_not contain 1 }
83
- it { should_not contain 9.9 }
84
- it { should_not contain 10 }
85
- it { should_not contain 10.0 }
86
- it { should contain 10.1 }
87
- it { should_not contain 11 }
88
- it { should_not contain 11.1 }
89
- it { should_not contain 12 }
107
+ it { should_not alert_if -1 }
108
+ it { should_not alert_if 1 }
109
+ it { should_not alert_if 9.9 }
110
+ it { should alert_if 10 }
111
+ it { should alert_if 10.0 }
112
+ it { should alert_if 10.1 }
113
+ it { should alert_if 11 }
114
+ it { should_not alert_if 11.1 }
115
+ it { should_not alert_if 12 }
90
116
  end
91
117
 
92
118
  context "when pattern is @10.05:11.05" do
93
- it { should_not contain -1 }
94
- it { should_not contain 1 }
95
- it { should_not contain 9.9 }
96
- it { should_not contain 10 }
97
- it { should_not contain 10.0 }
98
- it { should contain 10.1 }
99
- it { should contain 11 }
100
- it { should_not contain 11.1 }
101
- it { should_not contain 12 }
119
+ it { should_not alert_if -1 }
120
+ it { should_not alert_if 1 }
121
+ it { should_not alert_if 9.9 }
122
+ it { should_not alert_if 10 }
123
+ it { should_not alert_if 10.0 }
124
+ it { should alert_if 10.1 }
125
+ it { should alert_if 11 }
126
+ it { should_not alert_if 11.1 }
127
+ it { should_not alert_if 12 }
102
128
  end
103
129
 
104
130
  context "when pattern is -1:1" do
105
- it { should_not contain -2 }
106
- it { should contain -1 }
107
- it { should contain -0.9 }
108
- it { should contain 0 }
109
- it { should contain 0.9 }
110
- it { should contain 1 }
111
- it { should_not contain 2 }
131
+ it { should alert_if -2 }
132
+ it { should_not alert_if -1 }
133
+ it { should_not alert_if -0.9 }
134
+ it { should_not alert_if 0 }
135
+ it { should_not alert_if 0.9 }
136
+ it { should_not alert_if 1 }
137
+ it { should alert_if 2 }
112
138
  end
113
139
 
114
140
  context "when pattern is ~:1" do
115
- it { should contain -2 }
116
- it { should contain -1 }
117
- it { should contain 0 }
118
- it { should contain 1 }
119
- it { should_not contain 2 }
141
+ it { should_not alert_if -2 }
142
+ it { should_not alert_if -1 }
143
+ it { should_not alert_if 0 }
144
+ it { should_not alert_if 1 }
145
+ it { should alert_if 2 }
120
146
  end
121
147
 
122
148
  context "when pattern is @~:1" do
123
- it { should contain -2 }
124
- it { should contain -1 }
125
- it { should contain 0 }
126
- it { should_not contain 1 }
127
- it { should_not contain 2 }
149
+ it { should alert_if -2 }
150
+ it { should alert_if -1 }
151
+ it { should alert_if 0 }
152
+ it { should alert_if 1 }
153
+ it { should_not alert_if 2 }
128
154
  end
129
155
 
130
156
  context "when nil pattern" do
data/spec/spec_helper.rb CHANGED
@@ -8,19 +8,19 @@ module Matchers
8
8
 
9
9
  def matches?(actual)
10
10
  @actual = actual
11
- @actual.include? @expected
11
+ !@actual.include?(@expected)
12
12
  end
13
13
 
14
14
  def failure_message
15
- "expected #{@actual} to contain #{@expected}"
15
+ "expected #{@actual} to alert for value #{@expected}"
16
16
  end
17
17
 
18
18
  def negative_failure_message
19
- "expected #{@actual} not to contain #{@expected}"
19
+ "expected #{@actual} not to alert for value #{@expected}"
20
20
  end
21
21
  end
22
22
 
23
- def contain(value)
23
+ def alert_if(value)
24
24
  Contain::new(value)
25
25
  end
26
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nagios_check
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-19 00:00:00.000000000 Z
12
+ date: 2013-01-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
85
  version: '0'
86
86
  requirements: []
87
87
  rubyforge_project: nagios_check
88
- rubygems_version: 1.8.24
88
+ rubygems_version: 1.8.23
89
89
  signing_key:
90
90
  specification_version: 3
91
91
  summary: Ruby Nagios Check Integration