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