http_stub 0.14.2 → 0.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/lib/http_stub/configurer/request/http/basic.rb +21 -0
  3. data/lib/http_stub/configurer/request/http/factory.rb +43 -0
  4. data/lib/http_stub/configurer/request/http/multipart.rb +33 -0
  5. data/lib/http_stub/configurer/request/stub.rb +24 -8
  6. data/lib/http_stub/configurer/request/stub_activator.rb +12 -8
  7. data/lib/http_stub/configurer/request/{stub_activator_payload_builder.rb → stub_activator_builder.rb} +4 -4
  8. data/lib/http_stub/configurer/request/stub_builder.rb +34 -0
  9. data/lib/http_stub/configurer/request/stub_response.rb +40 -0
  10. data/lib/http_stub/configurer/request/stub_response_file.rb +20 -0
  11. data/lib/http_stub/configurer/server/command.rb +5 -1
  12. data/lib/http_stub/configurer/server/command_processor.rb +1 -1
  13. data/lib/http_stub/configurer/server/dsl.rb +4 -4
  14. data/lib/http_stub/configurer/server/facade.rb +25 -11
  15. data/lib/http_stub/extensions/core/hash.rb +26 -0
  16. data/lib/http_stub/rake/server_daemon_tasks.rb +1 -1
  17. data/lib/http_stub/rake/server_tasks.rb +1 -1
  18. data/lib/http_stub/rake/task_generators.rb +3 -3
  19. data/lib/http_stub/server/application.rb +117 -0
  20. data/lib/http_stub/server/daemon.rb +39 -0
  21. data/lib/http_stub/{models → server}/exact_value_matcher.rb +1 -1
  22. data/lib/http_stub/{models → server}/hash_with_string_value_matchers.rb +2 -2
  23. data/lib/http_stub/{models → server}/headers.rb +1 -1
  24. data/lib/http_stub/{models → server}/omitted_value_matcher.rb +1 -1
  25. data/lib/http_stub/{models → server}/regexp_value_matcher.rb +1 -1
  26. data/lib/http_stub/{models → server}/registry.rb +10 -3
  27. data/lib/http_stub/{models → server}/request_header_parser.rb +1 -1
  28. data/lib/http_stub/server/response.rb +13 -0
  29. data/lib/http_stub/server/response_pipeline.rb +18 -0
  30. data/lib/http_stub/{models → server}/string_value_matcher.rb +4 -4
  31. data/lib/http_stub/server/stub.rb +37 -0
  32. data/lib/http_stub/{models → server}/stub_activator.rb +10 -2
  33. data/lib/http_stub/{controllers → server}/stub_activator_controller.rb +5 -5
  34. data/lib/http_stub/{controllers → server}/stub_controller.rb +4 -4
  35. data/lib/http_stub/server/stub_factory.rb +30 -0
  36. data/lib/http_stub/{models → server}/stub_headers.rb +4 -4
  37. data/lib/http_stub/{models → server}/stub_parameters.rb +2 -2
  38. data/lib/http_stub/{models → server}/stub_registry.rb +4 -4
  39. data/lib/http_stub/server/stub_response/base.rb +62 -0
  40. data/lib/http_stub/server/stub_response/file.rb +48 -0
  41. data/lib/http_stub/server/stub_response/text.rb +17 -0
  42. data/lib/http_stub/server/stub_response.rb +14 -0
  43. data/lib/http_stub/{models → server}/stub_triggers.rb +6 -2
  44. data/lib/http_stub/{models → server}/stub_uri.rb +2 -2
  45. data/lib/http_stub/{views → server/views}/_stub.haml +0 -0
  46. data/lib/http_stub/{views → server/views}/application.sass +0 -0
  47. data/lib/http_stub/{views → server/views}/layout.haml +0 -0
  48. data/lib/http_stub/{views → server/views}/stub_activators.haml +0 -0
  49. data/lib/http_stub/{views → server/views}/stubs.haml +0 -0
  50. data/lib/http_stub/version.rb +1 -1
  51. data/lib/http_stub.rb +41 -24
  52. data/spec/lib/http_stub/configurer/deprecated_dsl_spec.rb +2 -2
  53. data/spec/lib/http_stub/configurer/request/http/basic_spec.rb +15 -0
  54. data/spec/lib/http_stub/configurer/request/http/factory_spec.rb +148 -0
  55. data/spec/lib/http_stub/configurer/request/http/multipart_spec.rb +74 -0
  56. data/spec/lib/http_stub/configurer/request/stub_activator_builder_spec.rb +119 -0
  57. data/spec/lib/http_stub/configurer/request/stub_activator_spec.rb +24 -22
  58. data/spec/lib/http_stub/configurer/request/stub_builder_spec.rb +154 -0
  59. data/spec/lib/http_stub/configurer/request/stub_response_spec.rb +136 -0
  60. data/spec/lib/http_stub/configurer/request/stub_spec.rb +238 -17
  61. data/spec/lib/http_stub/configurer/server/command_processor_integration_spec.rb +7 -3
  62. data/spec/lib/http_stub/configurer/server/command_spec.rb +7 -6
  63. data/spec/lib/http_stub/configurer/server/dsl_spec.rb +58 -94
  64. data/spec/lib/http_stub/configurer/server/facade_spec.rb +56 -41
  65. data/spec/lib/http_stub/configurer_integration_spec.rb +180 -81
  66. data/spec/lib/http_stub/{hash_extensions_spec.rb → extensions/core/hash_spec.rb} +1 -1
  67. data/spec/lib/http_stub/rake/server_daemon_tasks_smoke_spec.rb +1 -1
  68. data/spec/lib/http_stub/{server_integration_spec.rb → server/application_integration_spec.rb} +1 -1
  69. data/spec/lib/http_stub/server/application_spec.rb +205 -0
  70. data/spec/lib/http_stub/server/daemon_integration_spec.rb +7 -0
  71. data/spec/lib/http_stub/{server_daemon_spec.rb → server/daemon_spec.rb} +4 -4
  72. data/spec/lib/http_stub/{models → server}/exact_value_matcher_spec.rb +2 -2
  73. data/spec/lib/http_stub/{models → server}/hash_with_string_value_matchers_spec.rb +5 -5
  74. data/spec/lib/http_stub/{models → server}/headers_spec.rb +2 -2
  75. data/spec/lib/http_stub/{models → server}/omitted_value_matcher_spec.rb +2 -2
  76. data/spec/lib/http_stub/{models → server}/regexp_value_matcher_spec.rb +2 -2
  77. data/spec/lib/http_stub/{models → server}/registry_spec.rb +52 -55
  78. data/spec/lib/http_stub/{models → server}/request_header_parser_spec.rb +4 -4
  79. data/spec/lib/http_stub/server/response_pipeline_spec.rb +29 -0
  80. data/spec/lib/http_stub/server/response_spec.rb +41 -0
  81. data/spec/lib/http_stub/{models → server}/string_value_matcher_spec.rb +11 -11
  82. data/spec/lib/http_stub/server/stub_activator_controller_spec.rb +85 -0
  83. data/spec/lib/http_stub/server/stub_activator_spec.rb +124 -0
  84. data/spec/lib/http_stub/server/stub_controller_spec.rb +74 -0
  85. data/spec/lib/http_stub/server/stub_factory_spec.rb +117 -0
  86. data/spec/lib/http_stub/{models → server}/stub_headers_spec.rb +9 -9
  87. data/spec/lib/http_stub/{models → server}/stub_parameters_spec.rb +6 -6
  88. data/spec/lib/http_stub/{models → server}/stub_registry_integration_spec.rb +3 -3
  89. data/spec/lib/http_stub/{models → server}/stub_registry_spec.rb +15 -35
  90. data/spec/lib/http_stub/server/stub_response/base_spec.rb +225 -0
  91. data/spec/lib/http_stub/server/stub_response/file_spec.rb +140 -0
  92. data/spec/lib/http_stub/server/stub_response/text_spec.rb +103 -0
  93. data/spec/lib/http_stub/server/stub_response_spec.rb +49 -0
  94. data/spec/lib/http_stub/{models → server}/stub_spec.rb +34 -18
  95. data/spec/lib/http_stub/{models → server}/stub_triggers_spec.rb +26 -16
  96. data/spec/lib/http_stub/{models → server}/stub_uri_spec.rb +5 -5
  97. data/spec/resources/sample.pdf +0 -0
  98. data/spec/resources/sample.txt +1 -0
  99. data/spec/spec_helper.rb +13 -4
  100. data/spec/support/stub_fixture.rb +106 -0
  101. metadata +148 -102
  102. data/lib/http_stub/configurer/request/stub_payload_builder.rb +0 -46
  103. data/lib/http_stub/hash_extensions.rb +0 -22
  104. data/lib/http_stub/models/request_pipeline.rb +0 -13
  105. data/lib/http_stub/models/response.rb +0 -43
  106. data/lib/http_stub/models/stub.rb +0 -35
  107. data/lib/http_stub/server.rb +0 -114
  108. data/lib/http_stub/server_daemon.rb +0 -36
  109. data/spec/lib/http_stub/configurer/request/stub_activator_payload_builder_spec.rb +0 -103
  110. data/spec/lib/http_stub/configurer/request/stub_payload_builder_spec.rb +0 -304
  111. data/spec/lib/http_stub/controllers/stub_activator_controller_spec.rb +0 -94
  112. data/spec/lib/http_stub/controllers/stub_controller_spec.rb +0 -83
  113. data/spec/lib/http_stub/models/request_pipeline_spec.rb +0 -17
  114. data/spec/lib/http_stub/models/response_spec.rb +0 -206
  115. data/spec/lib/http_stub/models/stub_activator_spec.rb +0 -76
  116. data/spec/lib/http_stub/server_daemon_integration_spec.rb +0 -7
  117. data/spec/lib/http_stub/server_spec.rb +0 -234
  118. data/spec/support/http_stub/configurer/request/stub_payload_builder_shared_context.rb +0 -27
