http_stub 0.22.4 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/lib/http_stub.rb +15 -5
  3. data/lib/http_stub/configurer/dsl/request_attribute_referencer.rb +19 -0
  4. data/lib/http_stub/configurer/dsl/request_referencer.rb +24 -0
  5. data/lib/http_stub/configurer/dsl/scenario_activator.rb +2 -2
  6. data/lib/http_stub/configurer/dsl/scenario_builder.rb +2 -2
  7. data/lib/http_stub/configurer/dsl/server.rb +4 -4
  8. data/lib/http_stub/configurer/dsl/stub_builder.rb +5 -3
  9. data/lib/http_stub/configurer/request/controllable_value.rb +1 -3
  10. data/lib/http_stub/configurer/request/http/factory.rb +2 -2
  11. data/lib/http_stub/configurer/request/omittable.rb +2 -4
  12. data/lib/http_stub/configurer/request/regexpable.rb +3 -8
  13. data/lib/http_stub/configurer/server/command_processor.rb +5 -7
  14. data/lib/http_stub/configurer/server/facade.rb +2 -4
  15. data/lib/http_stub/extensions/core/hash.rb +4 -11
  16. data/lib/http_stub/extensions/core/hash/formatted.rb +23 -0
  17. data/lib/http_stub/extensions/core/hash/indifferent_and_insensitive_access.rb +24 -0
  18. data/lib/http_stub/extensions/core/hash/with_indifferent_and_insensitive_access.rb +18 -0
  19. data/lib/http_stub/extensions/rack/handler.rb +1 -1
  20. data/lib/http_stub/rake/task_generators.rb +1 -1
  21. data/lib/http_stub/server/application.rb +10 -11
  22. data/lib/http_stub/server/application_helpers.rb +3 -5
  23. data/lib/http_stub/server/daemon.rb +5 -6
  24. data/lib/http_stub/server/request.rb +3 -10
  25. data/lib/http_stub/server/request/headers.rb +25 -0
  26. data/lib/http_stub/server/request/parameters.rb +21 -0
  27. data/lib/http_stub/server/request/request.rb +21 -0
  28. data/lib/http_stub/server/scenario/links.rb +1 -1
  29. data/lib/http_stub/server/stub/controller.rb +1 -1
  30. data/lib/http_stub/server/stub/empty.rb +4 -0
  31. data/lib/http_stub/server/stub/match/hash_matcher.rb +19 -0
  32. data/lib/http_stub/server/stub/match/omitted_value_matcher.rb +1 -3
  33. data/lib/http_stub/server/stub/match/rule/body.rb +2 -4
  34. data/lib/http_stub/server/stub/match/rule/headers.rb +5 -11
  35. data/lib/http_stub/server/stub/match/rule/json_body.rb +3 -5
  36. data/lib/http_stub/server/stub/match/rule/method.rb +1 -1
  37. data/lib/http_stub/server/stub/match/rule/parameters.rb +4 -7
  38. data/lib/http_stub/server/stub/match/rule/simple_body.rb +3 -3
  39. data/lib/http_stub/server/stub/match/rule/truthy.rb +27 -0
  40. data/lib/http_stub/server/stub/match/rule/uri.rb +3 -3
  41. data/lib/http_stub/server/stub/match/string_value_matcher.rb +4 -13
  42. data/lib/http_stub/server/stub/response.rb +5 -2
  43. data/lib/http_stub/server/stub/response/attribute/body.rb +32 -0
  44. data/lib/http_stub/server/stub/response/attribute/headers.rb +26 -0
  45. data/lib/http_stub/server/stub/response/attribute/interpolator.rb +26 -0
  46. data/lib/http_stub/server/stub/response/attribute/interpolator/headers.rb +27 -0
  47. data/lib/http_stub/server/stub/response/attribute/interpolator/parameters.rb +27 -0
  48. data/lib/http_stub/server/stub/response/base.rb +5 -16
  49. data/lib/http_stub/server/stub/response/file.rb +6 -2
  50. data/lib/http_stub/server/stub/response/text.rb +12 -0
  51. data/lib/http_stub/server/stub/stub.rb +4 -0
  52. data/lib/http_stub/version.rb +1 -1
  53. data/spec/acceptance/request_reference_spec.rb +44 -0
  54. data/spec/lib/http_stub/configurer/dsl/request_attribute_referencer_spec.rb +37 -0
  55. data/spec/lib/http_stub/configurer/dsl/request_referencer_spec.rb +37 -0
  56. data/spec/lib/http_stub/configurer/dsl/scenario_activator_spec.rb +14 -14
  57. data/spec/lib/http_stub/configurer/dsl/server_spec.rb +2 -6
  58. data/spec/lib/http_stub/configurer/dsl/stub_builder_spec.rb +34 -8
  59. data/spec/lib/http_stub/{server/formatted_hash_spec.rb → extensions/core/hash/formatted_spec.rb} +4 -6
  60. data/spec/lib/http_stub/{hash_with_indifferent_and_insensitive_access_spec.rb → extensions/core/hash/indifferent_and_insensitive_access_spec.rb} +8 -4
  61. data/spec/lib/http_stub/extensions/core/hash/with_indifferent_and_insensitive_access_spec.rb +41 -0
  62. data/spec/lib/http_stub/extensions/core/hash_spec.rb +11 -129
  63. data/spec/lib/http_stub/server/application_spec.rb +1 -1
  64. data/spec/lib/http_stub/server/payload_file_consolidator_spec.rb +1 -1
  65. data/spec/lib/http_stub/server/request/headers_spec.rb +89 -0
  66. data/spec/lib/http_stub/server/request/parameters_spec.rb +60 -0
  67. data/spec/lib/http_stub/server/request/request_spec.rb +84 -0
  68. data/spec/lib/http_stub/server/request_spec.rb +9 -98
  69. data/spec/lib/http_stub/server/response_spec.rb +2 -6
  70. data/spec/lib/http_stub/server/scenario/controller_spec.rb +1 -1
  71. data/spec/lib/http_stub/server/scenario/parser_spec.rb +3 -1
  72. data/spec/lib/http_stub/server/stub/controller_spec.rb +11 -4
  73. data/spec/lib/http_stub/server/stub/empty_spec.rb +10 -0
  74. data/spec/lib/http_stub/server/stub/match/hash_matcher_spec.rb +122 -0
  75. data/spec/lib/http_stub/server/stub/match/rule/body_spec.rb +4 -4
  76. data/spec/lib/http_stub/server/stub/match/rule/headers_spec.rb +54 -45
  77. data/spec/lib/http_stub/server/stub/match/rule/json_body_spec.rb +5 -5
  78. data/spec/lib/http_stub/server/stub/match/rule/method_spec.rb +19 -17
  79. data/spec/lib/http_stub/server/stub/match/rule/parameters_spec.rb +26 -33
  80. data/spec/lib/http_stub/server/stub/match/rule/simple_body_spec.rb +16 -25
  81. data/spec/lib/http_stub/server/stub/match/{truthy_matcher_spec.rb → rule/truthy_spec.rb} +3 -5
  82. data/spec/lib/http_stub/server/stub/match/rule/uri_spec.rb +16 -25
  83. data/spec/lib/http_stub/server/stub/match/string_value_matcher_spec.rb +2 -12
  84. data/spec/lib/http_stub/server/stub/parser_spec.rb +5 -3
  85. data/spec/lib/http_stub/server/stub/response/attribute/body_spec.rb +98 -0
  86. data/spec/lib/http_stub/server/stub/response/attribute/headers_spec.rb +57 -0
  87. data/spec/lib/http_stub/server/stub/response/attribute/interpolator/headers_spec.rb +53 -0
  88. data/spec/lib/http_stub/server/stub/response/attribute/interpolator/parameters_spec.rb +53 -0
  89. data/spec/lib/http_stub/server/stub/response/attribute/interpolator_spec.rb +41 -0
  90. data/spec/lib/http_stub/server/stub/response/base_spec.rb +6 -53
  91. data/spec/lib/http_stub/server/stub/response/file_spec.rb +48 -7
  92. data/spec/lib/http_stub/server/stub/response/text_spec.rb +66 -1
  93. data/spec/lib/http_stub/server/stub/stub_spec.rb +25 -4
  94. data/spec/spec_helper.rb +1 -0
  95. data/spec/support/http_stub/server/request_fixture.rb +1 -1
  96. metadata +86 -26
  97. data/lib/http_stub/hash_with_indifferent_and_insensitive_access.rb +0 -18
  98. data/lib/http_stub/server/formatted_hash.rb +0 -18
  99. data/lib/http_stub/server/header_parser.rb +0 -17
  100. data/lib/http_stub/server/stub/match/hash_with_string_value_matchers.rb +0 -26
  101. data/lib/http_stub/server/stub/match/truthy_matcher.rb +0 -25
  102. data/spec/lib/http_stub/server/header_parser_spec.rb +0 -51
  103. data/spec/lib/http_stub/server/stub/match/hash_with_string_value_matchers_spec.rb +0 -166
