aws-sdk-core 2.0.0.rc2 → 2.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +13 -7
  3. data/.yardopts +1 -0
  4. data/Gemfile +5 -1
  5. data/README.md +26 -0
  6. data/apis/AutoScaling-2011-01-01.json +57 -0
  7. data/apis/CloudFormation-2010-05-15.json +29 -0
  8. data/apis/CloudFront-2012-05-05.json +33 -0
  9. data/apis/CloudFront-2013-05-12.json +33 -0
  10. data/apis/CloudFront-2013-08-26.json +33 -0
  11. data/apis/CloudSearch-2011-02-01.json +1 -0
  12. data/apis/CloudWatch-2010-08-01.json +22 -0
  13. data/apis/DataPipeline-2012-10-29.json +25 -0
  14. data/apis/DirectConnect-2012-10-25.json +1 -0
  15. data/apis/DynamoDB-2011-12-05.json +29 -0
  16. data/apis/DynamoDB-2012-08-10.json +29 -0
  17. data/apis/EC2-2013-06-15.json +29 -0
  18. data/apis/EC2-2013-10-01.json +29 -0
  19. data/apis/EMR-2009-03-31.json +958 -40
  20. data/apis/ElastiCache-2012-11-15.json +72 -0
  21. data/apis/ElastiCache-2013-06-15.json +72 -0
  22. data/apis/ElasticBeanstalk-2010-12-01.json +8 -0
  23. data/apis/ElasticLoadBalancing-2012-06-01.json +8 -0
  24. data/apis/ElasticTranscoder-2012-09-25.json +16 -3
  25. data/apis/Glacier-2012-06-01.json +35 -0
  26. data/apis/IAM-2010-05-08.json +129 -0
  27. data/apis/ImportExport-2010-06-01.json +9 -0
  28. data/apis/Kinesis-2013-12-02.json +409 -0
  29. data/apis/OpsWorks-2013-02-18.json +1 -0
  30. data/apis/RDS-2013-01-10.json +106 -0
  31. data/apis/RDS-2013-02-12.json +120 -0
  32. data/apis/RDS-2013-05-15.json +120 -0
  33. data/apis/Redshift-2012-12-01.json +90 -1
  34. data/apis/Route53-2012-12-12.json +27 -0
  35. data/apis/S3-2006-03-01.json +34 -0
  36. data/apis/SDB-2009-04-15.json +16 -0
  37. data/apis/SES-2010-12-01.json +8 -0
  38. data/apis/SNS-2010-03-31.json +22 -0
  39. data/apis/SQS-2012-11-05.json +1 -0
  40. data/apis/STS-2011-06-15.json +3 -1
  41. data/apis/SWF-2012-01-25.json +52 -1
  42. data/apis/StorageGateway-2012-06-30.json +15 -0
  43. data/apis/StorageGateway-2013-06-30.json +15 -0
  44. data/apis/Support-2013-04-15.json +15 -0
  45. data/apis/configuration/endpoints.json +88 -23
  46. data/apis/source/elasticmapreduce-2009-03-31.json +1529 -126
  47. data/apis/source/elasticmapreduce-2009-03-31.paginators.json +25 -0
  48. data/apis/source/importexport-2010-06-01.paginators.json +1 -0
  49. data/apis/source/kinesis-2013-12-02.json +894 -0
  50. data/apis/source/kinesis-2013-12-02.paginators.json +18 -0
  51. data/apis/source/rds-2013-01-10.paginators.json +1 -0
  52. data/apis/source/rds-2013-02-12.paginators.json +1 -0
  53. data/apis/source/rds-2013-05-15.paginators.json +1 -0
  54. data/apis/source/redshift-2012-12-01.paginators.json +1 -0
  55. data/apis/source/s3-2006-03-01.paginators.json +1 -1
  56. data/aws-sdk-core.gemspec +1 -0
  57. data/doc-src/plugins/stability.rb +1 -0
  58. data/features/glacier/client.feature +5 -0
  59. data/features/glacier/step_definitions.rb +56 -5
  60. data/features/kinesis/client.feature +18 -0
  61. data/features/kinesis/setup.rb +6 -0
  62. data/features/s3/buckets.feature +10 -0
  63. data/features/s3/objects.feature +9 -0
  64. data/features/s3/step_definitions.rb +29 -0
  65. data/lib/aws.rb +13 -2
  66. data/lib/aws/api/pagination_translator.rb +71 -0
  67. data/lib/aws/api/service_translators/glacier.rb +0 -7
  68. data/lib/aws/api/translator.rb +10 -3
  69. data/lib/aws/error_handler.rb +1 -1
  70. data/lib/aws/json/builder.rb +4 -2
  71. data/lib/aws/pageable_response.rb +230 -0
  72. data/lib/aws/plugins/glacier_checksums.rb +10 -29
  73. data/lib/aws/plugins/response_paging.rb +18 -0
  74. data/lib/aws/plugins/retry_errors.rb +3 -1
  75. data/lib/aws/plugins/s3_complete_multipart_upload_fix.rb +1 -1
  76. data/lib/aws/plugins/s3_get_bucket_location_fix.rb +9 -3
  77. data/lib/aws/plugins/signature_v4.rb +2 -1
  78. data/lib/aws/plugins/sqs_queue_urls.rb +7 -4
  79. data/lib/aws/plugins/user_agent.rb +3 -3
  80. data/lib/aws/response_handler.rb +1 -1
  81. data/lib/aws/signers/s3.rb +1 -1
  82. data/lib/aws/tree_hash.rb +69 -0
  83. data/lib/aws/version.rb +1 -1
  84. data/spec/aws/json/builder_spec.rb +12 -0
  85. data/spec/aws/pageable_response_spec.rb +195 -0
  86. data/spec/aws/plugins/retry_errors_spec.rb +13 -0
  87. data/spec/aws/plugins/signature_v4_spec.rb +65 -0
  88. data/spec/aws/plugins/sqs_queue_urls_spec.rb +41 -0
  89. data/spec/aws_spec.rb +4 -0
  90. data/spec/fixtures/operations/glacier/get_job_output.yml +23 -0
  91. data/spec/fixtures/operations/s3/get_bucket_policy.yml +8 -0
  92. data/tasks/endpoints.rake +15 -0
  93. data/tasks/handlers.rake +1 -1
  94. data/vendor/seahorse/lib/seahorse/client.rb +1 -0
  95. data/vendor/seahorse/lib/seahorse/client/base.rb +6 -0
  96. data/vendor/seahorse/lib/seahorse/client/configuration.rb +1 -1
  97. data/vendor/seahorse/lib/seahorse/client/handler_builder.rb +3 -3
  98. data/vendor/seahorse/lib/seahorse/client/handler_list.rb +2 -2
  99. data/vendor/seahorse/lib/seahorse/client/http/error.rb +17 -0
  100. data/vendor/seahorse/lib/seahorse/client/http/plain_string_io.rb +10 -0
  101. data/vendor/seahorse/lib/seahorse/client/logging/handler.rb +1 -1
  102. data/vendor/seahorse/lib/seahorse/client/net_http/handler.rb +13 -2
  103. data/vendor/seahorse/lib/seahorse/client/plugins/json_simple.rb +1 -1
  104. data/vendor/seahorse/lib/seahorse/client/plugins/operation_methods.rb +4 -2
  105. data/vendor/seahorse/lib/seahorse/client/plugins/restful_bindings.rb +9 -1
  106. data/vendor/seahorse/lib/seahorse/client/request.rb +14 -0
  107. data/vendor/seahorse/lib/seahorse/client/response.rb +8 -38
  108. data/vendor/seahorse/lib/seahorse/model/shapes/shape.rb +11 -3
  109. data/vendor/seahorse/spec/seahorse/client/configuration_spec.rb +13 -0
  110. data/vendor/seahorse/spec/seahorse/client/net_http/handler_spec.rb +6 -0
  111. data/vendor/seahorse/spec/seahorse/client/response_spec.rb +9 -63
  112. metadata +41 -3
