Permalink
Browse files

Fix exception handling specs

  • Loading branch information...
1 parent f769e3e commit 49cd3bceaa16cfc666068d8865be9fc10f6ef95c Eric Chapweske committed Dec 18, 2011
Showing with 11 additions and 7 deletions.
  1. +6 −0 spec/helper.rb
  2. +5 −7 spec/statsd_spec.rb
View
@@ -19,6 +19,12 @@ def recv
res = @buffer.shift
end
+ def break!
+ instance_eval do
+ def send(message, *rest); raise SocketError end
+ end
+ end
+
def clear
@buffer = []
end
View
@@ -23,19 +23,17 @@ def socket; @socket ||= FakeUDPSocket.new end
end
it "should fail silently when encountering an error on send" do
- def @statsd.socket; raise(SocketError) end
-
- @statsd.send('bad signature').must_equal false
+ @statsd.socket.break!
+ assert_equal false, @statsd.increment('foobar')
end
it "should log the exception when a logger is provided" do
- def @statsd.socket; raise(SocketError) end
-
+ @statsd.socket.break!
log = StringIO.new
@statsd.logger = Logger.new(log)
- @statsd.send('bad signature')
- log.string.must_match 'Statsd: wrong number of arguments'
+ @statsd.increment('foobar')
+ log.string.must_match 'Statsd: SocketError'
end
end

0 comments on commit 49cd3bc

Please sign in to comment.