http_stub 0.13.5 → 0.14.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/lib/http_stub.rb +13 -4
  3. data/lib/http_stub/configurer.rb +9 -63
  4. data/lib/http_stub/configurer/deprecated_dsl.rb +57 -0
  5. data/lib/http_stub/configurer/request/stub.rb +7 -13
  6. data/lib/http_stub/configurer/request/stub_activator.rb +8 -4
  7. data/lib/http_stub/configurer/request/stub_activator_payload_builder.rb +25 -0
  8. data/lib/http_stub/configurer/request/stub_payload_builder.rb +44 -0
  9. data/lib/http_stub/configurer/server/buffered_command_processor.rb +24 -0
  10. data/lib/http_stub/configurer/server/command.rb +18 -0
  11. data/lib/http_stub/configurer/server/command_processor.rb +38 -0
  12. data/lib/http_stub/configurer/server/dsl.rb +56 -0
  13. data/lib/http_stub/configurer/server/facade.rb +57 -0
  14. data/lib/http_stub/configurer/server/request_processor.rb +30 -0
  15. data/lib/http_stub/models/registry.rb +4 -0
  16. data/lib/http_stub/models/stub.rb +2 -1
  17. data/lib/http_stub/models/stub_registry.rb +29 -0
  18. data/lib/http_stub/models/stub_triggers.rb +23 -0
  19. data/lib/http_stub/rake/server_tasks.rb +2 -5
  20. data/lib/http_stub/server.rb +14 -4
  21. data/lib/http_stub/version.rb +1 -1
  22. data/lib/http_stub/views/_stub.haml +7 -0
  23. data/spec/lib/http_stub/configurer/deprecated_dsl_spec.rb +232 -0
  24. data/spec/lib/http_stub/configurer/request/controllable_value_spec.rb +8 -8
  25. data/spec/lib/http_stub/configurer/request/omittable_spec.rb +8 -8
  26. data/spec/lib/http_stub/configurer/request/regexpable_spec.rb +14 -14
  27. data/spec/lib/http_stub/configurer/request/stub_activator_payload_builder_spec.rb +74 -0
  28. data/spec/lib/http_stub/configurer/request/stub_activator_spec.rb +19 -26
  29. data/spec/lib/http_stub/configurer/request/stub_payload_builder_spec.rb +203 -0
  30. data/spec/lib/http_stub/configurer/request/stub_spec.rb +18 -157
  31. data/spec/lib/http_stub/configurer/server/buffered_command_processor_spec.rb +35 -0
  32. data/spec/lib/http_stub/configurer/server/command_processor_integration_spec.rb +62 -0
  33. data/spec/lib/http_stub/configurer/server/command_spec.rb +25 -0
  34. data/spec/lib/http_stub/configurer/server/dsl_spec.rb +241 -0
  35. data/spec/lib/http_stub/configurer/server/facade_spec.rb +253 -0
  36. data/spec/lib/http_stub/configurer/server/request_processor_spec.rb +99 -0
  37. data/spec/lib/http_stub/configurer_integration_spec.rb +172 -122
  38. data/spec/lib/http_stub/configurer_spec.rb +4 -4
  39. data/spec/lib/http_stub/controllers/stub_activator_controller_spec.rb +25 -25
  40. data/spec/lib/http_stub/controllers/stub_controller_spec.rb +22 -22
  41. data/spec/lib/http_stub/hash_extensions_spec.rb +24 -24
  42. data/spec/lib/http_stub/models/exact_value_matcher_spec.rb +4 -4
  43. data/spec/lib/http_stub/models/hash_with_string_value_matchers_spec.rb +29 -29
  44. data/spec/lib/http_stub/models/headers_spec.rb +10 -10
  45. data/spec/lib/http_stub/models/omitted_value_matcher_spec.rb +8 -8
  46. data/spec/lib/http_stub/models/regexp_value_matcher_spec.rb +6 -6
  47. data/spec/lib/http_stub/models/registry_spec.rb +71 -28
  48. data/spec/lib/http_stub/models/request_header_parser_spec.rb +4 -4
  49. data/spec/lib/http_stub/models/request_pipeline_spec.rb +2 -2
  50. data/spec/lib/http_stub/models/response_spec.rb +38 -38
  51. data/spec/lib/http_stub/models/string_value_matcher_spec.rb +25 -25
  52. data/spec/lib/http_stub/models/stub_activator_spec.rb +15 -15
  53. data/spec/lib/http_stub/models/stub_headers_spec.rb +18 -18
  54. data/spec/lib/http_stub/models/stub_parameters_spec.rb +16 -16
  55. data/spec/lib/http_stub/models/stub_registry_integration_spec.rb +62 -0
  56. data/spec/lib/http_stub/models/stub_registry_spec.rb +152 -0
  57. data/spec/lib/http_stub/models/stub_spec.rb +67 -43
  58. data/spec/lib/http_stub/models/stub_triggers_spec.rb +64 -0
  59. data/spec/lib/http_stub/models/stub_uri_spec.rb +9 -9
  60. data/spec/lib/http_stub/rake/server_daemon_tasks_smoke_spec.rb +7 -7
  61. data/spec/lib/http_stub/rake/server_tasks_smoke_spec.rb +5 -5
  62. data/spec/lib/http_stub/rake/server_tasks_spec.rb +17 -15
  63. data/spec/lib/http_stub/server_daemon_spec.rb +16 -16
  64. data/spec/lib/http_stub/server_integration_spec.rb +112 -65
  65. data/spec/lib/http_stub/server_spec.rb +134 -96
  66. data/spec/spec_helper.rb +1 -1
  67. data/spec/support/http_stub/configurer/request/stub_payload_builder_shared_context.rb +27 -0
  68. data/spec/support/server_integration.rb +2 -2
  69. metadata +69 -30
  70. data/lib/http_stub/configurer/command.rb +0 -26
  71. data/lib/http_stub/configurer/command_processor.rb +0 -36
  72. data/lib/http_stub/configurer/impatient_command_chain.rb +0 -13
  73. data/lib/http_stub/configurer/patient_command_chain.rb +0 -25
  74. data/spec/lib/http_stub/configurer/command_processor_integration_spec.rb +0 -63
  75. data/spec/lib/http_stub/configurer/command_spec.rb +0 -40
  76. data/spec/lib/http_stub/configurer/impatient_command_chain_spec.rb +0 -17
  77. data/spec/lib/http_stub/configurer/patient_command_chain_spec.rb +0 -73
