http_stub 0.15.5 → 0.16.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +4 -4
  2. data/lib/http_stub.rb +37 -27
  3. data/lib/http_stub/configurer.rb +2 -2
  4. data/lib/http_stub/configurer/dsl/deprecated.rb +60 -0
  5. data/lib/http_stub/configurer/{server/dsl.rb → dsl/sanctioned.rb} +18 -18
  6. data/lib/http_stub/configurer/dsl/scenario_activator.rb +15 -0
  7. data/lib/http_stub/configurer/dsl/scenario_builder.rb +37 -0
  8. data/lib/http_stub/configurer/dsl/stub_activator_builder.rb +24 -0
  9. data/lib/http_stub/configurer/{request → dsl}/stub_builder.rb +4 -3
  10. data/lib/http_stub/configurer/dsl/stub_builder_producer.rb +21 -0
  11. data/lib/http_stub/configurer/request/http/factory.rb +8 -2
  12. data/lib/http_stub/configurer/request/scenario.rb +29 -0
  13. data/lib/http_stub/configurer/server/facade.rb +7 -7
  14. data/lib/http_stub/server/application.rb +21 -14
  15. data/lib/http_stub/server/registry.rb +7 -3
  16. data/lib/http_stub/server/response.rb +3 -3
  17. data/lib/http_stub/server/scenario.rb +12 -0
  18. data/lib/http_stub/server/scenario/activator.rb +25 -0
  19. data/lib/http_stub/server/scenario/controller.rb +36 -0
  20. data/lib/http_stub/server/scenario/instance.rb +36 -0
  21. data/lib/http_stub/server/scenario/request_parser.rb +19 -0
  22. data/lib/http_stub/server/stub.rb +3 -23
  23. data/lib/http_stub/server/stub/controller.rb +30 -0
  24. data/lib/http_stub/server/stub/exact_value_matcher.rb +15 -0
  25. data/lib/http_stub/server/stub/hash_with_string_value_matchers.rb +22 -0
  26. data/lib/http_stub/server/stub/headers.rb +19 -0
  27. data/lib/http_stub/server/stub/instance.rb +31 -0
  28. data/lib/http_stub/server/stub/method.rb +23 -0
  29. data/lib/http_stub/server/stub/omitted_value_matcher.rb +21 -0
  30. data/lib/http_stub/server/stub/payload_file_consolidator.rb +18 -0
  31. data/lib/http_stub/server/stub/regexp_value_matcher.rb +16 -0
  32. data/lib/http_stub/server/stub/registry.rb +31 -0
  33. data/lib/http_stub/server/stub/request_header_parser.rb +19 -0
  34. data/lib/http_stub/server/stub/request_headers.rb +28 -0
  35. data/lib/http_stub/server/stub/request_parameters.rb +23 -0
  36. data/lib/http_stub/server/stub/request_parser.rb +17 -0
  37. data/lib/http_stub/server/stub/response.rb +16 -0
  38. data/lib/http_stub/server/stub/response/base.rb +64 -0
  39. data/lib/http_stub/server/stub/response/file.rb +36 -0
  40. data/lib/http_stub/server/stub/response/text.rb +19 -0
  41. data/lib/http_stub/server/stub/string_value_matcher.rb +31 -0
  42. data/lib/http_stub/server/stub/triggers.rb +25 -0
  43. data/lib/http_stub/server/stub/uri.rb +23 -0
  44. data/lib/http_stub/server/views/_scenario.haml +16 -0
  45. data/lib/http_stub/server/views/application.sass +4 -0
  46. data/lib/http_stub/server/views/scenarios.haml +3 -0
  47. data/lib/http_stub/version.rb +1 -1
  48. data/spec/acceptance/activator_spec.rb +81 -0
  49. data/spec/acceptance/configurer_initialization_spec.rb +158 -0
  50. data/spec/acceptance/scenario_spec.rb +91 -0
  51. data/spec/acceptance/stub_control_values_spec.rb +160 -0
  52. data/spec/acceptance/stub_spec.rb +290 -0
  53. data/spec/acceptance/stub_trigger_spec.rb +144 -0
  54. data/spec/lib/http_stub/configurer/{deprecated_dsl_spec.rb → dsl/deprecated_spec.rb} +21 -13
  55. data/spec/lib/http_stub/configurer/{server/dsl_spec.rb → dsl/sanctioned_spec.rb} +74 -97
  56. data/spec/lib/http_stub/configurer/dsl/scenario_activator_spec.rb +62 -0
  57. data/spec/lib/http_stub/configurer/dsl/scenario_builder_spec.rb +146 -0
  58. data/spec/lib/http_stub/configurer/dsl/stub_activator_builder_spec.rb +120 -0
  59. data/spec/lib/http_stub/configurer/dsl/stub_builder_producer_spec.rb +105 -0
  60. data/spec/lib/http_stub/configurer/{request → dsl}/stub_builder_spec.rb +33 -5
  61. data/spec/lib/http_stub/configurer/request/controllable_value_spec.rb +1 -1
  62. data/spec/lib/http_stub/configurer/request/http/factory_spec.rb +46 -5
  63. data/spec/lib/http_stub/configurer/request/omittable_spec.rb +1 -1
  64. data/spec/lib/http_stub/configurer/request/scenario_spec.rb +69 -0
  65. data/spec/lib/http_stub/configurer/request/stub_spec.rb +2 -2
  66. data/spec/lib/http_stub/configurer/server/facade_spec.rb +17 -17
  67. data/spec/lib/http_stub/configurer_spec.rb +1 -1
  68. data/spec/lib/http_stub/server/application_integration_spec.rb +23 -13
  69. data/spec/lib/http_stub/server/application_spec.rb +40 -38
  70. data/spec/lib/http_stub/server/daemon_spec.rb +2 -2
  71. data/spec/lib/http_stub/server/registry_spec.rb +66 -17
  72. data/spec/lib/http_stub/server/{request_parser_spec.rb → request_file_consolidator_spec.rb} +20 -33
  73. data/spec/lib/http_stub/server/response_pipeline_spec.rb +1 -1
  74. data/spec/lib/http_stub/server/scenario/activator_spec.rb +106 -0
  75. data/spec/lib/http_stub/server/scenario/controller_spec.rb +102 -0
  76. data/spec/lib/http_stub/server/scenario/instance_spec.rb +126 -0
  77. data/spec/lib/http_stub/server/scenario/request_parser_spec.rb +59 -0
  78. data/spec/lib/http_stub/server/scenario_spec.rb +24 -0
  79. data/spec/lib/http_stub/server/{stub_controller_spec.rb → stub/controller_spec.rb} +13 -17
  80. data/spec/lib/http_stub/server/{exact_value_matcher_spec.rb → stub/exact_value_matcher_spec.rb} +3 -3
  81. data/spec/lib/http_stub/server/{hash_with_string_value_matchers_spec.rb → stub/hash_with_string_value_matchers_spec.rb} +7 -5
  82. data/spec/lib/http_stub/server/{headers_spec.rb → stub/headers_spec.rb} +2 -2
  83. data/spec/lib/http_stub/server/stub/instance_spec.rb +201 -0
  84. data/spec/lib/http_stub/server/stub/method_spec.rb +95 -0
  85. data/spec/lib/http_stub/server/{omitted_value_matcher_spec.rb → stub/omitted_value_matcher_spec.rb} +3 -3
  86. data/spec/lib/http_stub/server/{regexp_value_matcher_spec.rb → stub/regexp_value_matcher_spec.rb} +3 -3
  87. data/spec/lib/http_stub/server/stub/registry_integration_spec.rb +56 -0
  88. data/spec/lib/http_stub/server/{stub_registry_spec.rb → stub/registry_spec.rb} +27 -14
  89. data/spec/lib/http_stub/server/{request_header_parser_spec.rb → stub/request_header_parser_spec.rb} +6 -6
  90. data/spec/lib/http_stub/server/stub/request_headers_spec.rb +68 -0
  91. data/spec/lib/http_stub/server/{stub_parameters_spec.rb → stub/request_parameters_spec.rb} +19 -17
  92. data/spec/lib/http_stub/server/stub/request_parser_spec.rb +56 -0
  93. data/spec/lib/http_stub/server/{stub_response → stub/response}/base_spec.rb +5 -5
  94. data/spec/lib/http_stub/server/{stub_response → stub/response}/file_spec.rb +3 -3
  95. data/spec/lib/http_stub/server/{stub_response → stub/response}/text_spec.rb +3 -3
  96. data/spec/lib/http_stub/server/{stub_response_spec.rb → stub/response_spec.rb} +8 -8
  97. data/spec/lib/http_stub/server/{string_value_matcher_spec.rb → stub/string_value_matcher_spec.rb} +25 -13
  98. data/spec/lib/http_stub/server/{stub_triggers_spec.rb → stub/triggers_spec.rb} +7 -9
  99. data/spec/lib/http_stub/server/stub/uri_spec.rb +43 -0
  100. data/spec/lib/http_stub/server/stub_spec.rb +10 -185
  101. data/spec/spec_helper.rb +10 -5
  102. data/spec/support/configurer_integration.rb +24 -0
  103. data/spec/support/scenario_fixture.rb +33 -0
  104. data/spec/support/stub_fixture.rb +1 -1
  105. metadata +126 -84
  106. data/lib/http_stub/configurer/deprecated_dsl.rb +0 -57
  107. data/lib/http_stub/configurer/request/stub_activator.rb +0 -26
  108. data/lib/http_stub/configurer/request/stub_activator_builder.rb +0 -25
  109. data/lib/http_stub/server/exact_value_matcher.rb +0 -13
  110. data/lib/http_stub/server/hash_with_string_value_matchers.rb +0 -20
  111. data/lib/http_stub/server/headers.rb +0 -17
  112. data/lib/http_stub/server/omitted_value_matcher.rb +0 -19
  113. data/lib/http_stub/server/regexp_value_matcher.rb +0 -14
  114. data/lib/http_stub/server/request_header_parser.rb +0 -17
  115. data/lib/http_stub/server/request_parser.rb +0 -29
  116. data/lib/http_stub/server/string_value_matcher.rb +0 -29
  117. data/lib/http_stub/server/stub_activator.rb +0 -30
  118. data/lib/http_stub/server/stub_activator_controller.rb +0 -34
  119. data/lib/http_stub/server/stub_controller.rb +0 -28
  120. data/lib/http_stub/server/stub_headers.rb +0 -24
  121. data/lib/http_stub/server/stub_parameters.rb +0 -21
  122. data/lib/http_stub/server/stub_registry.rb +0 -29
  123. data/lib/http_stub/server/stub_response.rb +0 -14
  124. data/lib/http_stub/server/stub_response/base.rb +0 -62
  125. data/lib/http_stub/server/stub_response/file.rb +0 -34
  126. data/lib/http_stub/server/stub_response/text.rb +0 -17
  127. data/lib/http_stub/server/stub_triggers.rb +0 -23
  128. data/lib/http_stub/server/stub_uri.rb +0 -21
  129. data/lib/http_stub/server/views/stub_activators.haml +0 -6
  130. data/spec/lib/http_stub/configurer/request/stub_activator_builder_spec.rb +0 -119
  131. data/spec/lib/http_stub/configurer/request/stub_activator_spec.rb +0 -45
  132. data/spec/lib/http_stub/configurer_integration_spec.rb +0 -837
  133. data/spec/lib/http_stub/server/stub_activator_controller_spec.rb +0 -95
  134. data/spec/lib/http_stub/server/stub_activator_spec.rb +0 -83
  135. data/spec/lib/http_stub/server/stub_headers_spec.rb +0 -68
  136. data/spec/lib/http_stub/server/stub_registry_integration_spec.rb +0 -62
  137. data/spec/lib/http_stub/server/stub_uri_spec.rb +0 -42