@@ -0,0 +1,26 @@
1
+ module HttpStub
2
+ module Server
3
+ module Stub
4
+ module Response
5
+ module Attribute
6
+
7
+ class Headers < ::Hash
8
+ include HttpStub::Extensions::Core::Hash::Formatted
9
+
10
+ def initialize(stub_headers)
11
+ super(stub_headers, ":")
12
+ end
13
+
14
+ def with_values_from(request)
15
+ self.each_with_object({}) do |(name, value), result|
16
+ result[name] = HttpStub::Server::Stub::Response::Attribute::Interpolator.interpolate(value, request)
17
+ end
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,26 @@
1
+ module HttpStub
2
+ module Server
3
+ module Stub
4
+ module Response
5
+ module Attribute
6
+
7
+ module Interpolator
8
+
9
+ CHAIN = [
10
+ HttpStub::Server::Stub::Response::Attribute::Interpolator::Headers,
11
+ HttpStub::Server::Stub::Response::Attribute::Interpolator::Parameters
12
+ ].freeze
13
+
14
+ private_constant :CHAIN
15
+
16
+ def self.interpolate(value, request)
17
+ CHAIN.reduce(value) { |result, interpolator| interpolator.interpolate(result, request) }
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,27 @@
1
+ module HttpStub
2
+ module Server
3
+ module Stub
4
+ module Response
5
+ module Attribute
6
+ module Interpolator
7
+
8
+ class Headers
9
+
10
+ CONTROL_VALUE_REGEXP = /control:request\.headers\[([^\]]+)\]/
11
+
12
+ private_constant :CONTROL_VALUE_REGEXP
13
+
14
+ def self.interpolate(stub_headers, request)
15
+ stub_headers.scan(CONTROL_VALUE_REGEXP).flatten.reduce(stub_headers) do |result, header_name|
16
+ result.gsub("control:request.headers[#{header_name}]", request.headers[header_name] || "")
17
+ end
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ module HttpStub
2
+ module Server
3
+ module Stub
4
+ module Response
5
+ module Attribute
6
+ module Interpolator
7
+
8
+ class Parameters
9
+
10
+ CONTROL_VALUE_REGEXP = /control:request\.parameters\[([^\]]+)\]/
11
+
12
+ private_constant :CONTROL_VALUE_REGEXP
13
+
14
+ def self.interpolate(stub_parameters, request)
15
+ stub_parameters.scan(CONTROL_VALUE_REGEXP).flatten.reduce(stub_parameters) do |result, parameter_name|
16
+ result.gsub("control:request.parameters[#{parameter_name}]", request.parameters[parameter_name] || "")
17
+ end
18
+ end
19
+
20
+ end
21
+
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -5,11 +5,9 @@ module HttpStub
5
5
 
