From 5df3f32cd81c3b0ac4a57ff5b53b8c230fd7b49f Mon Sep 17 00:00:00 2001 From: Martyn Loughran Date: Thu, 21 Jun 2012 17:55:51 +0100 Subject: [PATCH] Check that block given to Request#authenticate --- lib/signature.rb | 1 + spec/signature_spec.rb | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/lib/signature.rb b/lib/signature.rb index 00bc576..7b1b477 100644 --- a/lib/signature.rb +++ b/lib/signature.rb @@ -82,6 +82,7 @@ def authenticate_by_token(token, timestamp_grace = 600) end def authenticate(timestamp_grace = 600, &block) + raise ArgumentError, "Block required" unless block_given? key = @auth_hash['auth_key'] raise AuthenticationError, "Authentication key required" unless key token = yield key diff --git a/spec/signature_spec.rb b/spec/signature_spec.rb index 3167669..918974e 100644 --- a/spec/signature_spec.rb +++ b/spec/signature_spec.rb @@ -189,6 +189,13 @@ request.authenticate { |key| nil } }.should raise_error('Invalid authentication key') end + + it "should raise unless block given" do + request = Signature::Request.new('POST', '/some/path', @params) + lambda { + request.authenticate + }.should raise_error(ArgumentError, "Block required") + end end end end