Skip to content

Commit

Permalink
compatible with ruby 1.8.7, information abould failed scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffersongirao committed May 20, 2014
1 parent 40a0f1b commit 197d0ae
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ Gemfile.lock
*.rej
*.patch
tmp/aruba/
.ruby-version
2 changes: 1 addition & 1 deletion bin/check_rspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby

require 'optparse'
require 'open3'
require 'open3_backport'
require 'timeout'

EXIT_CRITICAL = 2
Expand Down
12 changes: 10 additions & 2 deletions lib/rspec/nagios/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@ def dump_summary(duration, example_count, failure_count, pending_count)
output.puts summary_line(duration, example_count, failure_count, pending_count)
end

def rounding(float, precision)
return ((float * 10**precision).round.to_f) / (10**precision)
end

def summary_line(duration, example_count, failure_count, pending_count)
passing_count = example_count - failure_count
# conformance is expressed as a percentage
# if example_count is zero we need to avoid div by 0
if example_count > 0
conformance = passing_count / example_count.to_f
conformance *= 100
conformance = conformance.round(0)
conformance = conformance.round
else
conformance = 0
end
# limit duration precision to microseconds
time = duration.round(6)
time = rounding(duration, 6)

summary = 'RSPEC'
if failure_count == 0
Expand All @@ -42,6 +46,10 @@ def summary_line(duration, example_count, failure_count, pending_count)
summary << " pending=#{pending_count}"
summary << " conformance=#{conformance}%"
summary << " time=#{time}s"
if failed_examples.size > 0
summary << "\n"
summary << "#{failed_examples.map { |e| "#{e.metadata.send(:location)} #{e.full_description}" }.join("\n") }"
end

summary
end
Expand Down
3 changes: 2 additions & 1 deletion rspec-nagios-formatter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ Gem::Specification.new do |s|
s.description = %q{A RSpec formatter for the Nagios/Icinga plugin format}
s.license = "Apache 2.0"

s.required_ruby_version = ">= 1.9.2"
s.required_ruby_version = ">= 1.8.7"
s.add_runtime_dependency("rspec-core", ">= 2.0.0")
s.add_runtime_dependency("open3_backport", ">= 0.0.3")
s.add_development_dependency("rspec", ">= 2.0.0")
s.add_development_dependency("rspec-expectations", ">= 2.0.0")
s.add_development_dependency("rspec-mocks", ">= 2.0.0")
Expand Down

0 comments on commit 197d0ae

Please sign in to comment.