6
6
  class Base
7
7
 
8
- private
9
-
10
8
  DEFAULT_ARGS = { "status" => 200, "delay_in_seconds" => 0 }.freeze
11
9
 
12
- public
10
+ private_constant :DEFAULT_ARGS
13
11
 
14
12
  class << self
15
13
 
@@ -20,7 +18,7 @@ module HttpStub
20
18
  def merge_defaults(args)
21
19
  args.clone.tap do |result|
22
20
  headers = result["headers"] ||= {}
23
- DEFAULT_ARGS.each { |key, value| result[key] = value if !result[key] || result[key] == "" }
21
+ DEFAULT_ARGS.each { |key, value| result[key] = value if !result[key] || result[key] == "" }
24
22
  default_headers.each { |key, value| headers[key] = value if !headers[key] || headers[key] == "" }
25
23
  end
26
24
  end
@@ -33,29 +31,20 @@ module HttpStub
33
31
 
34
32
  end
35
33
 
36
- attr_reader :status, :headers, :body, :delay_in_seconds
34
+ attr_reader :status, :headers, :delay_in_seconds
37
35
 
38
36
  def initialize(args={})
39
- @original_args = args
37
+ @original_args = args
40
38
  resolved_args = self.class.merge_defaults(args)
41
39
  @status = resolved_args["status"]