@@ -0,0 +1,253 @@
1
+ describe HttpStub::Configurer::Server::Facade do
2
+
3
+ let(:configurer) { double(HttpStub::Configurer) }
4
+ let(:request_processor) { instance_double(HttpStub::Configurer::Server::RequestProcessor) }
5
+
6
+ let(:facade) { HttpStub::Configurer::Server::Facade.new(configurer) }
7
+
8
+ before(:example) do
9
+ allow(HttpStub::Configurer::Server::RequestProcessor).to receive(:new).and_return(request_processor)
10
+ end
11
+
12
+ describe "constructor" do
13
+
14
+ it "creates a request processor with the provided configurer" do
15
+ expect(HttpStub::Configurer::Server::RequestProcessor).to receive(:new).with(configurer)
16
+
17
+ facade
18
+ end
19
+
20
+ end
21
+
22
+ describe "#stub_response" do
23
+
24
+ let(:stub_uri) { "/some/stub/uri" }
25
+ let(:request) { instance_double(HttpStub::Configurer::Request::Stub, stub_uri: stub_uri) }
26
+
27
+ subject { facade.stub_response(request) }
28
+
29
+ before(:example) { allow(request_processor).to receive(:submit) }
30
+
31
+ it "submits the stub request via the request processor" do
32
+ expect(request_processor).to receive(:submit).with(hash_including(request: request))
33
+
34
+ subject
35
+ end
36
+
37
+ it "describes the stub via its stub uri" do
38
+ expect(request_processor).to receive(:submit).with(hash_including(description: "stubbing '#{stub_uri}'"))
39
+
40
+ subject
41
+ end
42
+
43
+ end
44
+
45
+ describe "#stub_activator" do
46
+
47
+ let(:activation_uri) { "/some/activation/uri" }
48
+ let(:request) { instance_double(HttpStub::Configurer::Request::StubActivator, activation_uri: activation_uri) }
49
+
50
+ subject { facade.stub_activator(request) }
51
+
52
+ before(:example) { allow(request_processor).to receive(:submit) }
53
+
54
+ it "submits the stub request via the request processor" do
55
+ expect(request_processor).to receive(:submit).with(hash_including(request: request))
56
+
57
+ subject
58
+ end
59
+
60
+ it "describes the stub via its activation uri" do
61
+ expect(request_processor).to(
62
+ receive(:submit).with(hash_including(description: "registering activator '#{activation_uri}'"))
63
+ )
64
+
65
+ subject
66
+ end
67
+
68
+ end
69
+
70
+ describe "#activate" do
71
+
72
+ let(:uri) { "/some/activation/uri" }
73
+ let(:request) { instance_double(Net::HTTP::Get) }
74
+
75
+ subject { facade.activate(uri) }
76
+
77
+ before(:example) do
78
+ allow(Net::HTTP::Get).to receive(:new).and_return(request)
79
+ allow(request_processor).to receive(:submit)
80
+ end
81
+
82
+ it "creates a GET request for the uri" do
83
+ expect(Net::HTTP::Get).to receive(:new).with(uri).and_return(request)
84
+
85
+ subject
86
+ end
87
+
88
+ it "submits the GET request via the request processor" do
89
+ expect(request_processor).to receive(:submit).with(hash_including(request: request))
90
+
91
+ subject
92
+ end
93
+
94
+ it "describes the activation request via the provided uri" do
95
+ expect(request_processor).to receive(:submit).with(hash_including(description: "activating '#{uri}'"))
96
+
97
+ subject
98
+ end
99
+
100
+ end
101
+
102
+ describe "#remember_stubs" do
103
+
104
+ let(:request) { instance_double(Net::HTTP::Post) }
105
+
106
+ subject { facade.remember_stubs }
107
+
108
+ before(:example) do
109
+ allow(Net::HTTP::Post).to receive(:new).and_return(request)
110
+ allow(request).to receive(:body=)
111
+ allow(request_processor).to receive(:submit)
112
+ end
113
+
114
+ it "creates a POST request for /stubs/memory endpoint" do
115
+ expect(Net::HTTP::Post).to receive(:new).with("/stubs/memory").and_return(request)
116
+
117
+ subject
118
+ end
119
+
120
+ it "establishes an empty body on the POST request" do
121
+ expect(request).to receive(:body=).with("")
122
+
123
+ subject
124
+ end
125
+
126
+ it "submits the POST request via the request processor" do
127
+ expect(request_processor).to receive(:submit).with(hash_including(request: request))
128
+
129
+ subject
130
+ end
131
+
132
+ it "describes the request as committing the servers stubs to memory" do
133
+ expect(request_processor).to receive(:submit).with(hash_including(description: "committing stubs to memory"))
134
+
135
+ subject
136
+ end
137
+
138
+ end
139
+
140
+ describe "#recall_stubs" do
141
+
142
+ let(:request) { instance_double(Net::HTTP::Get) }
143
+
144
+ subject { facade.recall_stubs }
145
+
146
+ before(:example) do
147
+ allow(Net::HTTP::Get).to receive(:new).and_return(request)
148
+ allow(request_processor).to receive(:submit)
149
+ end
150
+
151
+ it "creates a POST request for /stubs/memory endpoint" do
152
+ expect(Net::HTTP::Get).to receive(:new).with("/stubs/memory").and_return(request)
153
+
154
+ subject
155
+ end
156
+
157
+ it "submits the GET request via the request processor" do
158
+ expect(request_processor).to receive(:submit).with(hash_including(request: request))
159
+
160
+ subject
161
+ end
162
+
163
+ it "describes the request as recalling the servers stubs in memory" do
164
+ expect(request_processor).to receive(:submit).with(hash_including(description: "recalling stubs in memory"))
165
+
166
+ subject
167
+ end
168
+
169
+ end
170
+
171
+ describe "#clear_stubs" do
172
+
173
+ let(:request) { instance_double(Net::HTTP::Delete) }
174
+
175
+ subject { facade.clear_stubs }
176
+
177
+ before(:example) do
178
+ allow(Net::HTTP::Delete).to receive(:new).and_return(request)
179
+ allow(request_processor).to receive(:submit)
180
+ end
181
+
182
+ it "creates a DELETE request for the /stubs endpoint" do
183
+ expect(Net::HTTP::Delete).to receive(:new).with("/stubs").and_return(request)
184
+
185
+ subject
186
+ end
187
+
188
+ it "adds the DELETE request to the server state" do
189
+ expect(request_processor).to receive(:submit).with(hash_including(request: request))
190
+
191
+ subject
192
+ end
193
+
194
+ it "describes the request as clearing the server stubs" do
195
+ expect(request_processor).to receive(:submit).with(hash_including(description: "clearing stubs"))
196
+
197
+ subject
198
+ end
199
+
200
+ end
201
+
202
+ describe "#clear_activators" do
203
+
204
+ let(:request) { instance_double(Net::HTTP::Delete) }
205
+
206
+ subject { facade.clear_activators }
207
+
208
+ before(:example) do
209
+ allow(Net::HTTP::Delete).to receive(:new).and_return(request)
210
+ allow(request_processor).to receive(:submit)
211
+ end
212
+
213
+ it "creates a DELETE request for the /stubs/activators endpoint" do
214
+ expect(Net::HTTP::Delete).to receive(:new).with("/stubs/activators").and_return(request)
215
+
216
+ subject
217
+ end
218
+
219
+ it "adds the DELETE request to the server state" do
220
+ expect(request_processor).to receive(:submit).with(hash_including(request: request))
221
+
222
+ subject
223
+ end
224
+
225
+ it "describes the request as clearing the server stub activators" do
226
+ expect(request_processor).to receive(:submit).with(hash_including(description: "clearing activators"))
227
+
228
+ subject
229
+ end
230
+
231
+ end
232
+
233
+ describe "#server_has_started" do
234
+
235
+ it "informs the request processor to disable buffering requests" do
236
+ expect(request_processor).to receive(:disable_buffering!)
237
+
238
+ facade.server_has_started
239
+ end
240
+
241
+ end
242
+
243
+ describe "#flush_requests" do
244
+
245
+ it "informs the request processor to flush it's requests" do
246
+ expect(request_processor).to receive(:flush!)
247
+
248
+ facade.flush_requests
249
+ end
250
+
251
+ end
252
+
253
+ end
@@ -0,0 +1,99 @@
1
+ describe HttpStub::Configurer::Server::RequestProcessor do
2
+
3
+ let(:configurer) { double(HttpStub::Configurer) }
4
+ let(:command_processor) { instance_double(HttpStub::Configurer::Server::CommandProcessor) }
5
+ let(:buffered_command_processor) { instance_double(HttpStub::Configurer::Server::BufferedCommandProcessor) }
6
+
7
+ let(:request_processor) { HttpStub::Configurer::Server::RequestProcessor.new(configurer) }
8
+
9
+ before(:example) do
10
+ allow(HttpStub::Configurer::Server::CommandProcessor).to receive(:new).and_return(command_processor)
11
+ allow(HttpStub::Configurer::Server::BufferedCommandProcessor).to(
12
+ receive(:new).and_return(buffered_command_processor)
13
+ )
14
+ end
15
+
16
+ describe "constructor" do
17
+
18
+ it "creates a command processor for the configurer" do
19
+ expect(HttpStub::Configurer::Server::CommandProcessor).to receive(:new).with(configurer)
20
+
21
+ request_processor
22
+ end
23
+
24
+ it "creates a buffered command processor that flushes via the command processor" do
25
+ expect(HttpStub::Configurer::Server::BufferedCommandProcessor).to receive(:new).with(command_processor)
26
+
27
+ request_processor
28
+ end
29
+
30
+ end
31
+
32
+ describe "#submit" do
33
+
34
+ let(:args) { { some_arg_key: "some arg value" } }
35
+
36
+ subject { request_processor.submit(args) }
37
+
38
+ shared_examples_for "submitting a request to the server" do |processor_description|
39
+
40
+ let(:command) { instance_double(HttpStub::Configurer::Server::Command) }
41
+
42
+ before(:each) { allow(active_command_processor).to receive(:process) }
43
+
44
+ it "creates a command for the provided arguments" do
45
+ expect(HttpStub::Configurer::Server::Command).to receive(:new).with(hash_including(args)).and_return(command)
46
+
47
+ subject
48
+ end
49
+
50
+ it "processes the command via the #{processor_description}" do
51
+ allow(HttpStub::Configurer::Server::Command).to receive(:new).and_return(command)
52
+ expect(active_command_processor).to receive(:process).with(command)
53
+
54
+ subject
55
+ end
56
+
57
+ end
58
+
59
+ context "when request buffering is enabled" do
60
+
61
+ let(:active_command_processor) { buffered_command_processor }
62
+
63
+ it_behaves_like "submitting a request to the server", "buffered command processor"
64
+
65
+ end
66
+
67
+ context "when request buffering is disabled" do
68
+
69
+ let(:active_command_processor) { command_processor }
70
+
71
+ before(:example) { request_processor.disable_buffering! }
72
+
73
+ it_behaves_like "submitting a request to the server", "command processor"
74
+
75
+ end
76
+
77
+ end
78
+
79
+ describe "#flush!" do
80
+
81
+ subject { request_processor.flush! }
82
+
83
+ before(:example) { allow(buffered_command_processor).to receive(:flush) }
84
+
85
+ it "delegates to the buffered command processor" do
86
+ expect(buffered_command_processor).to receive(:flush)
87
+
88
+ subject
89
+ end
90
+
91
+ it "disables request buffering" do
92
+ expect(request_processor).to receive(:disable_buffering!)
93
+
94
+ subject
95
+ end
96
+
97
+ end
98
+
99
+ end
@@ -1,16 +1,17 @@
1
1
  describe HttpStub::Configurer, "when the server is running" do