@@ -0,0 +1,23 @@
1
+ # This test ensures the GetJobOutput operation correctly manages the
2
+ # http status code response.
3
+ operation: get_job_output
4
+ params:
5
+ :vault_name: 'vault'
6
+ :job_id: 'id'
7
+ response:
8
+ status_code: 200
9
+ headers:
10
+ "x-amz-sha256-tree-hash": 'checksum'
11
+ "Content-Range": 'range'
12
+ "Accept-Ranges": 'accept-ranges'
13
+ "Content-Type": 'content-type'
14
+ "x-amz-archive-description": 'desc'
15
+ body: '{ "job": "output" }'
16
+ data:
17
+ :body: '{ "job": "output" }'
18
+ :checksum: 'checksum'
19
+ :content_range: 'range'
20
+ :accept_ranges: 'accept-ranges'
21
+ :content_type: 'content-type'
22
+ :status: 200
23
+ :archive_description: 'desc'
@@ -0,0 +1,8 @@
1
+ operation: get_bucket_policy
2
+ params:
3
+ :bucket: 'bucket-name'
4
+ response:
5
+ status_code: 200
6
+ body: '{ "policy": "json-document" }'
7
+ data:
8
+ :policy: '{ "policy": "json-document" }'
@@ -0,0 +1,15 @@
1
+ namespace :endpoints do
2
+
3
+ desc 'Downloads a fresh copy of the endpoints.json'
4
+ task :download do
5
+ require 'net/http'
6
+ require 'uri'
7
+ host = 'aws-sdk-configurations.amazonwebservices.com'
8
+ uri = URI.parse("http://#{host}/endpoints.json")
9
+ response = Net::HTTP.get_response(uri)
10
+ root = File.dirname(File.dirname(__FILE__))
11
+ target = File.join(root, 'apis', 'configuration', 'endpoints.json')
12
+ File.open(target, 'w') { |file| file.write(response.body) }
13
+ end
14
+
15
+ end
@@ -2,7 +2,7 @@ namespace :handlers do
2
2
  Aws.service_classes.each do |svc_name, svc_class|