@@ -0,0 +1,62 @@
1
+ describe HttpStub::Configurer::DSL::ScenarioActivator do
2
+
3
+ class HttpStub::Configurer::DSL::TestableScenarioActivator
4
+ include HttpStub::Configurer::DSL::ScenarioActivator
5
+
6
+ def activate_all!(uris)
7
+ # Intentionally blank
8
+ end
9
+
10
+ end
11
+
12
+ let(:activator) { HttpStub::Configurer::DSL::TestableScenarioActivator.new }
13
+
14
+ describe "#activate!" do
15
+
16
+ subject { activator.activate!(uri) }
17
+
18
+ context "when a uri is provided" do
19
+
20
+ let(:uri) { "some/uri" }
21
+
22
+ it "delegates to activate all with the provided uri" do
23
+ expect(activator).to receive(:activate_all!).with([ uri ])
24
+
25
+ subject
26
+ end
27
+
28
+ end
29
+
30
+ context "when multiple uri's are provided" do
31
+
32
+ let(:uris) { (1..3).map { |i| "uri/#{i}" } }
33
+
34
+ context "as multiple arguments" do
35
+
36
+ subject { activator.activate!(*uris) }
37
+
38
+ it "delegates to activate all the provided uris" do
39
+ expect(activator).to receive(:activate_all!).with(uris)
40
+
41
+ subject
42
+ end
43
+
44
+ end
45
+
46
+ context "as an array" do
47
+
48
+ subject { activator.activate!(uris) }
49
+
50
+ it "delegates to activate all the provided uris" do
51
+ expect(activator).to receive(:activate_all!).with(uris)
52
+
53
+ subject
54
+ end
55
+
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+
62
+ end
@@ -0,0 +1,146 @@
1
+ describe HttpStub::Configurer::DSL::ScenarioBuilder do
2
+
3
+ let(:stub_fixture) { HttpStub::StubFixture.new }
4
+
5
+ let(:response_defaults) { { some_default_key: "some default value" } }
6
+ let(:scenario_name) { "some/scenario/name" }
7
+
8
+ let(:scenario_builder) { HttpStub::Configurer::DSL::ScenarioBuilder.new(response_defaults, scenario_name) }
9
+
10
+ it "activates scenarios" do
11
+ expect(scenario_builder).to be_a(HttpStub::Configurer::DSL::ScenarioActivator)
12
+ end
13
+
14
+ it "produces stub builders" do
15
+ expect(scenario_builder).to be_a(HttpStub::Configurer::DSL::StubBuilderProducer)
16
+ end
17
+
18
+ describe "#add_stub!" do
19
+
20
+ let(:stub_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder) }
21
+
22
+ context "when a block is provided" do
23
+
24
+ let(:block) { lambda { |_builder| "some block" } }
25
+
26
+ subject { scenario_builder.add_stub!(&block) }
27
+
28
+ before(:example) { allow(HttpStub::Configurer::DSL::StubBuilder).to receive(:new).and_return(stub_builder) }
29
+
30
+ it "creates a stub builder with the response defaults provided to the scenario builder" do
31
+ expect(HttpStub::Configurer::DSL::StubBuilder).to receive(:new).and_return(stub_builder)
32
+
33
+ subject
34
+ end
35
+
36
+ it "yields the stub builder to the provided block" do
37
+ expect(block).to receive(:call).with(stub_builder)
38
+
39
+ subject
40
+ end
41
+
42
+ it "results in the stub being built when the scenario is built" do
43
+ subject
44
+ expect(stub_builder).to receive(:build)
45
+
46
+ scenario_builder.build
47
+ end
48
+
49
+ end
50
+
51
+ context "when a builder is provided" do
52
+
53
+ subject { scenario_builder.add_stub!(stub_builder) }
54
+
55
+ it "results in the stub being built when the scenario is built" do
56
+ subject
57
+ expect(stub_builder).to receive(:build)
58
+
59
+ scenario_builder.build
60
+ end
61
+
62
+ end
63
+
64
+ end
65
+
66
+ describe "#build" do
67
+
68
+ let(:scenario) { instance_double(HttpStub::Configurer::Request::Scenario) }
69
+
70
+ subject { scenario_builder.build }
71
+
72
+ before(:example) { allow(HttpStub::Configurer::Request::Scenario).to receive(:new).and_return(scenario) }
73
+
74
+ it "creates a scenario that includes the name" do
75
+ expect(HttpStub::Configurer::Request::Scenario).to receive(:new).with(hash_including(name: scenario_name))
76
+
77
+ subject
78
+ end
79
+
80
+ context "when multiple stubs have been added" do
81
+
82
+ let(:stubs) { (1..3).map { instance_double(HttpStub::Configurer::Request::Stub) } }
83
+ let(:stub_builders) do
84
+ stubs.map { |stub| instance_double(HttpStub::Configurer::DSL::StubBuilder, build: stub) }
85
+ end
86
+
87
+ before(:example) do
88
+ allow(HttpStub::Configurer::DSL::StubBuilder).to receive(:new).and_return(*stub_builders)
89
+ stub_builders.each { scenario_builder.add_stub! { |_builder| "some block" } }
90
+ end
91
+
92
+ it "builds the stubs" do
93
+ stub_builders.each { |stub_builder| expect(stub_builder).to receive(:build) }
94
+
95
+ subject
96
+ end
97
+
98
+ it "creates a scenario that includes the built stubs" do
99
+ expect(HttpStub::Configurer::Request::Scenario).to receive(:new).with(hash_including(stubs: stubs))
100
+
101
+ subject
102
+ end
103
+
104
+ end
105
+
106
+ context "when no stubs have been added" do
107
+
108
+ it "creates a scenario that has empty stubs" do
109
+ expect(HttpStub::Configurer::Request::Scenario).to receive(:new).with(hash_including(stubs: []))
110
+
111
+ subject
112
+ end
113
+
114
+ end
115
+
116
+ context "when triggered scenarios have been added" do
117
+
118
+ let(:triggered_scenario_names) { (1..3).map { |i| "activator_#{i}" } }
119
+
120
+ before(:example) { scenario_builder.activate!(triggered_scenario_names) }
121
+
122
+ it "creates a scenario that includes the triggered scenario names" do
123
+ expect(HttpStub::Configurer::Request::Scenario).to(
124
+ receive(:new).with(hash_including(triggered_scenario_names: triggered_scenario_names))
125
+ )
126
+
127
+ subject
128
+ end
129
+
130
+ end
131
+
132
+ context "when no scenario activators have been added" do
133
+
134
+ it "creates a scenario that has empty triggered scenario names" do
135
+ expect(HttpStub::Configurer::Request::Scenario).to(
136
+ receive(:new).with(hash_including(triggered_scenario_names: []))
137
+ )
138
+
139
+ subject
140
+ end
141
+
142
+ end
143
+
144
+ end
145
+
146
+ end
@@ -0,0 +1,120 @@
1
+ describe HttpStub::Configurer::DSL::StubActivatorBuilder do
2
+
3
+ let(:stub_fixture) { HttpStub::StubFixture.new }
4
+
5
+ let(:response_defaults) { {} }
6
+ let(:activation_uri) { "/some/activation/uri" }
7
+ let(:scenario) { instance_double(HttpStub::Configurer::Request::Scenario) }
8
+ let(:scenario_builder) do
9
+ instance_double(HttpStub::Configurer::DSL::ScenarioBuilder, build: scenario, add_stub!: nil)
10
+ end
11
+ let(:stub_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder) }
12
+
13
+ let(:builder) { HttpStub::Configurer::DSL::StubActivatorBuilder.new(response_defaults) }
14
+
15
+ before(:example) do
16
+ allow(HttpStub::Configurer::DSL::ScenarioBuilder).to receive(:new).and_return(scenario_builder)
17
+ allow(HttpStub::Configurer::DSL::StubBuilder).to receive(:new).and_return(stub_builder)
18
+ end
19
+
20
+ describe "#on" do
21
+
22
+ subject { builder.on(activation_uri) }
23
+
24
+ it "creates a scenario builder with the response defaults and activation uri" do
25
+ expect(HttpStub::Configurer::DSL::ScenarioBuilder).to receive(:new).with(response_defaults, activation_uri)
26
+
27
+ subject
28
+ end
29
+
30
+ it "creates a stub builder with the response defaults" do
31
+ expect(HttpStub::Configurer::DSL::StubBuilder).to receive(:new).with(response_defaults)
32
+
33
+ subject
34
+ end
35
+
36
+ it "adds the stub builder to the scenario builder" do
37
+ expect(scenario_builder).to receive(:add_stub!).with(stub_builder)
38
+
39
+ subject
40
+ end
41
+
42
+ end
43
+
44
+ describe "#match_requests" do
45
+
46
+ let(:request_payload) { stub_fixture.request.configurer_payload }
47
+
48
+ before(:example) { builder.on(activation_uri) }
49
+
50
+ it "delegates to a stub builder" do
51
+ expect(stub_builder).to receive(:match_requests).with(stub_fixture.request.uri, request_payload)
52
+
53
+ builder.match_requests(stub_fixture.request.uri, request_payload)
54
+ end
55
+
56
+ end
57
+
58
+ describe "#respond_with" do
59
+
60
+ let(:response_payload) { stub_fixture.response.configurer_payload }
61
+
62
+ before(:example) { builder.on(activation_uri) }
63
+
64
+ it "delegates to a stub builder" do
65
+ expect(stub_builder).to receive(:respond_with).with(response_payload)
66
+
67
+ builder.respond_with(response_payload)
68
+ end
69
+
70
+ end
71
+
72
+ describe "#trigger" do
73
+
74
+ before(:example) { builder.on(activation_uri) }
75
+
76
+ context "when one triggered stub is provided" do
77
+
78
+ let(:trigger_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder) }
79
+
80
+ it "delegates to a stub builder" do
81
+ expect(stub_builder).to receive(:trigger).with(trigger_builder)
82
+
83
+ builder.trigger(trigger_builder)
84
+ end
85
+
86
+ end
87
+
88
+ context "when many triggered stubs are provided" do
89
+
90
+ let(:trigger_builders) { (1..3).map { instance_double(HttpStub::Configurer::DSL::StubBuilder) } }
91
+
92
+ it "delegates to a stub builder" do
93
+ expect(stub_builder).to receive(:trigger).with(trigger_builders)
94
+
95
+ builder.trigger(trigger_builders)
96
+ end
97
+
98
+ end
99
+
100
+ end
101
+
102
+ describe "#build" do
103
+
104
+ subject { builder.build }
105
+
106
+ before(:example) { builder.on(activation_uri) }
107
+
108
+ it "builds a scenario" do
109
+ expect(scenario_builder).to receive(:build)
110
+
111
+ subject
112
+ end
113
+
114
+ it "returns the built scenario" do
115
+ expect(subject).to eql(scenario)
116
+ end
117
+
118
+ end
119
+
120
+ end
@@ -0,0 +1,105 @@
1
+ describe HttpStub::Configurer::DSL::StubBuilderProducer do
2
+
3
+ class HttpStub::Configurer::DSL::TestableStubBuilderProducer
4
+ include HttpStub::Configurer::DSL::StubBuilderProducer
5
+
6
+ def initialize(response_defaults)
7
+ @response_defaults = response_defaults
8
+ @builders = []
9
+ end
10
+
11
+ def add_stub!(builder)
12
+ @builders << builder
13
+ end
14
+
15
+ end
16
+
17
+ let(:response_defaults) { { default_key: "default value" } }
18
+
19
+ let(:producer) { HttpStub::Configurer::DSL::TestableStubBuilderProducer.new(response_defaults) }
20
+
21
+ describe "#build_stub" do
22
+
23
+ let(:stub_builder) { instance_double(HttpStub::Configurer::DSL::StubBuilder) }
24
+
25
+ before(:example) { allow(HttpStub::Configurer::DSL::StubBuilder).to receive(:new).and_return(stub_builder) }
26
+
27
+ subject { producer.build_stub }
28
+
29
+ it "creates a stub builder containing the producers response defaults" do
30
+ expect(HttpStub::Configurer::DSL::StubBuilder).to receive(:new).with(response_defaults)
31
+
32
+ subject
33
+ end
34
+
35
+ context "when a block is provided" do
36
+
37
+ context "that declares a stub builder parameter" do
38
+
39
+ let(:block) { lambda { |_stub_builder| "some block" } }
40
+
41
+ subject { producer.build_stub(&block) }
42
+
43
+ it "yields the created builder to the provided block" do
44
+ expect(block).to receive(:call).with(stub_builder)
45
+
46
+ subject
47
+ end
48
+
49
+ it "returns the created builder" do
50
+ expect(subject).to eql(stub_builder)
51
+ end
52
+
53
+ end
54
+
55
+ context "that has no parameters" do
56
+
57
+ subject { producer.build_stub { match_requests("/some/request/uri") } }
58
+
59
+ before(:example) { allow(stub_builder).to receive(:match_requests) }
60
+
61
+ it "executes the block in the context of the builder" do
62
+ expect(stub_builder).to receive(:match_requests).with("/some/request/uri")
63
+
64
+ subject
65
+ end
66
+
67
+ it "returns the created builder" do
68
+ expect(subject).to eql(stub_builder)
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+
75
+ context "when a block is not provided" do
76
+
77
+ subject { producer.build_stub }
78
+
79
+ it "returns the built stub" do
80
+ expect(subject).to eql(stub_builder)
81
+ end
82
+
83
+ end
84
+
85
+ end
86
+
87
+ describe "#add_stubs!" do
88
+
89
+ context "when multiple stub builders are provided" do
90
+
91
+ let(:stub_builders) { (1..3).map { instance_double(HttpStub::Configurer::DSL::StubBuilder) } }
92
+
93
+ subject { producer.add_stubs!(stub_builders) }
94
+
95
+ it "adds each stub to the producer" do
96
+ stub_builders.each { |stub_builder| expect(producer).to receive(:add_stub!).with(stub_builder) }
97
+
98
+ subject
99
+ end
100
+
101
+ end
102
+
103
+ end
104
+
105
+ end
@@ -1,14 +1,14 @@
1
- describe HttpStub::Configurer::Request::StubBuilder do
1
+ describe HttpStub::Configurer::DSL::StubBuilder do
2
2
 