2
2
  include_context "server integration"
3
3
 
4
- let(:configurer) { HttpStub::Examples::ConfigurerWithClassActivator.new }
4
+ let(:configurer) { HttpStub::Examples::ConfigurerWithClassActivator.new }
5
+ let(:stub_server) { configurer.stub_server }
5
6
 
6
- after(:each) do
7
+ after(:example) do
7
8
  configurer.clear_stubs!
8
9
  configurer.class.clear_activators!
9
10
  end
10
11
 
11
12
  context "and the configurer is initialized" do
12
13
 
13
- before(:each) do
14
+ before(:example) do
14
15
  configurer.class.host(server_host)
15
16
  configurer.class.port(server_port)
16
17
  configurer.class.initialize!
@@ -18,15 +19,15 @@ describe HttpStub::Configurer, "when the server is running" do
18
19
 
19
20
  context "and a stub is activated" do
20
21
 
21
- before(:each) { configurer.activate!("/an_activator") }
22
+ before(:example) { configurer.activate!("/an_activator") }
22
23
 
23
24
  context "and the stub request is made" do
24
25
 
25
26
  let(:response) { Net::HTTP.get_response(server_host, "/stub_path", server_port) }
26
27
 
27
- it "should replay the stubbed response" do
28
- response.code.should eql("200")
29
- response.body.should eql("Stub activator body")
28
+ it "replays the stubbed response" do
29
+ expect(response.code).to eql("200")
30
+ expect(response.body).to eql("Stub activator body")
30
31
  end