@@ -21,12 +21,22 @@ describe HttpStub::Configurer::Server::Facade do
21
21
 
22
22
  describe "#stub_response" do
23
23
 
24
- let(:stub_uri) { "/some/stub/uri" }
25
- let(:request) { instance_double(HttpStub::Configurer::Request::Stub, stub_uri: stub_uri) }
24
+ let(:model_description) { "some model description" }
25
+ let(:model) { instance_double(HttpStub::Configurer::Request::Stub, to_s: model_description) }
26
+ let(:request) { instance_double(HttpStub::Configurer::Request::Http::Multipart) }
26
27
 
27
- subject { facade.stub_response(request) }
28
+ subject { facade.stub_response(model) }
28
29
 
29
- before(:example) { allow(request_processor).to receive(:submit) }
30
+ before(:example) do
31
+ allow(request_processor).to receive(:submit)
32
+ allow(HttpStub::Configurer::Request::Http::Factory).to receive(:stub).and_return(request)
33
+ end
34
+
35
+ it "creates a stub request with the provided model" do
36
+ expect(HttpStub::Configurer::Request::Http::Factory).to receive(:stub).with(model)
37
+
38
+ subject
39
+ end
30
40
 
31
41
  it "submits the stub request via the request processor" do
32
42
  expect(request_processor).to receive(:submit).with(hash_including(request: request))
