http_stub 0.15.4 → 0.15.5
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 +2 -1
- data/lib/http_stub/server/stub_response/base.rb +4 -0
- data/lib/http_stub/server/stub_response/file.rb +4 -1
- data/lib/http_stub/server/views/_stub.haml +1 -2
- data/lib/http_stub/server/views/_stub_file_response.haml +1 -0
- data/lib/http_stub/server/views/_stub_text_response.haml +1 -0
- data/lib/http_stub/server/views/stub_activators.haml +1 -1
- data/lib/http_stub/version.rb +1 -1
- data/spec/lib/http_stub/configurer_integration_spec.rb +5 -5
- data/spec/lib/http_stub/server/application_integration_spec.rb +23 -18
- data/spec/lib/http_stub/server/stub_response/base_spec.rb +13 -0
- data/spec/lib/http_stub/server/stub_response/file_spec.rb +14 -0
- data/spec/spec_helper.rb +2 -2
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de9073e7cd507e925511a4e9e4ab51c7182cb44c
|
4
|
+
data.tar.gz: 0922450c8acc9793b0472877dfd2f603008588cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3722e4850fd58d0c2f104896e7f8b3662a39f596762ab78e35cebe8bdebe0266d956e94045f57ba1a659d6d4e89a9c163f8ca211da3e25064c5a85af86aad778
|
7
|
+
data.tar.gz: c9b22acf23548d508c60f5c00bec96b758cfbf2efee142d5e8fa43a3039095403f6b96f113e2703350c7a7949afe9a668a2ec8193f3716b36d33eb496d807aef
|
data/lib/http_stub.rb
CHANGED
@@ -2,13 +2,14 @@ require 'sinatra'
|
|
2
2
|
require 'sinatra/partial'
|
3
3
|
require 'haml'
|
4
4
|
require 'sass'
|
5
|
+
require 'json'
|
5
6
|
require 'net/http'
|
6
7
|
require 'net/http/post/multipart'
|
7
|
-
require 'json'
|
8
8
|
require 'http_server_manager'
|
9
9
|
|
10
10
|
require 'active_support/core_ext/module/aliasing'
|
11
11
|
require 'active_support/core_ext/module/delegation'
|
12
|
+
require 'active_support/core_ext/string/inflections'
|
12
13
|
require 'active_support/core_ext/hash/slice'
|
13
14
|
require 'active_support/core_ext/hash/deep_merge'
|
14
15
|
require 'active_support/core_ext/hash/indifferent_access'
|
@@ -6,9 +6,12 @@ module HttpStub
|
|
6
6
|
|
7
7
|
add_default_headers "content-type" => "application/octet-stream"
|
8
8
|
|
9
|
+
attr_reader :uri
|
10
|
+
|
9
11
|
def initialize(args)
|
10
12
|
@file = args["body"][:tempfile]
|
11
|
-
|
13
|
+
@uri = "file://#{@file.path}"
|
14
|
+
super(args.merge("body" => ""))
|
12
15
|
end
|
13
16
|
|
14
17
|
def serve_on(server)
|
@@ -19,7 +19,7 @@
|
|
19
19
|
%td=h(the_stub.response.headers)
|
20
20
|
%tr
|
21
21
|
%td Response Body:
|
22
|
-
%td=
|
22
|
+
%td=partial "stub_#{the_stub.response.type}_response".to_sym, locals: { response: the_stub.response }
|
23
23
|
%tr
|
24
24
|
%td Response Delay:
|
25
25
|
%td=h(the_stub.response.delay_in_seconds)
|
@@ -29,4 +29,3 @@
|
|
29
29
|
- the_stub.triggers.each do |trigger|
|
30
30
|
= partial :stub, locals: { the_stub: trigger }
|
31
31
|
%br
|
32
|
-
|
@@ -0,0 +1 @@
|
|
1
|
+
%a{ href: response.uri, class: :file }= response.uri
|
@@ -0,0 +1 @@
|
|
1
|
+
=h(response.body)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
- stub_activators.each do |stub_activator|
|
2
2
|
%div
|
3
3
|
%span Response Activation URI:
|
4
|
-
%a{ href: stub_activator.activation_uri }= stub_activator.activation_uri
|
4
|
+
%a{ href: stub_activator.activation_uri, class: :activator }= stub_activator.activation_uri
|
5
5
|
= partial :stub, locals: { the_stub: stub_activator.the_stub }
|
6
6
|
%br
|
data/lib/http_stub/version.rb
CHANGED
@@ -38,7 +38,7 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
38
38
|
|
39
39
|
context "and the response contains a file" do
|
40
40
|
|
41
|
-
let(:configurer) { HttpStub::Examples::
|
41
|
+
let(:configurer) { HttpStub::Examples::ConfigurerWithFileResponses.new }
|
42
42
|
|
43
43
|
before(:example) { configurer.activate!("/a_file_activator") }
|
44
44
|
|
@@ -48,7 +48,7 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
48
48
|
|
49
49
|
it "replays the stubbed response" do
|
50
50
|
expect(response.code).to eql(200)
|
51
|
-
expect_response_to_contain_file(HttpStub::Examples::
|
51
|
+
expect_response_to_contain_file(HttpStub::Examples::ConfigurerWithFileResponses::FILE_PATH)
|
52
52
|
end
|
53
53
|
|
54
54
|
end
|
@@ -667,7 +667,7 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
667
667
|
|
668
668
|
context "and the configurer stubs responses with a file body" do
|
669
669
|
|
670
|
-
let(:configurer) { HttpStub::Examples::
|
670
|
+
let(:configurer) { HttpStub::Examples::ConfigurerWithFileResponses.new }
|
671
671
|
|
672
672
|
context "and a request that matches is made" do
|
673
673
|
|
@@ -684,7 +684,7 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
684
684
|
end
|
685
685
|
|
686
686
|
it "responds with the configured file" do
|
687
|
-
expect_response_to_contain_file(HttpStub::Examples::
|
687
|
+
expect_response_to_contain_file(HttpStub::Examples::ConfigurerWithFileResponses::FILE_PATH)
|
688
688
|
end
|
689
689
|
|
690
690
|
end
|
@@ -698,7 +698,7 @@ describe HttpStub::Configurer, "when the server is running" do
|
|
698
698
|
end
|
699
699
|
|
700
700
|
it "responds with the configured response" do
|
701
|
-
expect_response_to_contain_file(HttpStub::Examples::
|
701
|
+
expect_response_to_contain_file(HttpStub::Examples::ConfigurerWithFileResponses::FILE_PATH)
|
702
702
|
end
|
703
703
|
|
704
704
|
end
|
@@ -2,24 +2,26 @@ describe HttpStub::Server::Application, "when the server is running" do
|
|
2
2
|
include Rack::Utils
|
3
3
|
include_context "server integration"
|
4
4
|
|
5
|
-
let(:
|
5
|
+
let(:response_document) { Nokogiri::HTML(response.body) }
|
6
6
|
|
7
|
-
describe "POST
|
7
|
+
describe "POST /stubs" do
|
8
8
|
|
9
9
|
context "when provided with the minimum data required" do
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
let(:response) do
|
12
|
+
HTTParty.post(
|
13
13
|
"#{server_uri}/stubs",
|
14
14
|
body: { uri: "/some/path", method: "get", response: { status: 200, body: "Some body" } }.to_json
|
15
15
|
)
|
16
16
|
end
|
17
17
|
|
18
18
|
it "returns a 200 response code" do
|
19
|
-
expect(
|
19
|
+
expect(response.code).to eql(200)
|
20
20
|
end
|
21
21
|
|
22
22
|
it "registers a stub returning the provided response for a matching request" do
|
23
|
+
response
|
24
|
+
|
23
25
|
stubbed_response = HTTParty.get("#{server_uri}/some/path")
|
24
26
|
|
25
27
|
expect(stubbed_response.code).to eql(200)
|
@@ -33,7 +35,7 @@ describe HttpStub::Server::Application, "when the server is running" do
|
|
33
35
|
describe "and a configurer with multiple stub activators is initialized" do
|
34
36
|
|
35
37
|
before(:context) do
|
36
|
-
configurer = HttpStub::Examples::
|
38
|
+
configurer = HttpStub::Examples::ConfigurerWithClassActivators
|
37
39
|
configurer.host(server_host)
|
38
40
|
configurer.port(server_port)
|
39
41
|
configurer.initialize!
|
@@ -121,12 +123,19 @@ describe HttpStub::Server::Application, "when the server is running" do
|
|
121
123
|
end
|
122
124
|
end
|
123
125
|
|
124
|
-
it "returns a response whose body contains the response body of
|
125
|
-
expect(response.body).to match(/Plain text body/)
|
126
|
+
it "returns a response whose body contains the response body of stub returning JSON" do
|
126
127
|
expect(response.body).to match(/#{escape_html({ "key" => "JSON body" }.to_json)}/)
|
128
|
+
end
|
129
|
+
|
130
|
+
it "returns a response whose body contains the response body of stub returning HTML" do
|
127
131
|
expect(response.body).to match(/#{escape_html("<html><body>HTML body</body></html>")}/)
|
128
132
|
end
|
129
133
|
|
134
|
+
it "returns a response whose body contains the response body of a stub returning a file" do
|
135
|
+
file_link = response_document.css("a.file").first
|
136
|
+
expect(file_link['href']).to match(/^file:\/\/[^']+\.pdf$/)
|
137
|
+
end
|
138
|
+
|
130
139
|
it "returns a response whose body contains the response body of each stub trigger" do
|
131
140
|
(1..3).each do |stub_number|
|
132
141
|
(1..3).each do |trigger_number|
|
@@ -149,13 +158,12 @@ describe HttpStub::Server::Application, "when the server is running" do
|
|
149
158
|
|
150
159
|
end
|
151
160
|
|
152
|
-
describe "GET
|
161
|
+
describe "GET /stubs/activators" do
|
153
162
|
|
154
|
-
let(:response)
|
155
|
-
let(:response_document) { Nokogiri::HTML(response.body) }
|
163
|
+
let(:response) { HTTParty.get("#{server_uri}/stubs/activators") }
|
156
164
|
|
157
165
|
it "returns response whose body contains links to each activator in alphabetical order" do
|
158
|
-
response_document.css("a").each_with_index do |link, i|
|
166
|
+
response_document.css("a.activator").each_with_index do |link, i|
|
159
167
|
expect(link['href']).to eql("/activator_#{i + 1}")
|
160
168
|
end
|
161
169
|
end
|
@@ -164,16 +172,13 @@ describe HttpStub::Server::Application, "when the server is running" do
|
|
164
172
|
|
165
173
|
end
|
166
174
|
|
167
|
-
describe "GET
|
175
|
+
describe "GET /stubs" do
|
168
176
|
|
169
177
|
describe "when multiple stubs are configured" do
|
170
178
|
|
171
|
-
before(:context)
|
172
|
-
(1..3).each { |i| HTTParty.get("#{server_uri}/activator_#{i}") }
|
173
|
-
end
|
179
|
+
before(:context) { (1..3).each { |i| HTTParty.get("#{server_uri}/activator_#{i}") } }
|
174
180
|
|
175
|
-
let(:response)
|
176
|
-
let(:response_document) { Nokogiri::HTML(response.body) }
|
181
|
+
let(:response) { HTTParty.get("#{server_uri}/stubs") }
|
177
182
|
|
178
183
|
include_context "the response contains HTML describing the configurers stubs"
|
179
184
|
|
@@ -184,6 +184,19 @@ describe HttpStub::Server::StubResponse::Base do
|
|
184
184
|
|
185
185
|
end
|
186
186
|
|
187
|
+
describe "#type" do
|
188
|
+
|
189
|
+
class HttpStub::Server::StubResponse::TestableBaseClass < HttpStub::Server::StubResponse::Base
|
190
|
+
end
|
191
|
+
|
192
|
+
let(:testable_response_class) { HttpStub::Server::StubResponse::TestableBaseClass }
|
193
|
+
|
194
|
+
it "returns the name of the concrete base instance underscored" do
|
195
|
+
expect(response.type).to eql("testable_base_class")
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
|
187
200
|
describe "#empty?" do
|
188
201
|
|
189
202
|
context "when the response is EMPTY" do
|
@@ -18,6 +18,20 @@ describe HttpStub::Server::StubResponse::File do
|
|
18
18
|
expect(response_file).to be_a(HttpStub::Server::StubResponse::Base)
|
19
19
|
end
|
20
20
|
|
21
|
+
describe "#uri" do
|
22
|
+
|
23
|
+
subject { response_file.uri }
|
24
|
+
|
25
|
+
it "is prefixed with 'file://' to support display within a hyperlink" do
|
26
|
+
expect(subject).to start_with("file://")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "concludes with the path to the temp file provided" do
|
30
|
+
expect(subject).to end_with(temp_file_path)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
21
35
|
describe "#serve_on" do
|
22
36
|
|
23
37
|
let(:server) { instance_double(Sinatra::Base) }
|
data/spec/spec_helper.rb
CHANGED
@@ -16,12 +16,12 @@ require 'http_server_manager/test_support'
|
|
16
16
|
require_relative '../lib/http_stub/rake/task_generators'
|
17
17
|
require_relative '../lib/http_stub'
|
18
18
|
require_relative '../examples/configurer_with_class_activator'
|
19
|
-
require_relative '../examples/
|
19
|
+
require_relative '../examples/configurer_with_class_activators'
|
20
20
|
require_relative '../examples/configurer_with_class_stub'
|
21
21
|
require_relative '../examples/configurer_with_initialize_callback'
|
22
22
|
require_relative '../examples/configurer_with_complex_initializer'
|
23
23
|
require_relative '../examples/configurer_with_response_defaults'
|
24
|
-
require_relative '../examples/
|
24
|
+
require_relative '../examples/configurer_with_file_responses'
|
25
25
|
|
26
26
|
HttpStub::Server::Daemon.log_dir = ::File.expand_path('../../tmp/log', __FILE__)
|
27
27
|
HttpStub::Server::Daemon.pid_dir = ::File.expand_path('../../tmp/pids', __FILE__)
|
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.15.
|
4
|
+
version: 0.15.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Ueckerman
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-05-
|
12
|
+
date: 2015-05-27 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -309,6 +309,8 @@ files:
|
|
309
309
|
- "./lib/http_stub/server/stub_triggers.rb"
|
310
310
|
- "./lib/http_stub/server/stub_uri.rb"
|
311
311
|
- "./lib/http_stub/server/views/_stub.haml"
|
312
|
+
- "./lib/http_stub/server/views/_stub_file_response.haml"
|
313
|
+
- "./lib/http_stub/server/views/_stub_text_response.haml"
|
312
314
|
- "./lib/http_stub/server/views/application.sass"
|
313
315
|
- "./lib/http_stub/server/views/layout.haml"
|
314
316
|
- "./lib/http_stub/server/views/stub_activators.haml"
|