3
3
 
4
4
  # create a task for each service, e.g. handlers:s3
5
- desc "Displays handlers for #{svc_class.name}"
5
+ desc "Displays handlers for #{svc_class.name}" if ENV['ALL']
6
6
  task(svc_name) do
7
7
  svc = svc_class.new
8
8
  if operation_name = ENV['OPERATION']
@@ -18,6 +18,7 @@ module Seahorse
18
18
 
19
19
  module Http
20
20
  autoload :Endpoint, 'seahorse/client/http/endpoint'
21
+ autoload :Error, 'seahorse/client/http/error'
21
22
  autoload :Headers, 'seahorse/client/http/headers'
22
23
  autoload :PlainStringIO, 'seahorse/client/http/plain_string_io'
23
24
  autoload :Request, 'seahorse/client/http/request'
@@ -1,3 +1,5 @@
1
+ require 'thread'
2
+
1
3
  module Seahorse
2
4
  module Client
3
5
  class Base
@@ -106,6 +108,9 @@ module Seahorse
106
108
  client
107
109
  end
108
110
 
111
+ # Used by plugins that modify the client class.
112
+ attr_reader :mutex
113
+
109
114
  # Registers a plugin with this client.
110
115
  #
111
116
  # @example Register a plugin
@@ -213,6 +218,7 @@ module Seahorse
213
218
 
214
219
  def inherited(subclass)
215
220
  subclass.instance_variable_set('@plugins', PluginList.new(@plugins))
