my_api_client 0.10.0 → 0.10.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6cd0cadf555eff5fcc7b6ce43f2af6437c89243fa371b8c17eb6db893948c256
4
- data.tar.gz: 9c69a2495c109a11c601bbe770f4f063fa4783f72d567d5b3b4f1a3ded514c99
3
+ metadata.gz: b184fa1b59269203a189c396d43f1b9f63e91c38c6402c22ed77ce30c60f78e6
4
+ data.tar.gz: 05befe929b0d318c2668dfeb3627602c9985e4da4baf8b5a234469d772da4d78
5
5
  SHA512:
6
- metadata.gz: 3b697f923d27cde7834774fc321f39a965f375619c591cb157f7e2743cdc54be44a41d160371e8c85f386159edbf6aeff269123d904c24eba0e6929ef540ec08
7
- data.tar.gz: 8868f50cf3f9b1358b070d5a0261bc9db268ccf90bc2715a478b0a1b82bb6d9d210fd7b022caaafa6c0ee3afa63b1a0efd3566dee4a9e91e4b3541b748cd35c8
6
+ metadata.gz: b788bb9d4ac50f1c0c31f6d24df04e164fe325173f4ece5a01effb2b5b696ea68c7630b56a4e0f6a1b6e001da2ce46b1e4a568e9110729f75c5b7a5d086a20c0
7
+ data.tar.gz: a8d5a2aa67ce54336961ce0a1a79b2461cf38cfa82546f6b9ddbe1f33e09c8bc002aa2cefe2f1f093321d9a6bbaad4003ea5e63c29b4e8858eeb882178cdf7cd
data/.rubocop.yml CHANGED
@@ -14,6 +14,7 @@ Metrics/BlockLength:
14
14
  Max: 50
15
15
  Exclude:
16
16
  - 'my_api_client.gemspec'
17
+ - 'lib/my_api_client/rspec/matchers/**/*'
17
18
  - 'spec/**/*'
18
19
 
19
20
  Metrics/MethodLength:
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Change log
2
2
 
3
+ ## 0.10.1 (Oct 23, 2019)
4
+
5
+ ### Feature
6
+
7
+ * Support `retry_on` testing at shoulda matcher ([#127](git@github.com:ryz310/my_api_client/pull/127))
8
+
3
9
  ## 0.10.0 (Oct 23, 2019)
4
10
 
5
11
  ### Feature
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- my_api_client (0.10.0)
4
+ my_api_client (0.10.1)
5
5
  activesupport (>= 4.2.0)
6
6
  jsonpath
7
7
  sawyer (>= 0.8.2)
data/README.jp.md CHANGED
@@ -406,6 +406,30 @@ it do
406
406
  end
407
407
  ```
408
408
 
409
+ ##### `retry_on` を定義している場合
410
+
411
+ 以下のように `retry_on` を API Client に定義している場合:
412
+
413
+ ```ruby
414
+ class ExampleApiClient < MyApiClient::Base
415
+ endpoint 'https://example.com'
416
+
417
+ error_handling json: { '$.errors.code': 20 }, raise: MyApiClient::ApiLimitError
418
+ retry_on MyApiClient::ApiLimitError, wait: 30.seconds, attempts: 3
419
+ end
420
+ ```
421
+
422
+ `after_retry` と `times` という Custom Matcher を利用することが出来ます。
423
+
424
+ ```ruby
425
+ it do
426
+ expect { api_client.get_users(condition: 'condition') }
427
+ .to be_handled_as_an_error(MyApiClient::ApiLimitError)
428
+ .after_retry(3).times
429
+ .when_receive(status_code: 200, body: { errors: { code: 20 } }.to_json)
430
+ end
431
+ ```
432
+
409
433
  ### Stubbing
410
434
 
411
435
  以下のような `ApiClient` を定義しているとします。
@@ -7,6 +7,7 @@ RSpec::Matchers.define :be_handled_as_an_error do |expected_error_class|
7
7
 
8
8
  match do |api_request|
9
9
  init
10
+ set_validation_for_retry_count
10
11
  handle_error(api_request).is_a? expected_error_class
11
12
  end
12
13
 
@@ -15,8 +16,16 @@ RSpec::Matchers.define :be_handled_as_an_error do |expected_error_class|
15
16
  handle_error(api_request).nil?
16
17
  end
17
18
 
19
+ chain :after_retry, :retry_count
20
+ chain(:times) { nil }
18
21
  chain :when_receive, :expected_response
19
22
 
23
+ description do
24
+ message = "be handled as #{expected_error_class}"
25
+ message += " after retry #{retry_count} times" unless retry_count.nil?
26
+ message
27
+ end
28
+
20
29
  failure_message do |api_request|
21
30
  actual_error = handle_error(api_request)
22
31
  if actual_error.nil?
@@ -34,6 +43,8 @@ RSpec::Matchers.define :be_handled_as_an_error do |expected_error_class|
34
43
  "but it was handled as #{actual_error.class.name}"
35
44
  end
36
45
 
46
+ attr_reader :sawyer
47
+
37
48
  def init
38
49
  disable_logging
39
50
  response = dummy_response(
@@ -41,10 +52,16 @@ RSpec::Matchers.define :be_handled_as_an_error do |expected_error_class|
41
52
  headers: expected_response[:headers] || {},
42
53
  body: expected_response[:body] || nil
43
54
  )
44
- sawyer = instance_double(Sawyer::Agent, call: response)
55
+ @sawyer = instance_double(Sawyer::Agent, call: response, sleep: nil)
45
56
  allow(Sawyer::Agent).to receive(:new).and_return(sawyer)
46
57
  end
47
58
 
59
+ def set_validation_for_retry_count
60
+ return if retry_count.nil?
61
+
62
+ expect(sawyer).to receive(:call).exactly(retry_count + 1).times
63
+ end
64
+
48
65
  def handle_error(api_request)
49
66
  api_request.call
50
67
  rescue MyApiClient::Error => e
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MyApiClient
4
- VERSION = '0.10.0'
4
+ VERSION = '0.10.1'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: my_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ryz310