Permalink
Browse files

Correctly handle string input.

  • Loading branch information...
1 parent 38dc52a commit cfe4d5e17aae202eba207084d4d0e6a456c47a07 @xaviershay xaviershay committed Oct 21, 2012
Showing with 7 additions and 8 deletions.
  1. +4 −5 lib/cane/threshold_check.rb
  2. +3 −3 spec/threshold_check_spec.rb
@@ -27,7 +27,7 @@ def violations
threshold
]
}
- elsif !value.send(operator, limit.to_f)
+ elsif !value.send(operator, limit)
{
description: 'Quality threshold crossed',
label: "%s is %s, should be %s %s" % [
@@ -39,10 +39,9 @@ def violations
end
def normalized_limit(limit)
- if limit.to_f != limit
- limit = value_from_file(limit)
- end
- limit
+ Float(limit)
+ rescue ArgumentError
+ value_from_file(limit)
end
def value_from_file(file)
@@ -8,17 +8,17 @@
context "when the current coverage cannot be read" do
it 'reports a violation' do
- check = Cane::ThresholdCheck.new(gte: [['bogus_file', 20]])
+ check = Cane::ThresholdCheck.new(gte: [['bogus_file', '20']])
violations = check.violations
violations.length.should == 1
violations[0][:label].should ==
- 'bogus_file is unavailable, should be >= 20'
+ 'bogus_file is unavailable, should be >= 20.0'
end
end
context "when the coverage threshold is incorrectly specified" do
it 'reports a violation' do
- check = Cane::ThresholdCheck.new(gte: [[20, 'bogus_file']])
+ check = Cane::ThresholdCheck.new(gte: [['20', 'bogus_file']])
violations = check.violations
violations.length.should == 1
violations[0][:label].should ==

0 comments on commit cfe4d5e

Please sign in to comment.