rspec-nagios-formatter 0.0.2 → 0.0.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d58a49d2635f47cc08c23104166cb3d47983fd4f
4
- data.tar.gz: 3c64f85521fa092f5ae9e1db8592e5cd6db2b84a
3
+ metadata.gz: 8b72496752c108b2f355a8f5368425e3eb2cbc48
4
+ data.tar.gz: fd03b3be2958a68fe30797d394f42b9d8a45fb1c
5
5
  SHA512:
6
- metadata.gz: c9f7d2a813a6fe2cceb5b7f9353fa12cac5d52e0740c21737a6ff4d305da20b2ffff17d0bf617a6047731287df3b502f16eef68215f221e6adb4f1f2e62b7f67
7
- data.tar.gz: a39d2dce238ef7679b366af96c24df1ce464fb204cf92f9cbdb6f626fb91f369e62240b32c0202b4eb0857a7112e23a84f50d0cbd7c25a6da20f4094de300e2a
6
+ metadata.gz: 68e4276d41375c06a5bec19e0f4a821c6dd63962524a195bdd02a19424373dfc98e064ccde41284e2201cc1e06d3183f62679aad20331a8f3d7b0f9aceac290b
7
+ data.tar.gz: ffe8f0b808867c264b8e3d82043768129b0c0f2c8ea2e59d84d9d7e1d48c9a0c153b7b62aee4d1348a2555568418b3e94f161037755f5fcc486ac179ec5676bc
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ pkg/
2
+ spec/fixtures/
3
+ Gemfile.lock
4
+ *.orig
5
+ *.rej
6
+ *.patch
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
6
+ notifications:
7
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (C) 2013 Joshua Hoblitt <jhoblitt@cpan.org>
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ Ruby rspec-nagios-formatter Gem
2
+ ===============================
3
+
4
+ [![Build Status](https://travis-ci.org/jhoblitt/rspec-nagios-formatter.png)](https://travis-ci.org/jhoblitt/rspec-nagios-formatter)
5
+
6
+
7
+ Description
8
+ -----------
9
+
10
+ This `gem` provides a simple [RSpec](http://rspec.info/) [custom formatter](https://www.relishapp.com/rspec/rspec-core/docs/formatters/custom-formatters) that reports `rspec` results in the Nagios/Icigna [plugin](http://docs.icinga.org/latest/en/pluginapi.html#outputspec) output format.
11
+
12
+ Install
13
+ -------
14
+
15
+ ### via rubygems
16
+
17
+ gem install rspec-nagios-formatter
18
+
19
+ ### from git repo
20
+
21
+ bundle install
22
+ bundle exec rake install
23
+
24
+
25
+ Usage
26
+ -----
27
+
28
+ rspec -f RSpec::Nagios::Formatter
29
+
30
+ See the documentation on [rspec --format](https://www.relishapp.com/rspec/rspec-core/v/2-6/docs/command-line/format-option)
31
+ for more information.
32
+
33
+
34
+ Demo
35
+ ----
36
+
37
+ Demonstration of running this gem's `rspec` tests with it's own formatter
38
+ (after it's been installed).
39
+
40
+ ### Default RSpec formatter
41
+
42
+ $ bundle exec rspec
43
+ .......
44
+
45
+ Finished in 0.00268 seconds
46
+ 7 examples, 0 failures
47
+
48
+ ### Formatted with RSpec::Nagios::Formatter
49
+
50
+ $ bundle exec rspec -f RSpec::Nagios::Formatter
51
+ RSPEC OK - 7 examples, 0 failures, finished in 0.00244 seconds | examples=7 passing=7 failures=0 pending=0 conformance=100% time=0.00244s
52
+
53
+
54
+ Support
55
+ -------
56
+
57
+ Please log tickets and issues at [github](https://github.com/jhoblitt/rspec-nagios-formatter)
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => [
7
+ :spec,
8
+ ]
@@ -0,0 +1,5 @@
1
+ module RSpec
2
+ module Nagios
3
+ require 'rspec/nagios/formatter'
4
+ end
5
+ end
@@ -0,0 +1,49 @@
1
+ require 'rspec/nagios'
2
+ require 'rspec/core/formatters/base_formatter'
3
+
4
+ class RSpec::Nagios::Formatter < RSpec::Core::Formatters::BaseFormatter
5
+ def initialize(output)
6
+ super(output)
7
+ end
8
+
9
+ def dump_summary(duration, example_count, failure_count, pending_count)
10
+ super(duration, example_count, failure_count, pending_count)
11
+ output.puts summary_line(duration, example_count, failure_count, pending_count)
12
+ end
13
+
14
+ def summary_line(duration, example_count, failure_count, pending_count)
15
+ passing_count = example_count - failure_count
16
+ # conformance is expressed as a percentage
17
+ # if example_count is zero we need to aviod div by 0
18
+ if example_count > 0
19
+ conformance = passing_count / example_count.to_f
20
+ conformance *= 100
21
+ #conformance = "%.2f" % conformance
22
+ conformance = conformance.round(0)
23
+ else
24
+ conformance = 0
25
+ end
26
+ # limit duration precision to microseconds
27
+ time = duration.round(6)
28
+
29
+ summary = 'RSPEC'
30
+ if failure_count == 0
31
+ summary << " OK"
32
+ else
33
+ summary << " Critical"
34
+ end
35
+ summary << " - " << pluralize(example_count, "example")
36
+ summary << ", " << pluralize(failure_count, "failure")
37
+ summary << ", #{pending_count} pending" if pending_count > 0
38
+ summary << ", finished in #{time} seconds"
39
+
40
+ summary << " | examples=#{example_count}"
41
+ summary << " passing=#{example_count - failure_count}"
42
+ summary << " failures=#{failure_count}"
43
+ summary << " pending=#{pending_count}"
44
+ summary << " conformance=#{conformance}%"
45
+ summary << " time=#{time}s"
46
+
47
+ summary
48
+ end
49
+ end
@@ -0,0 +1,5 @@
1
+ module RSpec
2
+ module Nagios
3
+ VERSION = '0.0.3'
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ require 'rspec/nagios/formatter'
2
+
3
+ RSpecNagiosFormatter = RSpec::Nagios::Formatter
@@ -0,0 +1,27 @@
1
+ $LOAD_PATH.push File.expand_path("../lib", __FILE__)
2
+ require "rspec/nagios/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "rspec-nagios-formatter"
6
+ s.version = RSpec::Nagios::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = ["Joshua Hoblitt"]
9
+ s.email = ["jhoblitt@cpan.org"]
10
+ s.homepage = "https://github.com/jhoblitt/rspec-nagios-formatter"
11
+ s.summary = %q{A RSpec formatter for the Nagios/Icinga plugin format}
12
+ s.description = %q{A RSpec formatter for the Nagios/Icinga plugin format}
13
+ s.license = "Apache 2.0"
14
+
15
+ s.required_ruby_version = ">= 1.9.2"
16
+ s.add_runtime_dependency("rspec-core", ">= 2.0.0")
17
+ s.add_development_dependency("rspec", ">= 2.0.0")
18
+ s.add_development_dependency("rspec-expectations", ">= 2.0.0")
19
+ s.add_development_dependency("rspec-mocks", ">= 2.0.0")
20
+ s.add_development_dependency("rake", ">= 10.0.0")
21
+
22
+ s.rubygems_version = ">= 1.6.1"
23
+ s.files = `git ls-files`.split("\n")
24
+ s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
25
+ # s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
26
+ s.require_path = "lib"
27
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe RSpec::Nagios::Formatter do
4
+ let(:output) { StringIO.new }
5
+ let(:formatter) { RSpec::Nagios::Formatter.new(output) }
6
+
7
+ describe "#summary_line" do
8
+ context 'status OK' do
9
+ it do
10
+ expect(formatter.summary_line(42,0,0,0)).to eq(
11
+ "RSPEC OK - 0 examples, 0 failures, finished in 42.0 seconds" +
12
+ " | examples=0 passing=0 failures=0 pending=0 conformance=0% time=42.0s"
13
+ )
14
+ end
15
+
16
+ it do
17
+ expect(formatter.summary_line(42,1,0,0)).to eq(
18
+ "RSPEC OK - 1 example, 0 failures, finished in 42.0 seconds" +
19
+ " | examples=1 passing=1 failures=0 pending=0 conformance=100% time=42.0s"
20
+ )
21
+ end
22
+
23
+ it do
24
+ expect(formatter.summary_line(42,2,0,1)).to eq(
25
+ "RSPEC OK - 2 examples, 0 failures, 1 pending, finished in 42.0 seconds" +
26
+ " | examples=2 passing=2 failures=0 pending=1 conformance=100% time=42.0s"
27
+ )
28
+ end
29
+ end
30
+
31
+ context 'status Critical' do
32
+ it do
33
+ expect(formatter.summary_line(42,1,1,0)).to eq(
34
+ "RSPEC Critical - 1 example, 1 failure, finished in 42.0 seconds" +
35
+ " | examples=1 passing=0 failures=1 pending=0 conformance=0% time=42.0s"
36
+ )
37
+ end
38
+
39
+ it do
40
+ expect(formatter.summary_line(42,2,1,1)).to eq(
41
+ "RSPEC Critical - 2 examples, 1 failure, 1 pending, finished in 42.0 seconds" +
42
+ " | examples=2 passing=1 failures=1 pending=1 conformance=50% time=42.0s"
43
+ )
44
+ end
45
+
46
+ it do
47
+ expect(formatter.summary_line(42,6,2,2)).to eq(
48
+ "RSPEC Critical - 6 examples, 2 failures, 2 pending, finished in 42.0 seconds" +
49
+ " | examples=6 passing=4 failures=2 pending=2 conformance=67% time=42.0s"
50
+ )
51
+ end
52
+ end
53
+ end
54
+ end
data/spec/shim_spec.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'rspec_nagios_formatter'
2
+ require 'spec_helper'
3
+
4
+ describe RSpecNagiosFormatter do
5
+ let(:output) { StringIO.new }
6
+ let(:formatter) { RSpecNagiosFormatter.new(output) }
7
+
8
+ it 'should be an alias of RSpec::Nagios::Formatter' do
9
+ formatter.should be_kind_of(RSpec::Nagios::Formatter)
10
+ end
11
+ end
@@ -0,0 +1 @@
1
+ require 'rspec/nagios/formatter'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-nagios-formatter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Hoblitt
@@ -86,7 +86,21 @@ email:
86
86
  executables: []
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
- files: []
89
+ files:
90
+ - .gitignore
91
+ - .travis.yml
92
+ - Gemfile
93
+ - LICENSE
94
+ - README.md
95
+ - Rakefile
96
+ - lib/rspec/nagios.rb
97
+ - lib/rspec/nagios/formatter.rb
98
+ - lib/rspec/nagios/version.rb
99
+ - lib/rspec_nagios_formatter.rb
100
+ - rspec-nagios-formatter.gemspec
101
+ - spec/rspec_nagios_formatter_spec.rb
102
+ - spec/shim_spec.rb
103
+ - spec/spec_helper.rb
90
104
  homepage: https://github.com/jhoblitt/rspec-nagios-formatter
91
105
  licenses:
92
106
  - Apache 2.0
@@ -111,4 +125,7 @@ rubygems_version: 2.1.5
111
125
  signing_key:
112
126
  specification_version: 4
113
127
  summary: A RSpec formatter for the Nagios/Icinga plugin format
114
- test_files: []
128
+ test_files:
129
+ - spec/rspec_nagios_formatter_spec.rb
130
+ - spec/shim_spec.rb
131
+ - spec/spec_helper.rb