221
+ subclass.instance_variable_set("@mutex", Mutex.new)
216
222
  end
217
223
 
218
224
  end
@@ -54,7 +54,7 @@ module Seahorse
54
54
  # @api private
55
55
  Defaults = Class.new(Array) do
56
56
  def each(&block)
57
- reverse.each(&block)
57
+ reverse.to_a.each(&block)
58
58
  end
59
59
  end
60
60
 
@@ -15,9 +15,9 @@ module Seahorse
15
15
 
16
16
  def handle_response(*args, &block)
17
17
  handler(*args) do |context|
18
- @handler.call(context).on_complete do |response|
19
- block.call(response)
20
- end
18
+ resp = @handler.call(context)
19
+ block.call(resp) if resp.http_response.status_code > 0
20
+ resp
21
21
  end
22
22
  end
23
23
 
@@ -168,8 +168,8 @@ module Seahorse
168
168
  # priority, the last one added will have the highest priority and
169
169
  # the first one added will have the lowest priority.
170
170
  #
171
- # @param [Class<Handler>] handler_class This should be a subclass
172
- # of {Handler} or any class that construct an object that
171
+ # @param [Class<Handler>] handler This should be a subclass
172
+ # of {Handler} or anany class that construct an object that
173
173
  # responds to `#call`.
174
174
  #
175
175
  # @option options [Symbol] :step (:build) The request life-cycle
@@ -0,0 +1,17 @@
1
+ module Seahorse
2
+ module Client
3
+ module Http
4
+ class Error < StandardError
5
+
6
+ def initialize(error)
7
+ super(error.message)
8
+ set_backtrace(error.backtrace)
9
+ @original_error = error
10
+ end
11
+
12
+ attr_reader :original_error
13
+
14
+ end
15
+ end
16
+ end
17
+ end
@@ -5,6 +5,16 @@ module Seahorse
5
5
  module Http
6
6
  class PlainStringIO < StringIO
7
7
  def inspect; string.inspect end
8
+
9
+ def eq?(other)
10
+ if other.is_a?(String) and self.string == other
11
+ true
12
+ else
13
+ super
14
+ end
15
+ end
16
+ alias == eq?
17
+
8
18
  end
9
19
  end
10
20
  end
@@ -7,7 +7,7 @@ module Seahorse
7
7
  # @return [Response]
8
8
  def call(context)
9
9
  context[:logging_started_at] = Time.now
10
- @handler.call(context).on_complete do |response|
10
+ @handler.call(context).tap do |response|
11
11
  context[:logging_completed_at] = Time.now
12
12
  log(context.config, response)
13
13
  end
@@ -6,6 +6,12 @@ module Seahorse
6
6
  # the Ruby's `Net::HTTP`.
7
7
  class Handler < Client::Handler
8
8
 
9
+ NETWORK_ERRORS = [
10
+ SocketError, EOFError, IOError, Timeout::Error,
11
+ Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EPIPE,
12
+ Errno::EINVAL, Errno::ETIMEDOUT, OpenSSL::SSL::SSLError
13
+ ]
14
+
9
15
  # Raised when a {Handler} can not construct a `Net::HTTP::Request`
10
16
  # from the given http verb.
11
17
  class InvalidHttpVerbError < StandardError; end
@@ -13,8 +19,13 @@ module Seahorse
13
19
  # @param [RequestContext] context
14
20
  # @return [Response]
15
21
  def call(context)
16
- transmit(context.config, context.http_request, context.http_response)
17
- Response.new(context: context)
22
+ response = Response.new(context: context)
23
+ begin
24
+ transmit(context.config, context.http_request, context.http_response)
25
+ rescue *NETWORK_ERRORS => error
26
+ response.error = Http::Error.new(error)
27
+ end
28
+ response
18
29
  end
19
30
 
20
31
  # @param [Configuration] config
@@ -19,7 +19,7 @@ module Seahorse
19
19
 
20
20
  def call(context)