42
- @headers = HttpStub::Server::FormattedHash.new(resolved_args["headers"], ":")
43
- @body = resolved_args["body"]
40
+ @headers = HttpStub::Server::Stub::Response::Attribute::Headers.new(resolved_args["headers"])
44
41
  @delay_in_seconds = resolved_args["delay_in_seconds"]
45
42
  end
46
43
 
47
- def empty?
48
- @original_args.empty?
49
- end
50
-
51
44
  def type
52
45
  self.class.name.demodulize.underscore
53
46
  end
54
47
 
55
- def to_s
56
- @original_args.to_s
57
- end
58
-
59
48
  end
60
49
 
61
50
  end
@@ -11,8 +11,12 @@ module HttpStub
11
11
 
12
12
  def initialize(args)
13
13
  @file = args["body"][:tempfile]
14
- @uri = "file://#{@file.path}"
15
- super(args.merge("body" => ""))
14
+ @uri = "file://#{@file.path}"
15
+ super
16
+ end
17
+
18
+ def with_values_from(request)
19
+ self.class.new(@original_args.merge("headers" => @headers.with_values_from(request)))
16
20
  end
17
21
 
18
22
  def serve_on(server)
@@ -7,6 +7,18 @@ module HttpStub
7
7
 
8
8
  add_default_headers "content-type" => "application/json"
9
9
 
10
+ attr_reader :body
11
+
12
+ def initialize(args={})
13
+ super
14
+ @body = HttpStub::Server::Stub::Response::Attribute::Body.new(args["body"])
15
+ end
16
+
17
+ def with_values_from(request)
18
+ self.class.new(@original_args.merge("headers" => @headers.with_values_from(request),
19
+ "body" => @body.with_values_from(request)))
20
+ end
21
+
10
22
  def serve_on(server)
11
23
  server.halt(@status, @headers.to_hash, @body)
12
24
  end
@@ -23,6 +23,10 @@ module HttpStub
23
23
  criteria.is_a?(String) ? matches_by_id?(criteria) : matches_by_rules?(criteria, logger)
24
24
  end
25
25
 
26
+ def response_for(request)
27
+ @response.with_values_from(request)
28
+ end
29
+
26
30
  def to_s
27
31
  @description
28
32
  end
@@ -1,3 +1,3 @@
1
1
  module HttpStub
2
- VERSION = "0.22.4".freeze
2
+ VERSION = "0.23.0".freeze
3
3
  end
