From 761dc80ba338e70aaee187334d60c91beb7c25bd Mon Sep 17 00:00:00 2001 From: Brandur Date: Wed, 4 Sep 2019 14:18:36 -0700 Subject: [PATCH] Add a test to make sure request IDs make it into error objects Follows up #845 to make sure that this sort of regression is much more difficult in the future by adding a test that makes sure a request ID is threaded all the way from an HTTP response back through to an error object. I verified that the test failed before #845 came in. --- .rubocop.yml | 9 +++++++++ .rubocop_todo.yml | 6 ------ test/stripe/stripe_client_test.rb | 13 +++++++++++++ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 6e531c80f..0fdbf93d4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -19,8 +19,17 @@ Layout/IndentFirstHashElement: Layout/IndentHeredoc: Enabled: false +Metrics/BlockLength: + Max: 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: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5d1ea8c17..008fd20de 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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: diff --git a/test/stripe/stripe_client_test.rb b/test/stripe/stripe_client_test.rb index 3f22242f4..59a2e5254 100644 --- a/test/stripe/stripe_client_test.rb +++ b/test/stripe/stripe_client_test.rb @@ -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)