From ffe9604fc9f9e54ffa14c99ab45b6f8e4457f6f9 Mon Sep 17 00:00:00 2001 From: Daniel Worrall Date: Wed, 22 May 2019 17:47:52 +0100 Subject: Rate Limit Spec and less 1 letter vars --- spec/rate_limiter_spec.cr | 20 ++++++++++++++++++++ src/twitch/irc/connection.cr | 4 ++-- 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 spec/rate_limiter_spec.cr diff --git a/spec/rate_limiter_spec.cr b/spec/rate_limiter_spec.cr new file mode 100644 index 0000000..345aa1a --- /dev/null +++ b/spec/rate_limiter_spec.cr @@ -0,0 +1,20 @@ +require "./spec_helper" + +describe RateLimiter do + describe "#rate_limited?" do + it "does the thing" do + limiter = RateLimiter(String).new + limiter.bucket(:foo, 5_u32, 1.seconds) + limiter.rate_limited?(:foo, "z64") + sleep 0.9 + 3.times do + limiter.rate_limited?(:foo, "z64") + end + sleep 0.2 + 3.times do + limiter.rate_limited?(:foo, "z64") + end + limiter.rate_limited?(:foo, "z64").should be_truthy + end + end +end \ No newline at end of file diff --git a/src/twitch/irc/connection.cr b/src/twitch/irc/connection.cr index daf6a05..b2647f7 100644 --- a/src/twitch/irc/connection.cr +++ b/src/twitch/irc/connection.cr @@ -38,8 +38,8 @@ class Twitch::IRC::Connection else socket.on_message do |message| reader = FastIRC::Reader.new(IO::Memory.new(message)) - while m = reader.next - @on_message.try &.call(m) + while msg = reader.next + @on_message.try &.call(msg) end end socket.run -- cgit v1.2.3