@@ -0,0 +1,44 @@
1
+ describe "Request references in response acceptance" do
2
+ include_context "configurer integration"
3
+
4
+ let(:configurer) { HttpStub::Examples::ConfigurerWithRequestReferences.new }
5
+
6
+ before(:example) { configurer.class.initialize! }
7
+
8
+ context "when a request is made matching a stub that references request attributes" do
9
+
10
+ let(:header_value) { "some header value" }
11
+ let(:parameter_value) { "some parameter value" }
12
+
13
+ let(:response) do
14
+ HTTParty.get("#{server_uri}/some_path", headers: { "header_name" => header_value },
15
+ query: { "parameter_name" => parameter_value })
16
+ end
17
+
18
+ context "the response headers" do
19
+
20
+ it "include request headers" do
21
+ expect(response.headers["header_referencing_header"]).to eql(header_value)
22
+ end
23
+
24
+ it "include request parameters" do
25
+ expect(response.headers["header_referencing_parameter"]).to eql(parameter_value)
26
+ end
27
+
28
+ end
29
+
30
+ context "the response body" do
31
+
32
+ it "include request headers" do
33
+ expect(response.body).to include(header_value)
34
+ end
35
+
36
+ it "include request parameters" do
37
+ expect(response.body).to include(parameter_value)
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+
44
+ end
@@ -0,0 +1,37 @@
1
+ describe HttpStub::Configurer::DSL::RequestAttributeReferencer do
2
+
3
+ let(:attribute_type) { :some_attribute_type }
4
+
5
+ let(:request_attribute_referencer) { described_class.new(attribute_type) }
6
+
7
+ describe "#[]" do
8
+
9
+ let(:name) { "some_name" }
10
+
11
+ subject { request_attribute_referencer[name] }
12
+
13
+ it "returns a control value" do
14
+ expect(subject).to start_with("control:")
15
+ end
16
+
17
+ it "returns a string referring to the referencer request attribute type" do
18
+ expect(subject).to include("request.some_attribute_type")
19
+ end
20
+
21
+ it "returns a string that will resolve the value for the provided name" do
22
+ expect(subject).to end_with("[#{name}]")
23
+ end
24
+
25
+ context "when the name provided is a symbol" do
26
+
27
+ let(:name) { :some_name }
28
+
29
+ it "returns a string that resolves the value with the provided name" do
30
+ expect(subject).to end_with("[#{name}]")
31
+ end
32
+
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,37 @@
1
+ describe HttpStub::Configurer::DSL::RequestReferencer do
2
+
3
+ let(:request_referencer) { described_class.new }
4
+
5
+ before(:example) { allow(HttpStub::Configurer::DSL::RequestAttributeReferencer).to receive(:new) }
6
+
7
+ describe "#parameters" do
8
+
9
+ subject { request_referencer.parameters }
10
+
11
+ it "returns an attribute request referencer for parameters" do
12
+ parameter_referencer = instance_double(HttpStub::Configurer::DSL::RequestAttributeReferencer)
13
+ allow(HttpStub::Configurer::DSL::RequestAttributeReferencer).to(
14
+ receive(:new).with(:parameters).and_return(parameter_referencer)
15
+ )
16
+
17
+ expect(subject).to eql(parameter_referencer)
18
+ end
19
+
20
+ end
21
+
22
+ describe "#headers" do
23
+
24
+ subject { request_referencer.headers }
25
+
26
+ it "returns an attribute request referencer for headers" do
27
+ header_referencer = instance_double(HttpStub::Configurer::DSL::RequestAttributeReferencer)
28
+ allow(HttpStub::Configurer::DSL::RequestAttributeReferencer).to(
29
+ receive(:new).with(:headers).and_return(header_referencer)
30
+ )
31
+
32
+ expect(subject).to eql(header_referencer)
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -3,7 +3,7 @@ describe HttpStub::Configurer::DSL::ScenarioActivator do
3
3
  class HttpStub::Configurer::DSL::TestableScenarioActivator
4
4
  include HttpStub::Configurer::DSL::ScenarioActivator
5
5
 
6
- def activate_all!(uris)
6
+ def activate_all!(_names)
7
7
  # Intentionally blank
8
8
  end
9
9
 
@@ -13,30 +13,30 @@ describe HttpStub::Configurer::DSL::ScenarioActivator do
13
13
 
14
14
  describe "#activate!" do
15
15
 
16
- subject { activator.activate!(uri) }
16
+ subject { activator.activate!(name) }
17
17
 
18
- context "when a uri is provided" do
18
+ context "when a name is provided" do
19
19
 
20
- let(:uri) { "some/uri" }
20
+ let(:name) { "some name" }
21
21
 
22
- it "delegates to activate all with the provided uri" do
23
- expect(activator).to receive(:activate_all!).with([ uri ])
22
+ it "delegates to activate all with the provided name" do
23
+ expect(activator).to receive(:activate_all!).with([ name ])
24
24
 
25
25
  subject
26
26
  end
27
27
 
28
28
  end
29
29
 
30
- context "when multiple uri's are provided" do
30
+ context "when multiple names are provided" do
31
31
 
32
- let(:uris) { (1..3).map { |i| "uri/#{i}" } }
32
+ let(:names) { (1..3).map { |i| "name #{i}" } }
33
33
 
34
34
  context "as multiple arguments" do
35
35
 
36
- subject { activator.activate!(*uris) }
36
+ subject { activator.activate!(*names) }
37
37
 
38
- it "delegates to activate all the provided uris" do
39
- expect(activator).to receive(:activate_all!).with(uris)
38
+ it "delegates to activate all the provided names" do
39
+ expect(activator).to receive(:activate_all!).with(names)
40
40
 