@@ -34,8 +44,8 @@ describe HttpStub::Configurer::Server::Facade do
34
44
  subject
35
45
  end
36
46
 
37
- it "describes the stub via its stub uri" do
38
- expect(request_processor).to receive(:submit).with(hash_including(description: "stubbing '#{stub_uri}'"))
47
+ it "describes the model via its string representation" do
48
+ expect(request_processor).to receive(:submit).with(hash_including(description: "stubbing '#{model_description}'"))
39
49
 
40
50
  subject
41
51
  end
@@ -44,22 +54,32 @@ describe HttpStub::Configurer::Server::Facade do
44
54
 
45
55
  describe "#stub_activator" do
46
56
 
47
- let(:activation_uri) { "/some/activation/uri" }
48
- let(:request) { instance_double(HttpStub::Configurer::Request::StubActivator, activation_uri: activation_uri) }
57
+ let(:model_description) { "some model description" }
58
+ let(:model) { instance_double(HttpStub::Configurer::Request::StubActivator, to_s: model_description) }
59
+ let(:request) { instance_double(HttpStub::Configurer::Request::Http::Multipart) }
49
60
 
50
- subject { facade.stub_activator(request) }
61
+ subject { facade.stub_activator(model) }
51
62
 
52
- before(:example) { allow(request_processor).to receive(:submit) }
63
+ before(:example) do
64
+ allow(request_processor).to receive(:submit)
65
+ allow(HttpStub::Configurer::Request::Http::Factory).to receive(:stub_activator).and_return(request)
66
+ end
53
67
 