21
21
  context.http_request.body = MultiJson.dump(context.params)
22
- @handler.call(context).on_success do |resp|
22
+ @handler.call(context).on(200..299) do |resp|
23
23
  resp.data = MultiJson.load(resp.http_response.body_contents)
24
24
  end
25
25
  end
@@ -7,7 +7,7 @@ module Seahorse
7
7
  #
8
8
  # # Helper Methods
9
9
  #
10
- # This plugin adds a helper method that lists the availalbe API
10
+ # This plugin adds a helper method that lists the available API
11
11
  # operations.
12
12
  #
13
13
  # client.operation_names
@@ -27,7 +27,9 @@ module Seahorse
27
27
 
28
28
  def after_initialize(client)
29
29
  unless client.respond_to?(:operation_names)
30
- add_operation_helpers(client, client.config.api.operations.keys)
30
+ client.class.mutex.synchronize do
31
+ add_operation_helpers(client, client.config.api.operations.keys)
32
+ end
31
33
  end
32
34
  end
33
35
 
@@ -10,7 +10,7 @@ module Seahorse
10
10
 
11
11
  def call(context)
12
12
  build_request(context)
13
- @handler.call(context).on_success do |response|
13
+ @handler.call(context).on(200..299) do |response|
14
14
  parse_response(response)
15
15
  end
16
16
  end
@@ -71,10 +71,18 @@ module Seahorse
71
71
  def parse_response(response)
72
72
  output = response.context.operation.output
73
73
  response.data ||= Aws::Structure.new(output.members.keys)
74
+ extract_status_code(response)
74
75
  extract_headers(response)
75
76
  extract_body(response)
76
77
  end
77
78
 
79
+ def extract_status_code(response)
80
+ if member = response.context.operation.output.status_code_member
81
+ status_code = response.http_response.status_code
82
+ response.data[member.member_name] = status_code
83
+ end
84
+ end
85
+
78
86
  def extract_headers(response)
79
87
  headers = response.http_response.headers
80
88
  rules = response.context.operation.output.header_members
@@ -33,10 +33,18 @@ module Seahorse
33
33
  # You can stream the raw HTTP response body to a File, or any IO-like
34
34
  # object, by passing the `:target` option.
35
35
  #
36
+ # # create a new file at the given path
37
+ # request.send_request(target: '/path/to/target/file')
38
+ #
39
+ # # or provide an IO object to write to
36
40
  # File.open('photo.jpg', 'wb') do |file|
37
41
  # request.send_request(target: file)
38
42
  # end
39
43
  #
44
+ # **Please Note**: The target IO object may receive `#truncate(0)`
45
+ # if the request generates a networking error and bytes have already
46
+ # been written to the target.
47
+ #
40
48
  # ## Block Streaming
41
49
  #
42
50
  # Pass a block to `#send_request` and the response will be yielded in
@@ -50,7 +58,13 @@ module Seahorse
50
58
  # **Please Note**: When streaming to a block, it is not possible to
51
59
  # retry failed requests.
52
60
  #
61
+ # @option options [String, IO] :target When specified, the HTTP response
62
+ # body is written to target. This is helpful when you are sending
63
+ # a request that may return a large payload that you don't want to
64
+ # load into memory.
65
+ #
53
66
  # @return [Response]
67
+ #
54
68
  def send_request(options = {}, &block)
55
69
  set_target(options, &block)
56
70
  resp = @handlers.to_stack.call(@context)
@@ -32,47 +32,17 @@ module Seahorse
32
32
  # @return [StandardError, nil]
33
33
  attr_accessor :error
34
34
 