41
41
  subject
42
42
  end
@@ -45,10 +45,10 @@ describe HttpStub::Configurer::DSL::ScenarioActivator do
45
45
 
46
46
  context "as an array" do
47
47
 
48
- subject { activator.activate!(uris) }
48
+ subject { activator.activate!(names) }
49
49
 
50
- it "delegates to activate all the provided uris" do
51
- expect(activator).to receive(:activate_all!).with(uris)
50
+ it "delegates to activate all the provided names" do
51
+ expect(activator).to receive(:activate_all!).with(names)
52
52
 
53
53
  subject
54
54
  end
@@ -204,9 +204,7 @@ describe HttpStub::Configurer::DSL::Server do
204
204
  end
205
205
 
206
206
  it "yields the created builder to the provided block" do
207
- expect(block).to receive(:call).with(scenario_builder)
208
-
209
- subject
207
+ expect { |block| server.add_scenario!(scenario_name, &block) }.to yield_with_args(scenario_builder)
210
208
  end
211
209
 
212
210
  it "builds the scenario request" do
@@ -335,9 +333,7 @@ describe HttpStub::Configurer::DSL::Server do
335
333
  end
336
334
 
337
335
  it "yields the created builder to the provided block" do
338
- expect(block).to receive(:call).with(stub_activator_builder)
339
-
340
- subject
336
+ expect { |block| server.add_activator!(&block) }.to yield_with_args(stub_activator_builder)
341
337
  end
342
338
 
343
339
  it "builds a scenario request" do
@@ -6,10 +6,8 @@ describe HttpStub::Configurer::DSL::StubBuilder do
6
6
 
7
7
  shared_context "triggers one stub" do
8
8
 
9
- let(:trigger_stub) { instance_double(HttpStub::Configurer::Request::Stub) }
10
- let(:trigger_builder) do
11
- instance_double(HttpStub::Configurer::DSL::StubBuilder, build: trigger_stub)
12
- end
9
+ let(:trigger_stub) { instance_double(HttpStub::Configurer::Request::Stub) }
10
+ let(:trigger_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder, build: trigger_stub) }
13
11
 
14
12
  before(:example) { builder.trigger(trigger_builder) }
15
13
 
@@ -17,7 +15,7 @@ describe HttpStub::Configurer::DSL::StubBuilder do
17
15
 
18
16
  shared_context "triggers many stubs" do
19
17
 
20
- let(:trigger_stubs) { (1..3).map { instance_double(HttpStub::Configurer::Request::Stub) } }
18
+ let(:trigger_stubs) { (1..3).map { instance_double(HttpStub::Configurer::Request::Stub) } }
21
19
  let(:trigger_builders) do
22
20
  trigger_stubs.map { |stub| instance_double(HttpStub::Configurer::DSL::StubBuilder, build: stub) }
23
21
  end
@@ -103,10 +101,38 @@ describe HttpStub::Configurer::DSL::StubBuilder do
103
101
 
104
102
  describe "#respond_with" do
105
103
 
106
- subject { builder.respond_with(status: 201) }
104
+ context "when a block is provided referencing the matching request" do
105
+
106
+ let(:request_referencer) { instance_double(HttpStub::Configurer::DSL::RequestReferencer) }
107
+
108
+ subject { builder.respond_with { |request| { headers: request.headers[:some_header] } } }
109
+
110
+ it "includes the hash returned from the evaluated block in the response hash" do
111
+ subject
112
+
113
+ expect(builder.response).to include(headers: a_string_matching(/^control/))
114
+ end
115
+
116
+ it "returns the builder to support method chaining" do
117
+ expect(subject).to eql(builder)
118
+ end
119
+
120
+ end
121
+
122
+ context "when a block is not provided" do
123
+
124
+ subject { builder.respond_with(status: 201) }
125
+
126
+ it "includes the proivded hash in the response hash" do
127
+ subject
128
+
129
+ expect(builder.response).to include(status: 201)
130
+ end
131
+
132
+ it "returns the builder to support method chaining" do
133
+ expect(subject).to eql(builder)
134
+ end
107
135
 
108
- it "returns the builder to support method chaining" do
109
- expect(subject).to eql(builder)
110
136
  end
111
137
 
112
138
  end