54
- it "submits the stub request via the request processor" do
68
+ it "creates a stub activator request with the provided model" do
69
+ expect(HttpStub::Configurer::Request::Http::Factory).to receive(:stub_activator).with(model)
70
+
71
+ subject
72
+ end
73
+
74
+ it "submits the stub activator request via the request processor" do
55
75
  expect(request_processor).to receive(:submit).with(hash_including(request: request))
56
76
 
57
77
  subject
58
78
  end
59
79
 
60
- it "describes the stub via its activation uri" do
80
+ it "describes the model via its string representation" do
61
81
  expect(request_processor).to(
62
- receive(:submit).with(hash_including(description: "registering activator '#{activation_uri}'"))
82
+ receive(:submit).with(hash_including(description: "registering activator '#{model_description}'"))
63
83
  )
64
84
 
65
85
  subject
@@ -70,22 +90,22 @@ describe HttpStub::Configurer::Server::Facade do
70
90
  describe "#activate" do
71
91
 
72
92
  let(:uri) { "/some/activation/uri" }
73
- let(:request) { instance_double(Net::HTTP::Get) }
93
+ let(:request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
74
94
 
75
95
  subject { facade.activate(uri) }
76
96
 
77
97
  before(:example) do
78
- allow(Net::HTTP::Get).to receive(:new).and_return(request)
98
+ allow(HttpStub::Configurer::Request::Http::Factory).to receive(:get).and_return(request)
79
99
  allow(request_processor).to receive(:submit)
80
100
  end
81
101
 
82
102
  it "creates a GET request for the uri" do
83
- expect(Net::HTTP::Get).to receive(:new).with(uri).and_return(request)
103
+ expect(HttpStub::Configurer::Request::Http::Factory).to receive(:get).with(uri).and_return(request)
84
104
 
85
105
  subject
86
106
  end
87
107
 
88
- it "submits the GET request via the request processor" do
108
+ it "submits the request via the request processor" do
89
109
  expect(request_processor).to receive(:submit).with(hash_including(request: request))
90
110
 
91
111
  subject
@@ -101,29 +121,22 @@ describe HttpStub::Configurer::Server::Facade do
101
121
 
102
122
  describe "#remember_stubs" do
103
123
 
104
- let(:request) { instance_double(Net::HTTP::Post) }
124
+ let(:request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
105
125
 
106
126
  subject { facade.remember_stubs }
107
127
 
108
128
  before(:example) do
109
- allow(Net::HTTP::Post).to receive(:new).and_return(request)
110
- allow(request).to receive(:body=)
129
+ allow(HttpStub::Configurer::Request::Http::Factory).to receive(:post).and_return(request)
111
130
  allow(request_processor).to receive(:submit)
112
131
  end
113
132
 
114
133
  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("")
134
+ expect(HttpStub::Configurer::Request::Http::Factory).to receive(:post).with("/stubs/memory").and_return(request)
122
135
 
123
136
  subject
124
137
  end
125
138
 
126
- it "submits the POST request via the request processor" do
139
+ it "submits the request via the request processor" do
127
140
  expect(request_processor).to receive(:submit).with(hash_including(request: request))
128
141
 
129
142
  subject
@@ -139,22 +152,22 @@ describe HttpStub::Configurer::Server::Facade do
139
152
 
140
153
  describe "#recall_stubs" do
141
154
 
142
- let(:request) { instance_double(Net::HTTP::Get) }
155
+ let(:request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
143
156
 
144
157
  subject { facade.recall_stubs }
145
158
 
146
159
  before(:example) do
147
- allow(Net::HTTP::Get).to receive(:new).and_return(request)
160
+ allow(HttpStub::Configurer::Request::Http::Factory).to receive(:get).and_return(request)
148
161
  allow(request_processor).to receive(:submit)
149
162
  end
150
163
 
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)
164
+ it "creates a GET request for /stubs/memory endpoint" do
165
+ expect(HttpStub::Configurer::Request::Http::Factory).to receive(:get).with("/stubs/memory").and_return(request)
153
166
 
154
167
  subject
155
168
  end
156
169
 
157
- it "submits the GET request via the request processor" do
170
+ it "submits the request via the request processor" do
158
171
  expect(request_processor).to receive(:submit).with(hash_including(request: request))
159
172
 
160
173
  subject
@@ -170,22 +183,22 @@ describe HttpStub::Configurer::Server::Facade do
170
183
 
171
184
  describe "#clear_stubs" do
172
185
 
173
- let(:request) { instance_double(Net::HTTP::Delete) }
186
+ let(:request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
174
187
 
175
188
  subject { facade.clear_stubs }
176
189
 
177
190
  before(:example) do
178
- allow(Net::HTTP::Delete).to receive(:new).and_return(request)
191
+ allow(HttpStub::Configurer::Request::Http::Factory).to receive(:delete).and_return(request)
179
192
  allow(request_processor).to receive(:submit)
180
193
  end
181
194
 
182
195
  it "creates a DELETE request for the /stubs endpoint" do
183
- expect(Net::HTTP::Delete).to receive(:new).with("/stubs").and_return(request)
196
+ expect(HttpStub::Configurer::Request::Http::Factory).to receive(:delete).with("/stubs").and_return(request)
184
197
 
185
198
  subject
186
199
  end
187
200
 
188
- it "adds the DELETE request to the server state" do
201
+ it "submits the request via the request processor" do
189
202
  expect(request_processor).to receive(:submit).with(hash_including(request: request))
190
203
 
191
204
  subject
@@ -201,22 +214,24 @@ describe HttpStub::Configurer::Server::Facade do
201
214
 
202
215
  describe "#clear_activators" do
203
216
 
204
- let(:request) { instance_double(Net::HTTP::Delete) }
217
+ let(:request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
205
218
 
206
219
  subject { facade.clear_activators }
207
220
 
208
221
  before(:example) do
209
- allow(Net::HTTP::Delete).to receive(:new).and_return(request)
222
+ allow(HttpStub::Configurer::Request::Http::Factory).to receive(:delete).and_return(request)
210
223
  allow(request_processor).to receive(:submit)
211
224
  end
212
225
 
213
226
  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)
227
+ expect(HttpStub::Configurer::Request::Http::Factory).to(
228
+ receive(:delete).with("/stubs/activators").and_return(request)
229
+ )
215
230
 
216
231
  subject
217
232
  end
218
233
 
219
- it "adds the DELETE request to the server state" do
234
+ it "submits the HTTP Stub request via the request processor" do
220
235
  expect(request_processor).to receive(:submit).with(hash_including(request: request))
221
236
 
222
237
  subject