Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test to make sure request IDs make it into error objects #846

Merged
merged 1 commit into from
Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@ Layout/IndentFirstHashElement:
Layout/IndentHeredoc:
Enabled: false

Metrics/BlockLength:
Max: 40
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we can make this much more restrictive after excluding the test directory. It moves from 509 to 40.

Exclude:
# `context` in tests are blocks and get quite large, so exclude the test
# directory from having to adhere to this rule.
- "test/**/*.rb"

Metrics/ClassLength:
Exclude:
# Test classes get quite large, so exclude the test directory from having
# to adhere to this rule.
- "test/**/*.rb"

Metrics/LineLength:
Expand Down
6 changes: 0 additions & 6 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
Metrics/AbcSize:
Max: 51

# Offense count: 33
# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 509

# Offense count: 12
# Configuration parameters: CountComments.
Metrics/ClassLength:
Expand Down
13 changes: 13 additions & 0 deletions test/stripe/stripe_client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,19 @@ class StripeClientTest < Test::Unit::TestCase
assert_equal 'Invalid response object from API: "" (HTTP response code was 200)', e.message
end

should "feed a request ID through to the error object" do
stub_request(:post, "#{Stripe.api_base}/v1/charges")
.to_return(body: JSON.generate(make_missing_id_error),
headers: { "Request-ID": "req_123" },
status: 400)
client = StripeClient.new

e = assert_raises Stripe::InvalidRequestError do
client.execute_request(:post, "/v1/charges")
end
assert_equal("req_123", e.request_id)
end

should "handle low level error" do
stub_request(:post, "#{Stripe.api_base}/v1/charges")
.to_raise(Errno::ECONNREFUSED.new)
Expand Down