http_stub 0.15.0 → 0.15.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/http_stub.rb +0 -6
- data/lib/http_stub/server/registry.rb +1 -3
- data/lib/http_stub/server/stub.rb +0 -5
- data/lib/http_stub/server/stub_activator.rb +0 -4
- data/lib/http_stub/server/stub_response/base.rb +0 -4
- data/lib/http_stub/server/stub_response/file.rb +1 -18
- data/lib/http_stub/server/stub_triggers.rb +0 -4
- data/lib/http_stub/version.rb +1 -1
- data/spec/lib/http_stub/server/registry_spec.rb +49 -7
- data/spec/lib/http_stub/server/stub_activator_spec.rb +0 -10
- data/spec/lib/http_stub/server/stub_response/base_spec.rb +0 -8
- data/spec/lib/http_stub/server/stub_response/file_spec.rb +2 -26
- data/spec/lib/http_stub/server/stub_spec.rb +2 -20
- data/spec/lib/http_stub/server/stub_triggers_spec.rb +0 -10
- data/spec/spec_helper.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 438c42456ebda9bd71a4c56735be06a71c62ef68
|
4
|
+
data.tar.gz: d9c2910a45e9c6ec166e58d7d02dd1f8a2d31357
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79748781d578ca9908fb56d818605e2ad1670958d69c9f47a5b1d692227d156f34fa4ed1f22caf26f0ef07a5838bbe98ba9190d3bae21ba79d4b779101562107
|
7
|
+
data.tar.gz: 719ec839fe7f02751cf4ea178e33daac0a9502c43ec3bac543c5f7f319e756decb8e0ab05b08fb2cc79a4bed2bb1d3938ac15476eecd3b1414114a96ecb1f811
|
data/lib/http_stub.rb
CHANGED
@@ -12,12 +12,6 @@ require 'active_support/core_ext/module/delegation'
|
|
12
12
|
require 'active_support/core_ext/hash/slice'
|
13
13
|
require 'active_support/core_ext/hash/deep_merge'
|
14
14
|
|
15
|
-
module HttpStub
|
16
|
-
|
17
|
-
BASE_DIR = ::File.expand_path("../..", __FILE__)
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
15
|
require_relative 'http_stub/extensions/core/hash'
|
22
16
|
require_relative 'http_stub/extensions/rack/handler'
|
23
17
|
require_relative 'http_stub/server/headers'
|
@@ -28,13 +28,11 @@ module HttpStub
|
|
28
28
|
|
29
29
|
def rollback_to(model)
|
30
30
|
starting_index = @models.index(model)
|
31
|
-
@models
|
32
|
-
@models = @models.slice(starting_index..-1)
|
31
|
+
@models = @models.slice(starting_index..-1) if starting_index
|
33
32
|
end
|
34
33
|
|
35
34
|
def clear(request)
|
36
35
|
request.logger.info "Clearing #{@model_name} registry"
|
37
|
-
@models.each(&:clear)
|
38
36
|
@models.clear
|
39
37
|
end
|
40
38
|
|
@@ -4,16 +4,10 @@ module HttpStub
|
|
4
4
|
|
5
5
|
class File < HttpStub::Server::StubResponse::Base
|
6
6
|
|
7
|
-
private
|
8
|
-
|
9
|
-
STORAGE_DIR = "#{HttpStub::BASE_DIR}/tmp/response_files".freeze
|
10
|
-
|
11
|
-
public
|
12
|
-
|
13
7
|
add_default_headers "content-type" => "application/octet-stream"
|
14
8
|
|
15
9
|
def initialize(args)
|
16
|
-
@file_path =
|
10
|
+
@file_path = args["body"][:tempfile].path
|
17
11
|
super(args.merge("body" => @file_path))
|
18
12
|
end
|
19
13
|
|
@@ -21,19 +15,8 @@ module HttpStub
|
|
21
15
|
server.send_file(@file_path, send_options)
|
22
16
|
end
|
23
17
|
|
24
|
-
def clear
|
25
|
-
FileUtils.rm_f(@file_path)
|
26
|
-
end
|
27
|
-
|
28
18
|
private
|
29
19
|
|
30
|
-
def store_file(upload)
|
31
|
-
FileUtils.mkdir_p(STORAGE_DIR)
|
32
|
-
"#{STORAGE_DIR}/#{upload[:filename]}".tap do |file_path|
|
33
|
-
::File.open(file_path, "w") { |file| file.write(upload[:tempfile].read) }
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
20
|
def send_options
|
38
21
|
{ status: @status, type: @headers["content-type"] }.tap do |options|
|
39
22
|
options[:last_modified] = @headers["last-modified"] if @headers["last-modified"]
|
data/lib/http_stub/version.rb
CHANGED
@@ -7,7 +7,7 @@ describe HttpStub::Server::Registry do
|
|
7
7
|
|
8
8
|
shared_context "register multiple models" do
|
9
9
|
|
10
|
-
let(:models) { (1..3).map { |i| double("HttpStub::Server::Model#{i}", :satisfies? => false
|
10
|
+
let(:models) { (1..3).map { |i| double("HttpStub::Server::Model#{i}", :satisfies? => false) } }
|
11
11
|
|
12
12
|
before(:example) { models.each { |model| registry.add(model, request) } }
|
13
13
|
|
@@ -136,6 +136,54 @@ describe HttpStub::Server::Registry do
|
|
136
136
|
|
137
137
|
end
|
138
138
|
|
139
|
+
describe "#rollback_to" do
|
140
|
+
|
141
|
+
subject { registry.rollback_to(model) }
|
142
|
+
|
143
|
+
context "when models have been added" do
|
144
|
+
|
145
|
+
include_context "register multiple models"
|
146
|
+
|
147
|
+
context "and the rollback is to one of those models" do
|
148
|
+
|
149
|
+
let(:model) { models[1] }
|
150
|
+
|
151
|
+
it "the models remaining are those added up to and including the provided model" do
|
152
|
+
subject
|
153
|
+
|
154
|
+
expect(registry.all).to eql(models[0, 2].reverse)
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
context "and the rollback is to a model that has not been added" do
|
160
|
+
|
161
|
+
let(:model) { double("HttpStub::Server::Model") }
|
162
|
+
|
163
|
+
it "does not remove any models" do
|
164
|
+
subject
|
165
|
+
|
166
|
+
expect(registry.all).to eql(models.reverse)
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
context "when no models have been added" do
|
174
|
+
|
175
|
+
let(:model) { double("HttpStub::Server::Model") }
|
176
|
+
|
177
|
+
it "does not effect the known models" do
|
178
|
+
subject
|
179
|
+
|
180
|
+
expect(registry.all).to be_empty
|
181
|
+
end
|
182
|
+
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
139
187
|
describe "#clear" do
|
140
188
|
|
141
189
|
subject { registry.clear(request) }
|
@@ -150,12 +198,6 @@ describe HttpStub::Server::Registry do
|
|
150
198
|
|
151
199
|
include_context "register multiple models"
|
152
200
|
|
153
|
-
it "clears each model" do
|
154
|
-
models.each { |model| expect(model).to receive(:clear) }
|
155
|
-
|
156
|
-
subject
|
157
|
-
end
|
158
|
-
|
159
201
|
it "releases all knowledge of the models" do
|
160
202
|
subject
|
161
203
|
|
@@ -101,16 +101,6 @@ describe HttpStub::Server::StubActivator do
|
|
101
101
|
|
102
102
|
end
|
103
103
|
|
104
|
-
describe "#clear" do
|
105
|
-
|
106
|
-
it "delegates to a HttpStub::Server::Stub constructed from the activator's arguments" do
|
107
|
-
expect(underlying_stub).to receive(:clear)
|
108
|
-
|
109
|
-
expect(stub_activator.clear)
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|
113
|
-
|
114
104
|
describe "#to_s" do
|
115
105
|
|
116
106
|
it "returns the string representation of the activation arguments" do
|
@@ -206,14 +206,6 @@ describe HttpStub::Server::StubResponse::Base do
|
|
206
206
|
|
207
207
|
end
|
208
208
|
|
209
|
-
describe "#clear" do
|
210
|
-
|
211
|
-
it "executes without error" do
|
212
|
-
expect { response.clear }.to_not raise_error
|
213
|
-
end
|
214
|
-
|
215
|
-
end
|
216
|
-
|
217
209
|
describe "#to_s" do
|
218
210
|
|
219
211
|
it "returns the string representation of the provided arguments" do
|
@@ -12,34 +12,20 @@ describe HttpStub::Server::StubResponse::File do
|
|
12
12
|
}
|
13
13
|
end
|
14
14
|
|
15
|
-
let(:expected_file_path) { "#{HttpStub::BASE_DIR}/tmp/response_files/#{file_name}" }
|
16
|
-
|
17
15
|
let(:response_file) { HttpStub::Server::StubResponse::File.new(args) }
|
18
16
|
|
19
|
-
after(:example) { FileUtils.rm_rf(expected_file_path) }
|
20
|
-
|
21
17
|
it "is a base response" do
|
22
18
|
expect(response_file).to be_a(HttpStub::Server::StubResponse::Base)
|
23
19
|
end
|
24
20
|
|
25
|
-
describe "constructor" do
|
26
|
-
|
27
|
-
it "stores the temporary file provided for subsequent use" do
|
28
|
-
response_file
|
29
|
-
|
30
|
-
expect(FileUtils.identical?(expected_file_path, temp_file_path)).to be(true)
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
21
|
describe "#serve_on" do
|
36
22
|
|
37
23
|
let(:server) { instance_double(Sinatra::Base) }
|
38
24
|
|
39
25
|
subject { response_file.serve_on(server) }
|
40
26
|
|
41
|
-
it "sends the file via the server" do
|
42
|
-
expect(server).to receive(:send_file).with(
|
27
|
+
it "sends the temp file via the server" do
|
28
|
+
expect(server).to receive(:send_file).with(temp_file_path, anything)
|
43
29
|
|
44
30
|
subject
|
45
31
|
end
|
@@ -127,14 +113,4 @@ describe HttpStub::Server::StubResponse::File do
|
|
127
113
|
|
128
114
|
end
|
129
115
|
|
130
|
-
describe "#clear" do
|
131
|
-
|
132
|
-
it "deletes the stored file" do
|
133
|
-
response_file.clear
|
134
|
-
|
135
|
-
expect(File.exist?(expected_file_path)).to be(false)
|
136
|
-
end
|
137
|
-
|
138
|
-
end
|
139
|
-
|
140
116
|
end
|
@@ -43,8 +43,8 @@ describe HttpStub::Server::Stub do
|
|
43
43
|
let(:stub_uri) { instance_double(HttpStub::Server::StubUri, match?: true) }
|
44
44
|
let(:stub_headers) { instance_double(HttpStub::Server::StubHeaders, match?: true) }
|
45
45
|
let(:stub_parameters) { instance_double(HttpStub::Server::StubParameters, match?: true) }
|
46
|
-
let(:stub_response) { instance_double(HttpStub::Server::StubResponse::Base
|
47
|
-
let(:stub_triggers) { instance_double(HttpStub::Server::StubTriggers
|
46
|
+
let(:stub_response) { instance_double(HttpStub::Server::StubResponse::Base) }
|
47
|
+
let(:stub_triggers) { instance_double(HttpStub::Server::StubTriggers) }
|
48
48
|
|
49
49
|
let(:the_stub) { HttpStub::Server::Stub.new(stub_args) }
|
50
50
|
|
@@ -186,24 +186,6 @@ describe HttpStub::Server::Stub do
|
|
186
186
|
|
187
187
|
end
|
188
188
|
|
189
|
-
describe "#clear" do
|
190
|
-
|
191
|
-
subject { the_stub.clear }
|
192
|
-
|
193
|
-
it "clears the stub response" do
|
194
|
-
expect(stub_response).to receive(:clear)
|
195
|
-
|
196
|
-
subject
|
197
|
-
end
|
198
|
-
|
199
|
-
it "clears the stub triggers" do
|
200
|
-
expect(stub_triggers).to receive(:clear)
|
201
|
-
|
202
|
-
subject
|
203
|
-
end
|
204
|
-
|
205
|
-
end
|
206
|
-
|
207
189
|
describe "#to_s" do
|
208
190
|
|
209
191
|
it "returns a string representation of the stub arguments" do
|
@@ -33,16 +33,6 @@ describe HttpStub::Server::StubTriggers do
|
|
33
33
|
|
34
34
|
end
|
35
35
|
|
36
|
-
describe "#clear" do
|
37
|
-
|
38
|
-
it "clears each stub" do
|
39
|
-
stubs_for_triggers.each { |stub| expect(stub).to receive(:clear) }
|
40
|
-
|
41
|
-
stub_triggers.clear
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
36
|
describe "#each" do
|
47
37
|
|
48
38
|
it "yields to the stubs for each trigger" do
|
data/spec/spec_helper.rb
CHANGED