Skip to content

Commit

Permalink
Raise an exception when setting gauge to nil
Browse files Browse the repository at this point in the history
  • Loading branch information
grobie committed Feb 20, 2017
1 parent 5033c15 commit 446c3d9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/prometheus/client/gauge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ def type

# Sets the value for the given label set
def set(labels, value)
unless value.is_a?(Numeric)
raise ArgumentError, 'value must be a number'
end

@values[label_set_for(labels)] = value
end
end
Expand Down
8 changes: 8 additions & 0 deletions spec/prometheus/client/gauge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,13 @@
end.to change { gauge.get(test: 'value') }.from(nil).to(42)
end.to_not change { gauge.get }
end

context 'given an invalid value' do
it 'raises an ArgumentError' do
expect do
gauge.set({}, nil)
end.to raise_exception(ArgumentError)
end
end
end
end

0 comments on commit 446c3d9

Please sign in to comment.