35
- # @param [Range<Integer>] status_code_range (nil) When present, the
36
- # `block` will be triggered only for responses with a status code
37
- # in the given range.
38
- # @return [Response] Returns self.
39
- def on_status(status_code_range = nil, &block)
40
- if status_code_range.nil? || status_code_range.include?(status_code)
41
- yield(self)
42
- end
35
+ # @param [Integer,Range<Integer>] status_code_range The block will be
36
+ # triggered only for responses with a status code that matches
37
+ # the given status code or status code range.
38
+ # @return [self]
39
+ def on(status_code_range, &block)
40
+ range = status_code_range
41
+ range = range..range if range.is_a?(Integer)
42
+ yield(self) if range.include?(status_code)
43
43
  self
44
44
  end
45
45
 
46
- # Yields to the given block if the HTTP request received a response.
47
- def on_complete(&block)
48
- on_status(200..599, &block)
49
- end
50
-
51
- # Yields to the given block if the HTTP request received response with a
52
- # ~ 200 level status code.
53
- def on_success(&block)
54
- on_status(200..299, &block)
55
- end
56
-
57
- # Yields to the given block if the HTTP request received response with a
58
- # ~ 300 level status code.
59
- def on_redirect(&block)
60
- on_status(300..399, &block)
61
- end
62
-
63
- # Yields to the given block if the HTTP request received response with a
64
- # ~ 400 or 500 level status code.
65
- def on_error(&block)
66
- on_status(400..599, &block)
67
- end
68
-
69
- # Yields to the given block if the HTTP request failed to receive any
70
- # response. This generally indicates there was a network
71
- # level status code.
72
- def on_failure(&block)
73
- on_status(0..0, &block)
74
- end
75
-
76
46
  # @api private
77
47
  def respond_to?(*args)
78
48
  @data.respond_to?(args.first, false) || super
@@ -1,4 +1,3 @@
1
-
2
1
  module Seahorse
3
2
  module Model
4
3
  module Shapes
@@ -170,6 +169,10 @@ module Seahorse
170
169
  member_map['body']
171
170
  end
172
171
 
172
+ def status_code_member
173
+ member_map['http_status'].values.first
174
+ end
175
+
173
176
  # @return [StructureShape] Returns a structure with each of the
174
177
  # members that represent the request body.
175
178
  def payload_member
@@ -189,14 +192,19 @@ module Seahorse
189
192
  # @return [Boolean] Returns `true` if the request input body
190
193
  # should be sent as blob/raw data (e.g. from a file).
191
194
  def raw_payload?
192
- payload_member.is_a?(BlobShape)
195
+ !payload_member.is_a?(StructureShape)
193
196
  end
194
197
 
195
198
  private
196
199
 
197
200
  def member_map
198
201
  @member_map ||= begin
199
- { 'header' => {}, 'uri' => {}, 'body' => {} }.tap do |map|
202
+ {
203
+ 'http_status' => {},
204
+ 'header' => {},
205
+ 'uri' => {},
206
+ 'body' => {}
207
+ }.tap do |map|
200
208
  members.each do |member_name, member|
201
209
  map[member.location][member_name] = member
202
210
  end
@@ -103,6 +103,19 @@ module Seahorse
103
103
  expect(config.build!.proc).to be(value)
104
104
  end
105
105
 
106
+ it 'resolves defaults in LIFO order until a non-nil value is found' do
107
+ # default cost is 10
108
+ config.add_option(:cost) { 10 }
109
+
110
+ # increase cost for red items
111
+ config.add_option(:cost) { |cfg| cfg.color == 'red' ? 9001 : nil }
112
+
113
+ config.add_option(:color)
114
+
115
+ expect(config.build!(color: 'green').cost).to eq(10)
116
+ expect(config.build!(color: 'red').cost).to eq(9001) # over 9000!
117
+ end
118
+
106
119
  end
107
120
  end
108
121
  end
@@ -225,6 +225,12 @@ module Seahorse
225
225
  expect(resp_body.read).to eq('response-body')
226
226
  end
227
227
 
228
+ it 'wraps errors with a Http::Error' do
229
+ stub_request(:any, endpoint).to_raise(EOFError)
230
+ resp = make_request
231
+ expect(resp.error).to be_a(Seahorse::Client::Http::Error)
232
+ end
233
+
228
234
  end
