Skip to content

Commit

Permalink
Catches nil api_key values during Client initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfulsome committed Mar 17, 2021
1 parent ec04d75 commit d0df2f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/recurly/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class Client
# @param api_key [String] The private API key
# @param logger [Logger] A logger to use. Defaults to creating a new STDOUT logger with level WARN.
def initialize(api_key:, logger: nil)
raise ArgumentError, "'api_key' must be set to a non-nil value" if api_key.nil?

set_api_key(api_key)

if logger.nil?
Expand Down
12 changes: 12 additions & 0 deletions spec/recurly/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,18 @@
end
end

context "with a missing api key" do
describe "initialize" do
let(:options) { { api_key: nil } }

it "should raise an ArgumentError when api_key is nil" do
expect {
Recurly::Client.new(**options)
}.to raise_error(ArgumentError)
end
end
end

describe "unexpected HTML responses" do
context "with 200 OK" do
let(:response) do
Expand Down

0 comments on commit d0df2f2

Please sign in to comment.