http_stub 0.8.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/http_stub/configurer/request/stub.rb +1 -0
- data/lib/http_stub/models/response.rb +4 -0
- data/lib/http_stub/server.rb +1 -1
- data/lib/http_stub/version.rb +1 -1
- data/spec/lib/http_stub/configurer/request/stub_spec.rb +18 -0
- data/spec/lib/http_stub/configurer_integration_spec.rb +13 -0
- data/spec/lib/http_stub/server_spec.rb +6 -0
- data/spec/spec_helper.rb +1 -1
- metadata +3 -3
@@ -14,6 +14,7 @@ module HttpStub
|
|
14
14
|
"parameters" => HttpStub::Configurer::Request::Regexpable.format(options[:parameters] || {}),
|
15
15
|
"response" => {
|
16
16
|
"status" => options[:response][:status] || "",
|
17
|
+
"content_type" => options[:response][:content_type] || "application/json",
|
17
18
|
"body" => options[:response][:body],
|
18
19
|
"delay_in_seconds" => options[:response][:delay_in_seconds] || ""
|
19
20
|
}
|
data/lib/http_stub/server.rb
CHANGED
@@ -96,7 +96,7 @@ module HttpStub
|
|
96
96
|
response = @stub_activator_controller.activate(request) if response.empty?
|
97
97
|
response = HttpStub::Models::Response::ERROR if response.empty?
|
98
98
|
HttpStub::Models::RequestPipeline.before_halt(response)
|
99
|
-
halt(response.status, response.body)
|
99
|
+
halt(response.status, response.headers, response.body)
|
100
100
|
end
|
101
101
|
|
102
102
|
end
|
data/lib/http_stub/version.rb
CHANGED
@@ -11,6 +11,7 @@ describe HttpStub::Configurer::Request::Stub do
|
|
11
11
|
let(:response_status) { 500 }
|
12
12
|
let(:response_body) { "Some body" }
|
13
13
|
let(:response_delay_in_seconds) { 7 }
|
14
|
+
let(:response_content_type) { "application/xhtml" }
|
14
15
|
|
15
16
|
let(:stub_options) do
|
16
17
|
{
|
@@ -19,6 +20,7 @@ describe HttpStub::Configurer::Request::Stub do
|
|
19
20
|
parameters: parameters,
|
20
21
|
response: {
|
21
22
|
status: response_status,
|
23
|
+
content_type: response_content_type,
|
22
24
|
body: response_body,
|
23
25
|
delay_in_seconds: response_delay_in_seconds
|
24
26
|
}
|
@@ -152,6 +154,22 @@ describe HttpStub::Configurer::Request::Stub do
|
|
152
154
|
|
153
155
|
end
|
154
156
|
|
157
|
+
context "when a content type is provided" do
|
158
|
+
|
159
|
+
it "should have a response entry for the option" do
|
160
|
+
request_body["response"].should include("content_type" => response_content_type)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context "when a content type is not provided" do
|
165
|
+
|
166
|
+
let (:response_content_type) { nil }
|
167
|
+
|
168
|
+
it "should have a response entry with the default content type" do
|
169
|
+
request_body["response"].should include("content_type" => "application/json")
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
155
173
|
end
|
156
174
|
|
157
175
|
end
|
@@ -408,6 +408,19 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
408
408
|
|
409
409
|
end
|
410
410
|
|
411
|
+
describe "and an attempt is made to register a response with a given content type" do
|
412
|
+
|
413
|
+
before(:each) do
|
414
|
+
configurer.stub_response!("/some_stub_path", method: :get, response: { body: "Some stub body", content_type: "application/xhtml" })
|
415
|
+
end
|
416
|
+
|
417
|
+
it "should register the stub" do
|
418
|
+
response = Net::HTTP.get_response("localhost", "/some_stub_path", 8001)
|
419
|
+
response.content_type.should eql("application/xhtml")
|
420
|
+
end
|
421
|
+
|
422
|
+
end
|
423
|
+
|
411
424
|
end
|
412
425
|
|
413
426
|
describe "and the configurer has not been informed that the server has started" do
|
@@ -184,6 +184,12 @@ describe HttpStub::Server do
|
|
184
184
|
get "/some/stubbed/uri"
|
185
185
|
end
|
186
186
|
|
187
|
+
it "should respond with the response's content type" do
|
188
|
+
stub_controller.stub(:replay).and_return(HttpStub::Models::Response.new("status" => 200, "body" => "A body", "content_type" => "application/xhtml"))
|
189
|
+
get "/some/stubbed/uri"
|
190
|
+
response.content_type.should eql("application/xhtml")
|
191
|
+
end
|
192
|
+
|
187
193
|
end
|
188
194
|
|
189
195
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_stub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -323,10 +323,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
323
323
|
version: '0'
|
324
324
|
segments:
|
325
325
|
- 0
|
326
|
-
hash:
|
326
|
+
hash: 1728406266310263637
|
327
327
|
requirements: []
|
328
328
|
rubyforge_project: http_stub
|
329
|
-
rubygems_version: 1.8.
|
329
|
+
rubygems_version: 1.8.23
|
330
330
|
signing_key:
|
331
331
|
specification_version: 3
|
332
332
|
summary: A HTTP Server replaying configured stub responses.
|