rspec-nagios-formatter 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +1 -0
- data/README.md +25 -0
- data/Rakefile +7 -0
- data/bin/check_rspec +42 -0
- data/features/check_rspec/options.feature +96 -0
- data/features/check_rspec/run.feature +31 -0
- data/features/support/env.rb +1 -0
- data/lib/rspec/nagios/formatter.rb +2 -3
- data/lib/rspec/nagios/version.rb +1 -1
- data/rspec-nagios-formatter.gemspec +2 -1
- metadata +25 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4240c25f93392c262ce1fb69d05cfb483b1b6075
|
4
|
+
data.tar.gz: 4ce8435fc6d4de3424de10c1e680175900fa5bea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f95fe8a95ab32fa17e5dbeb562ed5693e69fc537c02e3c7d9f23c07c53c1c78164e50c57da095dcbe0415101dbc54afea752cf061e65f3b75abbe66a27b69c6
|
7
|
+
data.tar.gz: f547a3190089bba1938f4ad834c82ddc442a1a592137a742ff86fc5cd35c834cf23bd1126ae04c1abc41030323d13d5a67692b4004d8d945c916a4a50ecbe19c
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -25,6 +25,24 @@ Install
|
|
25
25
|
Usage
|
26
26
|
-----
|
27
27
|
|
28
|
+
The formatter may be used by either passing the `-f|--format` flag to `rspec` or with the included `check_rspec` script. The later sets the appropriate exit status for a failing Nagios/Icinga plugin.
|
29
|
+
|
30
|
+
### `check_rspec`
|
31
|
+
|
32
|
+
Usage: check_rspec [options] [--] [passed to rspec]
|
33
|
+
|
34
|
+
Specific options:
|
35
|
+
-t, --timeout TIMEOUT default: 30.0 (seconds)
|
36
|
+
-h, --help Show this message
|
37
|
+
|
38
|
+
Any options to `check_rspec` not prefixed with `-` or `--` are passed directly
|
39
|
+
on to the `rspec` utility. If you need to pass an option flag you may
|
40
|
+
terminated `check_rspec`'s option parsing with a bare `--`.
|
41
|
+
|
42
|
+
check_rspec -- -e 'foo' trivial_spec.rb
|
43
|
+
|
44
|
+
### `rspec`
|
45
|
+
|
28
46
|
rspec -f RSpec::Nagios::Formatter
|
29
47
|
|
30
48
|
See the documentation on [rspec --format](https://www.relishapp.com/rspec/rspec-core/v/2-6/docs/command-line/format-option)
|
@@ -55,3 +73,10 @@ Support
|
|
55
73
|
-------
|
56
74
|
|
57
75
|
Please log tickets and issues at [github](https://github.com/jhoblitt/rspec-nagios-formatter)
|
76
|
+
|
77
|
+
See Also
|
78
|
+
--------
|
79
|
+
|
80
|
+
* [cucumber-nagios](http://auxesis.github.io/cucumber-nagios/)
|
81
|
+
* [RSpec](https://github.com/rspec/rspec)
|
82
|
+
* [Icinga Plugins](http://docs.icinga.org/latest/en/plugins.html)
|
data/Rakefile
CHANGED
data/bin/check_rspec
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'open3'
|
5
|
+
require 'timeout'
|
6
|
+
|
7
|
+
EXIT_CRITICAL = 2
|
8
|
+
|
9
|
+
options = { :timeout => 30.0 }
|
10
|
+
option_parser = OptionParser.new do |opts|
|
11
|
+
opts.banner = "Usage: check_rspec [options] [--] [passed to rspec]"
|
12
|
+
opts.separator ""
|
13
|
+
opts.separator "Specific options:"
|
14
|
+
|
15
|
+
opts.on("-t", "--timeout TIMEOUT", "default: 30.0 (seconds)", Float) do |t|
|
16
|
+
options[:timeout] = t
|
17
|
+
end
|
18
|
+
|
19
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
20
|
+
puts opts
|
21
|
+
exit
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
option_parser.parse!
|
26
|
+
|
27
|
+
cmd = ['rspec', '--format', 'RSpec::Nagios::Formatter', ARGV]
|
28
|
+
cmd_stdout, cmd_stderr, cmd_status = nil
|
29
|
+
|
30
|
+
begin
|
31
|
+
Timeout::timeout(options[:timeout]) {
|
32
|
+
cmd_stdout, cmd_stderr, cmd_status = Open3.capture3(cmd.join(' '))
|
33
|
+
}
|
34
|
+
rescue Timeout::Error
|
35
|
+
puts "RSPEC Critical - timeout after #{options[:timeout]} seconds"
|
36
|
+
exit EXIT_CRITICAL
|
37
|
+
end
|
38
|
+
|
39
|
+
puts cmd_stdout
|
40
|
+
unless cmd_status.exitstatus == 0
|
41
|
+
exit EXIT_CRITICAL
|
42
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
Feature: command line options
|
2
|
+
In order to modifiy the behavior of check_rspec
|
3
|
+
As an Icinga administrator
|
4
|
+
I want to be able to set command line options
|
5
|
+
|
6
|
+
Scenario: run a passing rspec test
|
7
|
+
Given a file named "trivial_spec.rb" with:
|
8
|
+
"""
|
9
|
+
describe do
|
10
|
+
it { true.should == true }
|
11
|
+
end
|
12
|
+
"""
|
13
|
+
When I successfully run `check_rspec trivial_spec.rb`
|
14
|
+
Then the stdout should contain:
|
15
|
+
"""
|
16
|
+
RSPEC OK
|
17
|
+
"""
|
18
|
+
|
19
|
+
Scenario: run a failing rspec test
|
20
|
+
Given a file named "trivial_spec.rb" with:
|
21
|
+
"""
|
22
|
+
describe do
|
23
|
+
it { true.should == false }
|
24
|
+
end
|
25
|
+
"""
|
26
|
+
When I run `check_rspec trivial_spec.rb`
|
27
|
+
Then the exit status should be 2
|
28
|
+
And the stdout should contain:
|
29
|
+
"""
|
30
|
+
RSPEC Critical
|
31
|
+
"""
|
32
|
+
|
33
|
+
Scenario: run a test with --timeout
|
34
|
+
Given a file named "trivial_spec.rb" with:
|
35
|
+
"""
|
36
|
+
describe do
|
37
|
+
it { true.should == true }
|
38
|
+
end
|
39
|
+
"""
|
40
|
+
When I successfully run `check_rspec --timeout 1 trivial_spec.rb`
|
41
|
+
Then the stdout should contain:
|
42
|
+
"""
|
43
|
+
RSPEC OK
|
44
|
+
"""
|
45
|
+
|
46
|
+
Scenario: run a test with --timeout that times out
|
47
|
+
Given a file named "trivial_spec.rb" with:
|
48
|
+
"""
|
49
|
+
describe do
|
50
|
+
it { sleep(1) }
|
51
|
+
end
|
52
|
+
"""
|
53
|
+
When I run `check_rspec --timeout 0.5 trivial_spec.rb`
|
54
|
+
Then the exit status should be 2
|
55
|
+
And the stdout should contain:
|
56
|
+
"""
|
57
|
+
RSPEC Critical - timeout after 0.5 seconds
|
58
|
+
"""
|
59
|
+
|
60
|
+
Scenario: view usage with -h
|
61
|
+
When I successfully run `check_rspec -h`
|
62
|
+
And the stdout should contain:
|
63
|
+
"""
|
64
|
+
Usage: check_rspec [options] [--] [passed to rspec]
|
65
|
+
|
66
|
+
Specific options:
|
67
|
+
-t, --timeout TIMEOUT default: 30.0 (seconds)
|
68
|
+
-h, --help Show this message
|
69
|
+
"""
|
70
|
+
|
71
|
+
Scenario: view usage with --help
|
72
|
+
When I successfully run `check_rspec --help`
|
73
|
+
And the stdout should contain:
|
74
|
+
"""
|
75
|
+
Usage: check_rspec [options] [--] [passed to rspec]
|
76
|
+
|
77
|
+
Specific options:
|
78
|
+
-t, --timeout TIMEOUT default: 30.0 (seconds)
|
79
|
+
-h, --help Show this message
|
80
|
+
"""
|
81
|
+
|
82
|
+
Scenario: pass options to rspec
|
83
|
+
Given a file named "trivial_spec.rb" with:
|
84
|
+
"""
|
85
|
+
describe 'foo' do
|
86
|
+
it { true.should == true }
|
87
|
+
end
|
88
|
+
describe 'bar' do
|
89
|
+
it { true.should == true }
|
90
|
+
end
|
91
|
+
"""
|
92
|
+
When I successfully run `check_rspec -- -e 'foo' trivial_spec.rb`
|
93
|
+
Then the stdout should contain:
|
94
|
+
"""
|
95
|
+
RSPEC OK - 1 example
|
96
|
+
"""
|
@@ -0,0 +1,31 @@
|
|
1
|
+
Feature: run rspec tests
|
2
|
+
In order to monitor the enviroment
|
3
|
+
As an Icinga administrator
|
4
|
+
I want to get RSpec test results in Icinga plugin format
|
5
|
+
|
6
|
+
Scenario: run a passing rspec test
|
7
|
+
Given a file named "trivial_spec.rb" with:
|
8
|
+
"""
|
9
|
+
describe do
|
10
|
+
it { true.should == true }
|
11
|
+
end
|
12
|
+
"""
|
13
|
+
When I successfully run `check_rspec trivial_spec.rb`
|
14
|
+
Then it should pass with regexp:
|
15
|
+
"""
|
16
|
+
^RSPEC OK - 1 example, 0 failures, finished in 0.\d+ seconds | examples=1 passing=1 failures=0 pending=0 conformance=100% time=0.\d+s$
|
17
|
+
"""
|
18
|
+
|
19
|
+
Scenario: run a failing rspec test
|
20
|
+
Given a file named "trivial_spec.rb" with:
|
21
|
+
"""
|
22
|
+
describe do
|
23
|
+
it { true.should == false }
|
24
|
+
end
|
25
|
+
"""
|
26
|
+
When I run `check_rspec trivial_spec.rb`
|
27
|
+
Then the exit status should be 2
|
28
|
+
And it should fail with regexp:
|
29
|
+
"""
|
30
|
+
^RSPEC Critical - 1 example, 1 failures, finished in 0.\d+ seconds | examples=1 passing=0 failures=1 pending=0 conformance=0% time=0.\d+s$
|
31
|
+
"""
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'aruba/cucumber'
|
@@ -14,17 +14,16 @@ class RSpec::Nagios::Formatter < RSpec::Core::Formatters::BaseFormatter
|
|
14
14
|
def summary_line(duration, example_count, failure_count, pending_count)
|
15
15
|
passing_count = example_count - failure_count
|
16
16
|
# conformance is expressed as a percentage
|
17
|
-
# if example_count is zero we need to
|
17
|
+
# if example_count is zero we need to avoid div by 0
|
18
18
|
if example_count > 0
|
19
19
|
conformance = passing_count / example_count.to_f
|
20
20
|
conformance *= 100
|
21
|
-
#conformance = "%.2f" % conformance
|
22
21
|
conformance = conformance.round(0)
|
23
22
|
else
|
24
23
|
conformance = 0
|
25
24
|
end
|
26
25
|
# limit duration precision to microseconds
|
27
|
-
time
|
26
|
+
time = duration.round(6)
|
28
27
|
|
29
28
|
summary = 'RSPEC'
|
30
29
|
if failure_count == 0
|
data/lib/rspec/nagios/version.rb
CHANGED
@@ -18,10 +18,11 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.add_development_dependency("rspec-expectations", ">= 2.0.0")
|
19
19
|
s.add_development_dependency("rspec-mocks", ">= 2.0.0")
|
20
20
|
s.add_development_dependency("rake", ">= 10.0.0")
|
21
|
+
s.add_development_dependency('aruba', '~> 0.4.6')
|
21
22
|
|
22
23
|
s.rubygems_version = ">= 1.6.1"
|
23
24
|
s.files = `git ls-files`.split("\n")
|
24
25
|
s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
|
25
|
-
|
26
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
26
27
|
s.require_path = "lib"
|
27
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-nagios-formatter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joshua Hoblitt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-core
|
@@ -80,10 +80,25 @@ dependencies:
|
|
80
80
|
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 10.0.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: aruba
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.4.6
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.4.6
|
83
97
|
description: A RSpec formatter for the Nagios/Icinga plugin format
|
84
98
|
email:
|
85
99
|
- jhoblitt@cpan.org
|
86
|
-
executables:
|
100
|
+
executables:
|
101
|
+
- check_rspec
|
87
102
|
extensions: []
|
88
103
|
extra_rdoc_files: []
|
89
104
|
files:
|
@@ -93,6 +108,10 @@ files:
|
|
93
108
|
- LICENSE
|
94
109
|
- README.md
|
95
110
|
- Rakefile
|
111
|
+
- bin/check_rspec
|
112
|
+
- features/check_rspec/options.feature
|
113
|
+
- features/check_rspec/run.feature
|
114
|
+
- features/support/env.rb
|
96
115
|
- lib/rspec/nagios.rb
|
97
116
|
- lib/rspec/nagios/formatter.rb
|
98
117
|
- lib/rspec/nagios/version.rb
|
@@ -126,6 +145,9 @@ signing_key:
|
|
126
145
|
specification_version: 4
|
127
146
|
summary: A RSpec formatter for the Nagios/Icinga plugin format
|
128
147
|
test_files:
|
148
|
+
- features/check_rspec/options.feature
|
149
|
+
- features/check_rspec/run.feature
|
150
|
+
- features/support/env.rb
|
129
151
|
- spec/rspec_nagios_formatter_spec.rb
|
130
152
|
- spec/shim_spec.rb
|
131
153
|
- spec/spec_helper.rb
|