3
3
  let(:response_defaults) { {} }
4
4
 
5
- let(:builder) { HttpStub::Configurer::Request::StubBuilder.new(response_defaults) }
5
+ let(:builder) { HttpStub::Configurer::DSL::StubBuilder.new(response_defaults) }
6
6
 
7
7
  shared_context "triggers one stub" do
8
8
 
9
9
  let(:trigger_stub) { instance_double(HttpStub::Configurer::Request::Stub) }
10
10
  let(:trigger_builder) do
11
- instance_double(HttpStub::Configurer::Request::StubBuilder, build: trigger_stub)
11
+ instance_double(HttpStub::Configurer::DSL::StubBuilder, build: trigger_stub)
12
12
  end
13
13
 
14
14
  before(:example) { builder.trigger(trigger_builder) }
@@ -19,23 +19,51 @@ describe HttpStub::Configurer::Request::StubBuilder do
19
19
 
20
20
  let(:trigger_stubs) { (1..3).map { instance_double(HttpStub::Configurer::Request::Stub) } }
21
21
  let(:trigger_builders) do
22
- trigger_stubs.map { |stub| instance_double(HttpStub::Configurer::Request::StubBuilder, build: stub) }
22
+ trigger_stubs.map { |stub| instance_double(HttpStub::Configurer::DSL::StubBuilder, build: stub) }
23
23
  end
