http_stub 0.24.2 → 0.24.3
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.
- checksums.yaml +4 -4
- data/lib/http_stub/configurer/dsl/stub_builder.rb +1 -1
- data/lib/http_stub/configurer/part.rb +5 -1
- data/lib/http_stub/extensions/core/hash/indifferent_and_insensitive_access.rb +1 -1
- data/lib/http_stub/server/stub/match/rule/method.rb +1 -1
- data/lib/http_stub/server/stub/response/file.rb +1 -1
- data/lib/http_stub/version.rb +1 -1
- data/spec/acceptance/stub_spec.rb +29 -4
- data/spec/acceptance/stub_trigger_spec.rb +6 -8
- data/spec/lib/http_stub/configurer/part_spec.rb +35 -1
- data/spec/lib/http_stub/server/stub/response/file_spec.rb +12 -10
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae298667f0d24ef61eee93ad2a8a9daa92d5ed87
|
4
|
+
data.tar.gz: 82479a4ed23ef2173f90a9f19504fdaa72377f50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f81e67a3de971f554b81ce98e0d0fdd49534d855ae524466ee030ea46eedfd63baafd5900f37795daabddfbe4ef75071834dcf2d5e6110b01a826c1e9358b2a
|
7
|
+
data.tar.gz: b0858d659ce4bacb911d4b16e7ab870219384901881668ee181c7a68285b6d6291114f568c4be25ecdcca8318b1b4b5af796495bc411ddd92f3bf0d40b2d7ae3
|
@@ -10,7 +10,11 @@ module HttpStub
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def method_missing(name, *args, &block)
|
13
|
-
@configurer.send(name, *args, &block)
|
13
|
+
@configurer.respond_to?(name, true) ? @configurer.send(name, *args, &block) : super
|
14
|
+
end
|
15
|
+
|
16
|
+
def respond_to_missing?(name, include_private = false)
|
17
|
+
@configurer.respond_to?(name, include_private)
|
14
18
|
end
|
15
19
|
|
16
20
|
end
|
@@ -12,7 +12,7 @@ module HttpStub
|
|
12
12
|
private
|
13
13
|
|
14
14
|
def indifferent_and_insensitive_find(key)
|
15
|
-
entry = self.find { |entry_key, _entry_value| entry_key.to_s.casecmp(key.to_s)
|
15
|
+
entry = self.find { |entry_key, _entry_value| entry_key.to_s.casecmp(key.to_s).zero? }
|
16
16
|
entry ? entry[1] : nil
|
17
17
|
end
|
18
18
|
|
@@ -26,7 +26,7 @@ module HttpStub
|
|
26
26
|
private
|
27
27
|
|
28
28
|
def send_options
|
29
|
-
{
|
29
|
+
{ type: @headers["content-type"] }.tap do |options|
|
30
30
|
options[:last_modified] = @headers["last-modified"] if @headers["last-modified"]
|
31
31
|
options[:disposition] = @headers["content-disposition"] if @headers["content-disposition"]
|
32
32
|
end
|
data/lib/http_stub/version.rb
CHANGED
@@ -237,11 +237,11 @@ describe "Stub basics acceptance" do
|
|
237
237
|
|
238
238
|
context "and a request that matches is made" do
|
239
239
|
|
240
|
-
context "
|
240
|
+
context "matching a stub with a custom content-type" do
|
241
241
|
|
242
|
-
let(:response) {
|
242
|
+
let(:response) { issue_request }
|
243
243
|
|
244
|
-
it "responds with
|
244
|
+
it "responds with a status code of 200" do
|
245
245
|
expect(response.code).to eql(200)
|
246
246
|
end
|
247
247
|
|
@@ -253,9 +253,34 @@ describe "Stub basics acceptance" do
|
|
253
253
|
expect_response_to_contain_file(HttpStub::Examples::ConfigurerWithFileResponses::FILE_PATH)
|
254
254
|
end
|
255
255
|
|
256
|
+
context "and a subsequent request is made that requests the file if it has been modified" do
|
257
|
+
|
258
|
+
let(:first_response) { issue_request }
|
259
|
+
let(:file_last_modified_time) { first_response.headers["Last-Modified"] }
|
260
|
+
|
261
|
+
let(:second_response) { issue_request("if_modified_since" => file_last_modified_time) }
|
262
|
+
|
263
|
+
it "responds with a status code of 304 to indicate the file is unchanged" do
|
264
|
+
expect(second_response.code).to eql(304)
|
265
|
+
end
|
266
|
+
|
267
|
+
it "responds with no content type" do
|
268
|
+
expect(second_response.content_type).to be(nil)
|
269
|
+
end
|
270
|
+
|
271
|
+
it "responds with an empty body" do
|
272
|
+
expect(second_response.body).to be(nil)
|
273
|
+
end
|
274
|
+
|
275
|
+
end
|
276
|
+
|
277
|
+
def issue_request(headers={})
|
278
|
+
HTTParty.get("#{server_uri}/stub_response_with_file", headers: headers)
|
279
|
+
end
|
280
|
+
|
256
281
|
end
|
257
282
|
|
258
|
-
context "
|
283
|
+
context "matching a stub with no content-type" do
|
259
284
|
|
260
285
|
let(:response) { HTTParty.get("#{server_uri}/stub_response_with_file_and_no_content_type") }
|
261
286
|
|
@@ -61,9 +61,8 @@ describe "Stub trigger acceptance" do
|
|
61
61
|
stub_server.build_stub do |stub|
|
62
62
|
stub.match_requests(uri: "/triggered_stub_pdf_file", method: :get)
|
63
63
|
stub.respond_with(
|
64
|
-
status: 201,
|
65
64
|
headers: { "content-type" => "application/pdf" },
|
66
|
-
body:
|
65
|
+
body: { file: { path: pdf_file_path, name: ::File.basename(pdf_file_path) } }
|
67
66
|
)
|
68
67
|
end
|
69
68
|
end
|
@@ -72,7 +71,7 @@ describe "Stub trigger acceptance" do
|
|
72
71
|
let(:text_trigger) do
|
73
72
|
stub_server.build_stub do |stub|
|
74
73
|
stub.match_requests(uri: "/triggered_stub_text", method: :get)
|
75
|
-
stub.respond_with(status:
|
74
|
+
stub.respond_with(status: 201, body: "Sample trigger stub body")
|
76
75
|
end
|
77
76
|
end
|
78
77
|
|
@@ -81,9 +80,8 @@ describe "Stub trigger acceptance" do
|
|
81
80
|
stub_server.build_stub do |stub|
|
82
81
|
stub.match_requests(uri: "/triggered_stub_txt_file", method: :get)
|
83
82
|
stub.respond_with(
|
84
|
-
status: 203,
|
85
83
|
headers: { "content-type" => "text/plain" },
|
86
|
-
body:
|
84
|
+
body: { file: { path: txt_file_path, name: ::File.basename(txt_file_path) } }
|
87
85
|
)
|
88
86
|
end
|
89
87
|
end
|
@@ -107,7 +105,7 @@ describe "Stub trigger acceptance" do
|
|
107
105
|
let(:response) { HTTParty.get("#{server_uri}/triggered_stub_pdf_file") }
|
108
106
|
|
109
107
|
it "replays the triggered response" do
|
110
|
-
expect(response.code).to eql(
|
108
|
+
expect(response.code).to eql(200)
|
111
109
|
expect_response_to_contain_file(pdf_file_path)
|
112
110
|
end
|
113
111
|
|
@@ -118,7 +116,7 @@ describe "Stub trigger acceptance" do
|
|
118
116
|
let(:response) { HTTParty.get("#{server_uri}/triggered_stub_text") }
|
119
117
|
|
120
118
|
it "replays the triggered response" do
|
121
|
-
expect(response.code).to eql(
|
119
|
+
expect(response.code).to eql(201)
|
122
120
|
expect(response.body).to eql(text_body)
|
123
121
|
end
|
124
122
|
|
@@ -129,7 +127,7 @@ describe "Stub trigger acceptance" do
|
|
129
127
|
let(:response) { HTTParty.get("#{server_uri}/triggered_stub_txt_file") }
|
130
128
|
|
131
129
|
it "replays the triggered response" do
|
132
|
-
expect(response.code).to eql(
|
130
|
+
expect(response.code).to eql(200)
|
133
131
|
expect(response.parsed_response).to eql(::File.read(txt_file_path))
|
134
132
|
end
|
135
133
|
|
@@ -8,7 +8,7 @@ describe HttpStub::Configurer::Part do
|
|
8
8
|
Class.new.tap { |part_class| part_class.send(:include, HttpStub::Configurer::Part) }
|
9
9
|
end
|
10
10
|
|
11
|
-
let(:part)
|
11
|
+
let(:part) { part_class.new }
|
12
12
|
|
13
13
|
describe "#configure" do
|
14
14
|
|
@@ -66,4 +66,38 @@ describe HttpStub::Configurer::Part do
|
|
66
66
|
|
67
67
|
end
|
68
68
|
|
69
|
+
context "when configured" do
|
70
|
+
|
71
|
+
before(:example) { part.configure(configurer) }
|
72
|
+
|
73
|
+
describe "other methods on the part" do
|
74
|
+
|
75
|
+
context "when defined in the configurer" do
|
76
|
+
|
77
|
+
it "are defined on the part" do
|
78
|
+
expect(part.respond_to?(:stub_server)).to be(true)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "are delegated to the configurer" do
|
82
|
+
expect(part.stub_server).to eql(configurer.stub_server)
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
context "when not defined in the configurer" do
|
88
|
+
|
89
|
+
it "are not defined on the part" do
|
90
|
+
expect(part.respond_to?(:not_in_configurer)).to be(false)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "raise an error on the part when invoked" do
|
94
|
+
expect { part.not_in_configurer }.to raise_error(/#{part_class}/)
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
69
103
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
describe HttpStub::Server::Stub::Response::File do
|
2
2
|
|
3
|
-
let(:
|
4
|
-
let(:
|
5
|
-
let(:
|
6
|
-
let(:
|
7
|
-
let(:
|
8
|
-
let(:args)
|
3
|
+
let(:headers) { {} }
|
4
|
+
let(:file_name) { "sample.txt" }
|
5
|
+
let(:temp_file_path) { "#{HttpStub::Spec::RESOURCES_DIR}/#{file_name}" }
|
6
|
+
let(:body) { { filename: file_name, tempfile: File.new(temp_file_path) } }
|
7
|
+
let(:additional_args) { {} }
|
8
|
+
let(:args) { { "headers" => headers, "body" => body }.merge(additional_args) }
|
9
9
|
|
10
10
|
let(:response_file) { HttpStub::Server::Stub::Response::File.new(args) }
|
11
11
|
|
@@ -55,7 +55,7 @@ describe HttpStub::Server::Stub::Response::File do
|
|
55
55
|
end
|
56
56
|
|
57
57
|
it "creates a new response file with other arguments preserved" do
|
58
|
-
expect(described_class).to receive(:new).with(hash_including("
|
58
|
+
expect(described_class).to receive(:new).with(hash_including("body" => body))
|
59
59
|
|
60
60
|
subject
|
61
61
|
end
|
@@ -75,7 +75,9 @@ describe HttpStub::Server::Stub::Response::File do
|
|
75
75
|
|
76
76
|
describe "#serve_on" do
|
77
77
|
|
78
|
-
let(:
|
78
|
+
let(:status) { 321 }
|
79
|
+
let(:additional_args) { { "status" => status } }
|
80
|
+
let(:server) { instance_double(Sinatra::Base) }
|
79
81
|
|
80
82
|
subject { response_file.serve_on(server) }
|
81
83
|
|
@@ -85,8 +87,8 @@ describe HttpStub::Server::Stub::Response::File do
|
|
85
87
|
subject
|
86
88
|
end
|
87
89
|
|
88
|
-
it "sends the file
|
89
|
-
expect(server).to receive(:send_file).with(anything,
|
90
|
+
it "sends the file without any provided response status to ensure that 304 responses are honoured" do
|
91
|
+
expect(server).to receive(:send_file).with(anything, hash_excluding(:status))
|
90
92
|
|
91
93
|
subject
|
92
94
|
end
|
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.24.
|
4
|
+
version: 0.24.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dueckes
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date: 2016-
|
15
|
+
date: 2016-08-02 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: rake
|
@@ -146,14 +146,14 @@ dependencies:
|
|
146
146
|
requirements:
|
147
147
|
- - "~>"
|
148
148
|
- !ruby/object:Gem::Version
|
149
|
-
version: '0.
|
149
|
+
version: '0.42'
|
150
150
|
type: :development
|
151
151
|
prerelease: false
|
152
152
|
version_requirements: !ruby/object:Gem::Requirement
|
153
153
|
requirements:
|
154
154
|
- - "~>"
|
155
155
|
- !ruby/object:Gem::Version
|
156
|
-
version: '0.
|
156
|
+
version: '0.42'
|
157
157
|
- !ruby/object:Gem::Dependency
|
158
158
|
name: rspec
|
159
159
|
requirement: !ruby/object:Gem::Requirement
|
@@ -188,14 +188,14 @@ dependencies:
|
|
188
188
|
requirements:
|
189
189
|
- - "~>"
|
190
190
|
- !ruby/object:Gem::Version
|
191
|
-
version: '0.
|
191
|
+
version: '0.14'
|
192
192
|
type: :development
|
193
193
|
prerelease: false
|
194
194
|
version_requirements: !ruby/object:Gem::Requirement
|
195
195
|
requirements:
|
196
196
|
- - "~>"
|
197
197
|
- !ruby/object:Gem::Version
|
198
|
-
version: '0.
|
198
|
+
version: '0.14'
|
199
199
|
- !ruby/object:Gem::Dependency
|
200
200
|
name: rack-test
|
201
201
|
requirement: !ruby/object:Gem::Requirement
|