31
32
 
32
33
  end
@@ -39,8 +40,8 @@ describe HttpStub::Configurer, "when the server is running" do
39
40
 
40
41
  let(:response) { Net::HTTP.get_response(server_host, "/stub_path", server_port) }
41
42
 
42
- it "should respond with a 404 status code" do
43
- response.code.should eql("404")
43
+ it "responds with a 404 status code" do
44
+ expect(response.code).to eql("404")
44
45
  end
45
46
 
46
47
  end
@@ -51,28 +52,28 @@ describe HttpStub::Configurer, "when the server is running" do
51
52
 
52
53
  let(:configurer) { HttpStub::Examples::ConfigurerWithClassStub.new }
53
54
 
54
- it "should register the stub" do
55
+ it "registers the stub" do
55
56
  response = Net::HTTP.get_response(server_host, "/a_class_stub", server_port)
56
57
 
57
- response.code.should eql("201")
58
- response.body.should eql("Class stub body")
58
+ expect(response.code).to eql("201")
59
+ expect(response.body).to eql("Class stub body")
59
60
  end
60
61
 
61
62
  context "and the stub is overridden" do
62
63
 
63
- before(:each) do
64
+ before(:example) do
64
65
  configurer.stub_response!("/a_class_stub", method: :get, response: { body: "Other class stub body" })
65
66
  end
66
67
 
67
68
  context "and the configurer is re-initialized" do
68
69
 
69
- before(:each) { configurer.class.initialize! }
70
+ before(:example) { configurer.class.initialize! }
70
71
 
71
- it "should re-establish the class stub as having priority" do
72
+ it "re-establishes the class stub as having priority" do
72
73
  response = Net::HTTP.get_response(server_host, "/a_class_stub", server_port)
73
74
 
74
- response.code.should eql("201")
75
- response.body.should eql("Class stub body")
75
+ expect(response.code).to eql("201")
76
+ expect(response.body).to eql("Class stub body")
76
77
  end
77
78
 
78
79
  end
@@ -85,48 +86,48 @@ describe HttpStub::Configurer, "when the server is running" do
85
86
 
86
87
  let(:configurer) { HttpStub::Examples::ConfigurerWithComplexInitializer.new }
87
88
 
88
- it "should register the activated activator" do
89
+ it "registers the activated activator" do
89
90
  response = Net::HTTP.get_response(server_host, "/activated_during_initialization_stub_path", server_port)
90
91
 
91
- response.code.should eql("200")
92
- response.body.should eql("Activated during initialization body")
92
+ expect(response.code).to eql("200")
93
+ expect(response.body).to eql("Activated during initialization body")
93
94
  end
94
95
 
95
- it "should register the stub" do
96
+ it "registers the stub" do
96
97
  response = Net::HTTP.get_response(server_host, "/stubbed_during_initialization_path", server_port)
97
98
 
98
- response.code.should eql("200")
99
- response.body.should eql("Stubbed during initialization body")
99
+ expect(response.code).to eql("200")
100
+ expect(response.body).to eql("Stubbed during initialization body")
100
101
  end
101
102
 
102
103
  context "and another stub is registered" do
103
104
 
104
- before(:each) do
105
+ before(:example) do
105
106
  configurer.stub_response!("/another_stub", method: :get, response: { body: "Another stub body" })
106
107
  end
107
108
 
108
- context "and the configurer is reset" do
109
+ context "and the servers remembered stubs are recalled" do
109
110
 
110
- before(:each) { configurer.reset! }
111
+ before(:example) { configurer.recall_stubs! }
111
112
 
112
- it "should remove the stub registered post-initialization" do
113
+ it "removes the stub registered post-initialization" do
113
114
  response = Net::HTTP.get_response(server_host, "/another_stub", server_port)