24
24
 
25
25
  before(:example) { builder.trigger(trigger_builders) }
26
26
 
27
27
  end
28
28
 
29
+ describe "#match_requests" do
30
+
31
+ let(:fixture) { HttpStub::StubFixture.new }
32
+
33
+ subject { builder.match_requests(fixture.request.uri, fixture.request.symbolized) }
34
+
35
+ it "returns the builder to support method chaining" do
36
+ expect(subject).to eql(builder)
37
+ end
38
+
39
+ end
40
+
29
41
  describe "#respond_with" do
30
42
 
43
+ subject { builder.respond_with(status: 201) }
44
+
31
45
  it "does not modify any provided response defaults" do
32
46
  original_response_defaults = response_defaults.clone
33
47
 
34
- builder.respond_with(status: 201)
48
+ subject
35
49
 
36
50
  expect(response_defaults).to eql(original_response_defaults)
37
51
  end
38
52
 
53
+ it "returns the builder to support method chaining" do
54
+ expect(subject).to eql(builder)
55
+ end
56
+
57
+ end
58
+
59
+ describe "#trigger" do
60
+
61
+ subject { builder.trigger(instance_double(HttpStub::Configurer::DSL::StubBuilder)) }
62
+
63
+ it "returns the builder to support method chaining" do
64
+ expect(subject).to eql(builder)
65
+ end
66
+
39
67
  end
40
68
 
41
69
  describe "#build" do