229
235
  end
230
236
  end
@@ -87,80 +87,26 @@ module Seahorse
87
87
  Response.new(context: RequestContext.new(http_response: http_resp))
88
88
  }
89
89
 
90
- describe '#on_complete' do
90
+ describe '#on' do
91
91
 
92
- it 'triggers the callback when a response is received' do
92
+ it 'triggers the callback when status code matches' do
93
93
  http_resp.status_code = 200
94
- expect { |b| response.on_complete(&b) }.to yield_control
94
+ expect { |b| response.on(200,&b) }.to yield_control
95
95
  end
96
96
 
97
- it 'does not trigger when when a response is not received' do
98
- http_resp.status_code = 0
99
- expect { |b| response.on_complete(&b) }.not_to yield_control
100
- end
101
-
102
- end
103
-
104
- describe '#on_success' do
105
-
106
- it 'triggers the callback when response has a ~ 200 status code' do
107
- http_resp.status_code = 0
108
- expect { |b| response.on_success(&b) }.not_to yield_control
109
- http_resp.status_code = 200
110
- expect { |b| response.on_success(&b) }.to yield_control
111
- http_resp.status_code = 299
112
- expect { |b| response.on_success(&b) }.to yield_control
113
- http_resp.status_code = 300
114
- expect { |b| response.on_success(&b) }.not_to yield_control
115
- end
116
-
117
- end
118
-
119
- describe '#on_redirect' do
120
-
121
- it 'triggers the callback when response has a ~ 300 status code' do
122
- http_resp.status_code = 200
123
- expect { |b| response.on_redirect(&b) }.not_to yield_control
124
- http_resp.status_code = 304
125
- expect { |b| response.on_redirect(&b) }.to yield_control
97
+ it 'triggers the callback when status code included' do
126
98
  http_resp.status_code = 307
127
- expect { |b| response.on_redirect(&b) }.to yield_control
128
- http_resp.status_code = 400
129
- expect { |b| response.on_redirect(&b) }.not_to yield_control
99
+ expect { |b| response.on(300..599,&b) }.to yield_control
130
100
  end
131
101
 
132
- end
133
-
134
- describe '#on_error' do
135
-
136
- it 'triggers the callback when response has a ~ 400-500 code' do
137
- http_resp.status_code = 0
138
- expect { |b| response.on_error(&b) }.not_to yield_control
139
- http_resp.status_code = 200
140
- expect { |b| response.on_error(&b) }.not_to yield_control
102
+ it 'does not trigger when when a response is not included' do
141
103
  http_resp.status_code = 300
142
- expect { |b| response.on_error(&b) }.not_to yield_control
143
- http_resp.status_code = 400
144
- expect { |b| response.on_error(&b) }.to yield_control
145
- http_resp.status_code = 500
146
- expect { |b| response.on_error(&b) }.to yield_control
104
+ expect { |b| response.on(200..299,&b) }.not_to yield_control
147
105
  end
148
106
 
149
- end
150
-
151
- describe '#on_failure' do
152
-
153
- it 'triggers the callback when a response is not received' do
154
- http_resp.status_code = 0
155
- expect { |b| response.on_failure(&b) }.to yield_control
156
- http_resp.status_code = 200
157
- expect { |b| response.on_failure(&b) }.not_to yield_control
107
+ it 'returns self' do
158
108
  http_resp.status_code = 300
159
- expect { |b| response.on_failure(&b) }.not_to yield_control
160
- http_resp.status_code = 400
161
- expect { |b| response.on_failure(&b) }.not_to yield_control
162
- http_resp.status_code = 500
163
- expect { |b| response.on_failure(&b) }.not_to yield_control
109
+ expect(response.on(300) { |r| }).to be(response)
164
110
  end
165
111
 
166
112
  end