114
115
 
115
- response.code.should eql("404")
116
+ expect(response.code).to eql("404")
116
117
  end
117
118
 
118
- it "should retain the activated activator during initialization" do
119
+ it "retains the activated activator during initialization" do
119
120
  response = Net::HTTP.get_response(server_host, "/activated_during_initialization_stub_path", server_port)
120
121
 
121
- response.code.should eql("200")
122
- response.body.should eql("Activated during initialization body")
122
+ expect(response.code).to eql("200")
123
+ expect(response.body).to eql("Activated during initialization body")
123
124
  end
124
125
 
125
- it "should retain the stub registered during initialization" do
126
+ it "retains the stub registered during initialization" do
126
127
  response = Net::HTTP.get_response(server_host, "/stubbed_during_initialization_path", server_port)
127
128
 
128
- response.code.should eql("200")
129
- response.body.should eql("Stubbed during initialization body")
129
+ expect(response.code).to eql("200")
130
+ expect(response.body).to eql("Stubbed during initialization body")
130
131
  end
131
132
 
132
133
  end
@@ -135,13 +136,13 @@ describe HttpStub::Configurer, "when the server is running" do
135
136
 
136
137
  end
137
138
 
138
- context "and a response for a request is stubbed" do
139
+ context "and a stub is submitted" do
139
140
 
140
141
  context "that contains no headers or parameters" do
141
142
 
142
143
  context "and contains a response status" do
143
144
 
144
- before(:each) do
145
+ before(:example) do
145
146
  configurer.stub_response!("/stub_with_status", method: :get, response: { status: 201, body: "Stub body" })
146
147
  end
147
148
 
@@ -149,26 +150,26 @@ describe HttpStub::Configurer, "when the server is running" do
149
150
 
150
151
  let(:response) { Net::HTTP.get_response(server_host, "/stub_with_status", server_port) }
151
152
 
152
- it "should respond with the stubbed status" do
153
- response.code.should eql("201")
153
+ it "responds with the stubbed status" do
154
+ expect(response.code).to eql("201")
154
155
  end
155
156
 
156
- it "should replay the stubbed body" do
157
- response.body.should eql("Stub body")
157
+ it "replays the stubbed body" do
158
+ expect(response.body).to eql("Stub body")
158
159
  end
159
160
 
160
161
  end
161
162
 
162
- context "and the stub is cleared" do
163
+ context "and stubs are cleared" do
163
164
 
164
- before(:each) { configurer.clear! }
165
+ before(:example) { configurer.clear_stubs! }
165
166
 
166
167
  context "and the original request is made" do
167
168
 
168
169
  let(:response) { Net::HTTP.get_response(server_host, "/stub_with_status", server_port) }
169
170
 
170
- it "should respond with a 404 status code" do
171
- response.code.should eql("404")
171
+ it "responds with a 404 status code" do
172
+ expect(response.code).to eql("404")
172
173
  end
173
174
 
174
175
  end
@@ -179,7 +180,7 @@ describe HttpStub::Configurer, "when the server is running" do
179
180
 
180
181
  context "and does not contain a response status" do
181
182
 
182
- before(:each) do
183
+ before(:example) do
183
184
  configurer.stub_response!("/stub_without_status", method: :get, response: { body: "Stub body" })
184
185
  end
185
186
 
@@ -187,15 +188,15 @@ describe HttpStub::Configurer, "when the server is running" do
187
188
 
188
189
  let(:response) { Net::HTTP.get_response(server_host, "/stub_without_status", server_port) }
189
190
 
190
- it "should respond with the stubbed body" do
191
- response.body.should eql("Stub body")
191
+ it "responds with the stubbed body" do
192
+ expect(response.body).to eql("Stub body")
192
193
  end
193
194
 
194
195
  end
195
196
 
196
197
  context "and the stub uri is regular expression containing meta characters" do
197
198
 
198
- before(:each) do
199
+ before(:example) do
199
200
  configurer.stub_response!(/\/stub\/regexp\/\$key=value/, method: :get, response: { body: "Stub body" })
200
201
  end
201
202
 
@@ -203,8 +204,8 @@ describe HttpStub::Configurer, "when the server is running" do
203
204
 
204
205
  let(:response) { Net::HTTP.get_response(server_host, "/match/stub/regexp/$key=value", server_port) }
205
206
 
206
- it "should respond with the stubbed body" do
207
- response.body.should eql("Stub body")
207
+ it "responds with the stubbed body" do
208
+ expect(response.body).to eql("Stub body")
208
209
  end
209
210
 
210
211
  end
@@ -213,8 +214,8 @@ describe HttpStub::Configurer, "when the server is running" do
213
214
 
214
215
  let(:response) { Net::HTTP.get_response(server_host, "/stub/no_match/regexp", server_port) }
215
216
 
216
- it "should respond with a 404 status code" do
217
- response.code.should eql("404")
217
+ it "responds with a 404 status code" do
218
+ expect(response.code).to eql("404")
218
219
  end
219
220
 
220
221
  end
@@ -230,7 +231,7 @@ describe HttpStub::Configurer, "when the server is running" do
230
231
 
231
232
  context "whose values are strings" do
232
233
 
