http_stub 0.8.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
  }
@@ -35,6 +35,10 @@ module HttpStub
35
35
  @response_options["delay_in_seconds"]
36
36
  end
37
37
 
38
+ def headers
39
+ {"content-type" => @response_options["content_type"]}
40
+ end
41
+
38
42
  def empty?
39
43
  @original_options.empty?
40
44
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module HttpStub
2
- VERSION = "0.8.1"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -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
@@ -2,7 +2,7 @@ require 'simplecov'
2
2
  SimpleCov.start do
3
3
  add_filter "/spec/"
4
4
  add_filter "/vendor/"
5
- minimum_coverage 98.3
5
+ minimum_coverage 98.31
6
6
  refuse_coverage_drop
7
7
  end if ENV["coverage"]
8
8
 
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.8.1
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: -2719492474227436530
326
+ hash: 1728406266310263637
327
327
  requirements: []
328
328
  rubyforge_project: http_stub
329
- rubygems_version: 1.8.25
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.