233
- before(:each) do
234
+ before(:example) do
234
235
  configurer.stub_response!(
235
236
  "/stub_with_headers", method: :get, headers: { key: "value" },
236
237
  response: { status: 202, body: "Another stub body" }
@@ -241,9 +242,9 @@ describe HttpStub::Configurer, "when the server is running" do
241
242
 
242
243
  let(:response) { HTTParty.get("#{server_uri}/stub_with_headers", headers: { "key" => "value" }) }
243
244
 
244
- it "should replay the stubbed response" do
245
- response.code.should eql(202)
246
- response.body.should eql("Another stub body")
245
+ it "replays the stubbed response" do
246
+ expect(response.code).to eql(202)
247
+ expect(response.body).to eql("Another stub body")
247
248
  end
248
249
 
249
250
  end
@@ -252,8 +253,8 @@ describe HttpStub::Configurer, "when the server is running" do
252
253
 
253
254
  let(:response) { HTTParty.get("#{server_uri}/stub_with_headers", headers: { "key" => "other_value" }) }
254
255
 
255
- it "should respond with a 404 status code" do
256
- response.code.should eql(404)
256
+ it "responds with a 404 status code" do
257
+ expect(response.code).to eql(404)
257
258
  end
258
259
 
259
260
  end
@@ -262,7 +263,7 @@ describe HttpStub::Configurer, "when the server is running" do
262
263
 
263
264
  context "whose values are regular expressions" do
264
265
 
265
- before(:each) do
266
+ before(:example) do
266
267
  configurer.stub_response!(
267
268
  "/stub_with_headers", method: :get, headers: { key: /^match.*/ },
268
269
  response: { status: 202, body: "Another stub body" }
@@ -275,9 +276,9 @@ describe HttpStub::Configurer, "when the server is running" do
275
276
  HTTParty.get("#{server_uri}/stub_with_headers", headers: { "key" => "matching_value" })
276
277
  end
277
278
 
278
- it "should replay the stubbed response" do
279
- response.code.should eql(202)
280
- response.body.should eql("Another stub body")
279
+ it "replays the stubbed response" do
280
+ expect(response.code).to eql(202)
281
+ expect(response.body).to eql("Another stub body")
281
282
  end
282
283
 
283
284
  end
@@ -288,8 +289,8 @@ describe HttpStub::Configurer, "when the server is running" do
288
289
  HTTParty.get("#{server_uri}/stub_with_headers", headers: { "key" => "does_not_match_value" })
289
290
  end
290
291
 
291
- it "should respond with a 404 status code" do
292
- response.code.should eql(404)
292
+ it "responds with a 404 status code" do
293
+ expect(response.code).to eql(404)
293
294
  end
294
295
 
295
296
  end
@@ -302,7 +303,7 @@ describe HttpStub::Configurer, "when the server is running" do
302
303
 
303
304
  context "whose values are strings" do
304
305
 
305
- before(:each) do
306
+ before(:example) do
306
307
  configurer.stub_response!("/stub_with_parameters", method: :get, parameters: { key: "value" },
307
308
  response: { status: 202, body: "Another stub body" })
308
309
  end
@@ -311,9 +312,9 @@ describe HttpStub::Configurer, "when the server is running" do
311
312
 
312
313
  let(:response) { Net::HTTP.get_response(server_host, "/stub_with_parameters?key=value", server_port) }
313
314
 
314
- it "should replay the stubbed response" do
315
- response.code.should eql("202")
316
- response.body.should eql("Another stub body")
315
+ it "replays the stubbed response" do
316
+ expect(response.code).to eql("202")
317
+ expect(response.body).to eql("Another stub body")
317
318
  end
318
319
 
319
320
  end
@@ -324,8 +325,8 @@ describe HttpStub::Configurer, "when the server is running" do
324
325
  Net::HTTP.get_response(server_host, "/stub_with_parameters?key=another_value", server_port)
325
326
  end
326
327
 
327
- it "should respond with a 404 status code" do
328
- response.code.should eql("404")
328
+ it "responds with a 404 status code" do
329
+ expect(response.code).to eql("404")
329
330
  end
330
331
 
331
332
  end
@@ -334,7 +335,7 @@ describe HttpStub::Configurer, "when the server is running" do
334
335
 
335
336
  context "whose values are regular expressions" do
336
337
 
337
- before(:each) do
338
+ before(:example) do
338
339
  configurer.stub_response!(
339
340
  "/stub_with_parameters", method: :get, parameters: { key: /^match.*/ },
340
341
  response: { status: 202, body: "Another stub body" }
@@ -347,9 +348,9 @@ describe HttpStub::Configurer, "when the server is running" do
347
348
  Net::HTTP.get_response(server_host, "/stub_with_parameters?key=matching_value", server_port)
348
349
  end
349
350
 
350
- it "should replay the stubbed response" do
351
- response.code.should eql("202")
352
- response.body.should eql("Another stub body")
351
+ it "replays the stubbed response" do
352
+ expect(response.code).to eql("202")
353
+ expect(response.body).to eql("Another stub body")
353
354
  end
354
355
 
355
356
  end
@@ -360,8 +361,8 @@ describe HttpStub::Configurer, "when the server is running" do
360
361
  Net::HTTP.get_response(server_host, "/stub_with_parameters?key=does_not_match_value", server_port)
361
362
  end
362
363
 
363
- it "should respond with a 404 status code" do
364
- response.code.should eql("404")
364
+ it "responds with a 404 status code" do
365
+ expect(response.code).to eql("404")
365
366
  end
366
367
 
367
368
  end
@@ -370,7 +371,7 @@ describe HttpStub::Configurer, "when the server is running" do
370
371
 
371
372
  context "whose values indicate the parameters must be omitted" do
372
373
 
373
- before(:each) do
374
+ before(:example) do
374
375
  configurer.stub_response!(
375
376
  "/stub_with_omitted_parameters", method: :get, parameters: { key: :omitted },
376
377
  response: { status: 202, body: "Omitted parameter stub body" }
@@ -381,9 +382,9 @@ describe HttpStub::Configurer, "when the server is running" do
381
382
 
382
383
  let(:response) { Net::HTTP.get_response(server_host, "/stub_with_omitted_parameters", server_port) }
383
384
 
384
- it "should replay the stubbed response" do
385
- response.code.should eql("202")
386
- response.body.should eql("Omitted parameter stub body")
385
+ it "replays the stubbed response" do
386
+ expect(response.code).to eql("202")
387
+ expect(response.body).to eql("Omitted parameter stub body")
387
388
  end
388
389
 
389
390
  end
@@ -394,8 +395,8 @@ describe HttpStub::Configurer, "when the server is running" do
394
395
  Net::HTTP.get_response(server_host, "/stub_with_omitted_parameters?key=must_be_omitted", server_port)
395
396
  end
396
397
 
397
- it "should respond with a 404 status code" do
398
- response.code.should eql("404")
398
+ it "responds with a 404 status code" do
399
+ expect(response.code).to eql("404")
399
400
  end
400
401
 
401
402
  end
@@ -404,7 +405,7 @@ describe HttpStub::Configurer, "when the server is running" do
404
405
 
405
406
  context "whose values are numbers" do
406
407
 
407
- before(:each) do
408
+ before(:example) do
408
409
  configurer.stub_response!("/stub_with_parameters", method: :get, parameters: { key: 88 },
409
410
  response: { status: 203, body: "Body for parameter number" })
410
411
  end
@@ -413,9 +414,9 @@ describe HttpStub::Configurer, "when the server is running" do
413
414
 
414
415
  let(:response) { Net::HTTP.get_response(server_host, "/stub_with_parameters?key=88", server_port) }
415
416
 
416
- it "should replay the stubbed response" do
417
- response.code.should eql("203")
418
- response.body.should eql("Body for parameter number")
417
+ it "replays the stubbed response" do
418
+ expect(response.code).to eql("203")
419
+ expect(response.body).to eql("Body for parameter number")
419
420
  end
420
421
 
421
422
  end
@@ -424,7 +425,7 @@ describe HttpStub::Configurer, "when the server is running" do
424
425
 
425
426
  context "whose values are regular expressions" do
426
427
 
427
- before(:each) do
428
+ before(:example) do
428
429
  configurer.stub_response!(
429
430
  "/stub_with_parameters", method: :get, parameters: { key: /^match.*/ },
430
431
  response: { status: 202, body: "Another stub body" }
@@ -437,9 +438,9 @@ describe HttpStub::Configurer, "when the server is running" do
437
438
  Net::HTTP.get_response(server_host, "/stub_with_parameters?key=matching_value", server_port)
438
439
  end
439
440
 
440
- it "should replay the stubbed response" do
441
- response.code.should eql("202")
442
- response.body.should eql("Another stub body")
441
+ it "replays the stubbed response" do
442
+ expect(response.code).to eql("202")
443
+ expect(response.body).to eql("Another stub body")
443
444
  end
444
445
 
445
446
  end
@@ -450,8 +451,8 @@ describe HttpStub::Configurer, "when the server is running" do
450
451
  Net::HTTP.get_response(server_host, "/stub_with_parameters?key=does_not_match_value", server_port)
451
452
  end
452
453
 
453
- it "should respond with a 404 status code" do
454
- response.code.should eql("404")
454
+ it "responds with a 404 status code" do
455
+ expect(response.code).to eql("404")
455
456
  end
456
457
 
457
458
  end
@@ -460,7 +461,7 @@ describe HttpStub::Configurer, "when the server is running" do
460
461
 
461
462
  context "whose values indicate the parameters must be omitted" do
462
463
 
463
- before(:each) do
464
+ before(:example) do
464
465
  configurer.stub_response!(
465
466
  "/stub_with_omitted_parameters", method: :get, parameters: { key: :omitted },
466
467
  response: { status: 202, body: "Omitted parameter stub body" }
@@ -471,9 +472,9 @@ describe HttpStub::Configurer, "when the server is running" do
471
472
 
472
473
  let(:response) { Net::HTTP.get_response(server_host, "/stub_with_omitted_parameters", server_port) }
473
474
 
474
- it "should replay the stubbed response" do
475
- response.code.should eql("202")
476
- response.body.should eql("Omitted parameter stub body")
475
+ it "replays the stubbed response" do
476
+ expect(response.code).to eql("202")
477
+ expect(response.body).to eql("Omitted parameter stub body")
477
478
  end
478
479
 
479
480
  end
@@ -484,8 +485,57 @@ describe HttpStub::Configurer, "when the server is running" do
484
485
  Net::HTTP.get_response(server_host, "/stub_with_omitted_parameters?key=must_be_omitted", server_port)
485
486
  end
486
487
 
487
- it "should respond with a 404 status code" do
488
- response.code.should eql("404")
488
+ it "responds with a 404 status code" do
489
+ expect(response.code).to eql("404")
490
+ end
491
+
492
+ end
493
+
494
+ end
495
+
496
+ end
497
+
498
+ context "that contains triggers" do
499
+
500
+ let(:triggers) do
501
+ (1..3).map do |trigger_number|
502
+ stub_server.build_stub do |stub|
503
+ stub.match_request("/triggered_stub_#{trigger_number}", method: :get)
504
+ stub.with_response(status: 200 + trigger_number, body: "Triggered stub body #{trigger_number}")
505
+ end
506
+ end
507
+ end
508
+
509
+ before(:example) do
510
+ stub_server.add_stub! do |stub|
511
+ stub.match_request("/stub_with_triggers", method: :get)
512
+ stub.with_response(body: "Trigger stub body")
513
+ triggers.each { |trigger| stub.and_add_stub(trigger) }
514
+ end
515
+ end
516
+
517
+ context "and a request is made matching the stub" do
518
+
519
+ before(:example) do
520
+ @stub_with_triggers_response = Net::HTTP.get_response(server_host, "/stub_with_triggers", server_port)
521
+ end
522
+
523
+ it "replays the stubbed response" do
524
+ expect(@stub_with_triggers_response.code).to eql("200")
525
+ expect(@stub_with_triggers_response.body).to eql("Trigger stub body")
526
+ end
527
+
528
+ (1..3).each do |trigger_number|
529
+
530
+ context "and then a request matching triggered stub ##{trigger_number} is made" do
531
+
532
+ let(:response) { Net::HTTP.get_response(server_host, "/triggered_stub_#{trigger_number}", server_port) }
533
+
534
+ it "replays the triggered response" do
535
+ expect(response.code).to eql("20#{trigger_number}")
536
+ expect(response.body).to eql("Triggered stub body #{trigger_number}")
537
+ end
538
+
489
539
  end
490
540
 
491
541
  end
@@ -500,11 +550,11 @@ describe HttpStub::Configurer, "when the server is running" do
500
550
 
501
551
  let(:configurer) { HttpStub::Examples::ConfigurerWithInitializeCallback.new }
502
552
 
503
- it "should execute the callback" do
553
+ it "executes the callback" do
504
554
  response = Net::HTTP.get_response(server_host, "/stubbed_on_initialize_path", server_port)
505
555
 
506
- response.code.should eql("200")
507
- response.body.should eql("Stubbed on initialize body")
556
+ expect(response.code).to eql("200")
557
+ expect(response.body).to eql("Stubbed on initialize body")
508
558
  end
509
559
 
510
560
  end
@@ -515,61 +565,61 @@ describe HttpStub::Configurer, "when the server is running" do
515
565
 
516
566
  context "and the configurer is informed that the server has started" do
517
567
 
518
- before(:each) { configurer.server_has_started! }
568
+ before(:example) { configurer.server_has_started! }
519
569
 
520
- it "should not initialize the configurer" do
570
+ it "does not initialize the configurer" do
521
571
  activation_lambda = lambda { configurer.activate!("/an_activator") }
522
572
 
523
- activation_lambda.should raise_error(/error occurred activating '\/an_activator'/i)
573
+ expect(activation_lambda).to raise_error(/error occurred activating '\/an_activator'/i)
524
574
  end
525
575
 
526
576
  context "and an attempt is made to register a stub" do
527
577
 
528
- before(:each) do
578
+ before(:example) do
529
579
  configurer.stub_response!("/some_stub_path", method: :get, response: { body: "Some stub body"})
530
580
  end
531
581
 
532
- it "should register the stub" do
582
+ it "registers the stub" do
533
583
  response = Net::HTTP.get_response(server_host, "/some_stub_path", server_port)
534
584
 
535
- response.code.should eql("200")
536
- response.body.should eql("Some stub body")
585
+ expect(response.code).to eql("200")
586
+ expect(response.body).to eql("Some stub body")
537
587
  end
538
588
 
539
589
  end
540
590
 
541
591
  context "and an attempt is made to register a stub with a timeout" do
542
592
 
543
- before(:each) do
593
+ before(:example) do
544
594
  configurer.stub_response!("/some_stub_path", method: :get, response: {:delay_in_seconds => 2})
545
595
  end
546
596
 
547
- it "should delegate to request pipeline" do
597
+ it "delegates to request pipeline" do
548
598
  before = Time.new
549
599
 
550
600
  response = Net::HTTP.get_response(server_host, "/some_stub_path", server_port)
551
- response.code.should eql("200")
601
+ expect(response.code).to eql("200")
552
602
 
553
603
  after = Time.now
554
604
 
555
- (after - before).round().should be >= 2
605
+ expect((after - before).round()).to be >= 2
556
606
  end
557
607
 
558
608
  end
559
609
 
560
610
  describe "and an attempt is made to register a response with a content type header" do
561
611
 
562
- before(:each) do
612
+ before(:example) do
563
613
  configurer.stub_response!(
564
614
  "/some_stub_path", method: :get, response: { body: "Some stub body",
565
615
  headers: { "content-type" => "application/xhtml" } }
566
616
  )
567
617
  end
568
618
 
569
- it "should register the stub" do
619
+ it "registers the stub" do
570
620
  response = Net::HTTP.get_response("localhost", "/some_stub_path", 8001)
571
621
 
572
- response.content_type.should eql("application/xhtml")
622
+ expect(response.content_type).to eql("application/xhtml")
573
623
  end
574
624
 
575
625
  end
@@ -584,16 +634,16 @@ describe HttpStub::Configurer, "when the server is running" do
584
634
  }
585
635
  end
586
636
 
587
- before(:each) do
637
+ before(:example) do
588
638
  configurer.stub_response!(
589
639
  "/some_stub_path", method: :get, response: { body: "Some stub body", headers: response_headers }
590
640
  )
591
641
  end
592
642
 
593
- it "should register the stub" do
643
+ it "registers the stub" do
594
644
  response = Net::HTTP.get_response("localhost", "/some_stub_path", 8001)
595
645
 
596
- response_headers.each { |key, value| response[key].should eql(value) }
646
+ response_headers.each { |key, value| expect(response[key]).to eql(value) }
597
647
  end
598
648
 
599
649
  end
@@ -604,10 +654,10 @@ describe HttpStub::Configurer, "when the server is running" do
604
654
 
605
655
  context "and an attempt is made to activate a stub" do
606
656
 
607
- it "should raise an exception indicating an error occurred during activation" do
657
+ it "raises an exception indicating an error occurred during activation" do
608
658
  activation_lambda = lambda { configurer.activate!("/an_activator") }
609
659
 
610
- activation_lambda.should raise_error(/error occurred activating '\/an_activator'/i)
660
+ expect(activation_lambda).to raise_error(/error occurred activating '\/an_activator'/i)
611
661
  end
612
662
 
613
663
  end
@@ -618,10 +668,10 @@ describe HttpStub::Configurer, "when the server is running" do
618
668
 
619
669
  let(:configurer) { HttpStub::Examples::ConfigurerWithInitializeCallback.new }
620
670
 
621
- it "should not execute the callback" do
671
+ it "does not execute the callback" do
622
672
  response = Net::HTTP.get_response(server_host, "/stubbed_on_initialize_path", server_port)
623
673
 
624
- response.code.should eql("404")
674
+ expect(response.code).to eql("404")
625
675
  end
626
676
 
627
677
  end