http_stub 0.7.0 → 0.7.1
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.
- data/lib/http_stub.rb +6 -2
- data/lib/http_stub/configurer.rb +2 -2
- data/lib/http_stub/configurer/request/hash_with_regexpable_values.rb +22 -0
- data/lib/http_stub/configurer/request/regexpable_value.rb +18 -0
- data/lib/http_stub/configurer/request/stub.rb +26 -0
- data/lib/http_stub/configurer/request/stub_activator.rb +18 -0
- data/lib/http_stub/models/hash_with_regexpable_values.rb +20 -0
- data/lib/http_stub/models/regexpable_value.rb +22 -0
- data/lib/http_stub/models/stub_headers.rb +3 -3
- data/lib/http_stub/models/stub_parameters.rb +3 -3
- data/lib/http_stub/models/stub_uri.rb +3 -4
- data/lib/http_stub/version.rb +1 -1
- data/spec/lib/http_stub/configurer/request/hash_with_regexpable_values_spec.rb +35 -0
- data/spec/lib/http_stub/configurer/request/regexpable_value_spec.rb +55 -0
- data/spec/lib/http_stub/configurer/{stub_activator_request_spec.rb → request/stub_activator_spec.rb} +4 -4
- data/spec/lib/http_stub/configurer/request/stub_spec.rb +152 -0
- data/spec/lib/http_stub/configurer_integration_spec.rb +102 -26
- data/spec/lib/http_stub/models/hash_with_regexpable_values_spec.rb +149 -0
- data/spec/lib/http_stub/models/regexpable_value_spec.rb +69 -0
- data/spec/lib/http_stub/models/stub_headers_spec.rb +34 -86
- data/spec/lib/http_stub/models/stub_parameters_spec.rb +22 -11
- data/spec/lib/http_stub/models/stub_uri_spec.rb +16 -47
- data/spec/spec_helper.rb +1 -1
- metadata +21 -9
- data/lib/http_stub/configurer/stub_activator_request.rb +0 -16
- data/lib/http_stub/configurer/stub_request.rb +0 -24
- data/spec/lib/http_stub/configurer/stub_request_spec.rb +0 -129
@@ -4,28 +4,39 @@ describe HttpStub::Models::StubParameters do
|
|
4
4
|
let(:request) { double("HttpRequest", params: request_parameters) }
|
5
5
|
|
6
6
|
let(:stubbed_parameters) { { "key1" => "value1", "key2" => "value2", "key3" => "value3" } }
|
7
|
+
let(:regexpable_stubbed_paremeters) { double(HttpStub::Models::HashWithRegexpableValues).as_null_object }
|
8
|
+
|
7
9
|
let(:stub_parameters) { HttpStub::Models::StubParameters.new(stubbed_parameters) }
|
8
10
|
|
9
|
-
describe "
|
11
|
+
describe "when stubbed parameters are provided" do
|
12
|
+
|
13
|
+
it "should create a regexpable representation of the stubbed parameters" do
|
14
|
+
HttpStub::Models::HashWithRegexpableValues.should_receive(:new).with(stubbed_parameters)
|
10
15
|
|
11
|
-
|
16
|
+
stub_parameters
|
17
|
+
end
|
12
18
|
|
13
|
-
|
19
|
+
end
|
14
20
|
|
15
|
-
|
16
|
-
stub_parameters.match?(request).should be(true)
|
17
|
-
end
|
21
|
+
describe "when the stubbed parameters are nil" do
|
18
22
|
|
23
|
+
let(:stubbed_parameters) { nil }
|
24
|
+
|
25
|
+
it "should create a regexpable representation of an empty hash" do
|
26
|
+
HttpStub::Models::HashWithRegexpableValues.should_receive(:new).with({})
|
27
|
+
|
28
|
+
stub_parameters
|
19
29
|
end
|
20
30
|
|
21
|
-
|
31
|
+
end
|
22
32
|
|
23
|
-
|
33
|
+
describe "#match?" do
|
24
34
|
|
25
|
-
|
26
|
-
|
27
|
-
|
35
|
+
it "should delegate to the regexpable representation of the stubbed parameters to determine a match" do
|
36
|
+
HttpStub::Models::HashWithRegexpableValues.stub!(:new).and_return(regexpable_stubbed_paremeters)
|
37
|
+
regexpable_stubbed_paremeters.should_receive(:match?).with(request_parameters).and_return(true)
|
28
38
|
|
39
|
+
stub_parameters.match?(request).should be(true)
|
29
40
|
end
|
30
41
|
|
31
42
|
end
|
@@ -1,71 +1,40 @@
|
|
1
1
|
describe HttpStub::Models::StubUri do
|
2
2
|
|
3
|
+
let(:stubbed_uri) { "/some/uri" }
|
3
4
|
let(:request) { double("HttpRequest", path_info: request_uri) }
|
4
|
-
|
5
|
+
let(:regexpable_value) { double(HttpStub::Models::RegexpableValue).as_null_object }
|
5
6
|
let(:stub_uri) { HttpStub::Models::StubUri.new(stubbed_uri) }
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
describe "when the uri provided has no 'regexp' prefix" do
|
10
|
-
|
11
|
-
let(:stubbed_uri) { "/some/uri" }
|
12
|
-
|
13
|
-
describe "and the request uri is equal" do
|
14
|
-
|
15
|
-
let(:request_uri) { "/some/uri" }
|
16
|
-
|
17
|
-
it "should return true" do
|
18
|
-
stub_uri.match?(request).should be_true
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "and the request uri is not equal" do
|
8
|
+
before(:each) { HttpStub::Models::RegexpableValue.stub!(:new).and_return(regexpable_value) }
|
24
9
|
|
25
|
-
|
10
|
+
describe "constructor" do
|
26
11
|
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
12
|
+
it "should create a regexpable representation of the provided uri" do
|
13
|
+
HttpStub::Models::RegexpableValue.should_receive(:new).with(stubbed_uri)
|
32
14
|
|
15
|
+
stub_uri
|
33
16
|
end
|
34
17
|
|
35
|
-
|
36
|
-
|
37
|
-
let(:stubbed_uri) { "regexp:/some/regexp/uri/.+" }
|
38
|
-
|
39
|
-
describe "and the request uri matches the regular expression" do
|
40
|
-
|
41
|
-
let(:request_uri) { "/some/regexp/uri/match" }
|
42
|
-
|
43
|
-
it "should return true" do
|
44
|
-
stub_uri.match?(request).should be_true
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
describe "and the request uri does not match the regular expression" do
|
18
|
+
end
|
50
19
|
|
51
|
-
|
20
|
+
describe "#match?" do
|
52
21
|
|
53
|
-
|
54
|
-
stub_uri.match?(request).should be_false
|
55
|
-
end
|
22
|
+
let(:request_uri) { "/some/uri" }
|
56
23
|
|
57
|
-
|
24
|
+
it "should delegate to the regexpable representation of the provided uri" do
|
25
|
+
regexpable_value.should_receive(:match?).with(request_uri).and_return(true)
|
58
26
|
|
27
|
+
stub_uri.match?(request).should be_true
|
59
28
|
end
|
60
29
|
|
61
30
|
end
|
62
31
|
|
63
32
|
describe "#to_s" do
|
64
33
|
|
65
|
-
|
34
|
+
it "should delegate to the regexpable representation of the provided uri" do
|
35
|
+
regexpable_value.should_receive(:to_s).and_return("some regexpable value string")
|
66
36
|
|
67
|
-
|
68
|
-
stub_uri.to_s.should eql(stubbed_uri)
|
37
|
+
stub_uri.to_s.should eql("some regexpable value string")
|
69
38
|
end
|
70
39
|
|
71
40
|
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.7.
|
4
|
+
version: 0.7.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-04-
|
13
|
+
date: 2013-04-18 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: sinatra
|
@@ -213,12 +213,16 @@ files:
|
|
213
213
|
- ./lib/http_stub/configurer/command.rb
|
214
214
|
- ./lib/http_stub/configurer/impatient_command_chain.rb
|
215
215
|
- ./lib/http_stub/configurer/patient_command_chain.rb
|
216
|
-
- ./lib/http_stub/configurer/
|
217
|
-
- ./lib/http_stub/configurer/
|
216
|
+
- ./lib/http_stub/configurer/request/hash_with_regexpable_values.rb
|
217
|
+
- ./lib/http_stub/configurer/request/regexpable_value.rb
|
218
|
+
- ./lib/http_stub/configurer/request/stub.rb
|
219
|
+
- ./lib/http_stub/configurer/request/stub_activator.rb
|
218
220
|
- ./lib/http_stub/configurer.rb
|
219
221
|
- ./lib/http_stub/controllers/stub_activator_controller.rb
|
220
222
|
- ./lib/http_stub/controllers/stub_controller.rb
|
221
223
|
- ./lib/http_stub/hash_extensions.rb
|
224
|
+
- ./lib/http_stub/models/hash_with_regexpable_values.rb
|
225
|
+
- ./lib/http_stub/models/regexpable_value.rb
|
222
226
|
- ./lib/http_stub/models/registry.rb
|
223
227
|
- ./lib/http_stub/models/request_header_parser.rb
|
224
228
|
- ./lib/http_stub/models/response.rb
|
@@ -242,12 +246,16 @@ files:
|
|
242
246
|
- ./spec/lib/http_stub/configurer/command_spec.rb
|
243
247
|
- ./spec/lib/http_stub/configurer/impatient_command_chain_spec.rb
|
244
248
|
- ./spec/lib/http_stub/configurer/patient_command_chain_spec.rb
|
245
|
-
- ./spec/lib/http_stub/configurer/
|
246
|
-
- ./spec/lib/http_stub/configurer/
|
249
|
+
- ./spec/lib/http_stub/configurer/request/hash_with_regexpable_values_spec.rb
|
250
|
+
- ./spec/lib/http_stub/configurer/request/regexpable_value_spec.rb
|
251
|
+
- ./spec/lib/http_stub/configurer/request/stub_activator_spec.rb
|
252
|
+
- ./spec/lib/http_stub/configurer/request/stub_spec.rb
|
247
253
|
- ./spec/lib/http_stub/configurer_integration_spec.rb
|
248
254
|
- ./spec/lib/http_stub/controllers/stub_activator_controller_spec.rb
|
249
255
|
- ./spec/lib/http_stub/controllers/stub_controller_spec.rb
|
250
256
|
- ./spec/lib/http_stub/hash_extensions_spec.rb
|
257
|
+
- ./spec/lib/http_stub/models/hash_with_regexpable_values_spec.rb
|
258
|
+
- ./spec/lib/http_stub/models/regexpable_value_spec.rb
|
251
259
|
- ./spec/lib/http_stub/models/registry_spec.rb
|
252
260
|
- ./spec/lib/http_stub/models/request_header_parser_spec.rb
|
253
261
|
- ./spec/lib/http_stub/models/response_spec.rb
|
@@ -282,7 +290,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
282
290
|
version: '0'
|
283
291
|
segments:
|
284
292
|
- 0
|
285
|
-
hash:
|
293
|
+
hash: -1139132984430576269
|
286
294
|
requirements: []
|
287
295
|
rubyforge_project: http_stub
|
288
296
|
rubygems_version: 1.8.25
|
@@ -295,12 +303,16 @@ test_files:
|
|
295
303
|
- ./spec/lib/http_stub/configurer/command_spec.rb
|
296
304
|
- ./spec/lib/http_stub/configurer/impatient_command_chain_spec.rb
|
297
305
|
- ./spec/lib/http_stub/configurer/patient_command_chain_spec.rb
|
298
|
-
- ./spec/lib/http_stub/configurer/
|
299
|
-
- ./spec/lib/http_stub/configurer/
|
306
|
+
- ./spec/lib/http_stub/configurer/request/hash_with_regexpable_values_spec.rb
|
307
|
+
- ./spec/lib/http_stub/configurer/request/regexpable_value_spec.rb
|
308
|
+
- ./spec/lib/http_stub/configurer/request/stub_activator_spec.rb
|
309
|
+
- ./spec/lib/http_stub/configurer/request/stub_spec.rb
|
300
310
|
- ./spec/lib/http_stub/configurer_integration_spec.rb
|
301
311
|
- ./spec/lib/http_stub/controllers/stub_activator_controller_spec.rb
|
302
312
|
- ./spec/lib/http_stub/controllers/stub_controller_spec.rb
|
303
313
|
- ./spec/lib/http_stub/hash_extensions_spec.rb
|
314
|
+
- ./spec/lib/http_stub/models/hash_with_regexpable_values_spec.rb
|
315
|
+
- ./spec/lib/http_stub/models/regexpable_value_spec.rb
|
304
316
|
- ./spec/lib/http_stub/models/registry_spec.rb
|
305
317
|
- ./spec/lib/http_stub/models/request_header_parser_spec.rb
|
306
318
|
- ./spec/lib/http_stub/models/response_spec.rb
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module HttpStub
|
2
|
-
module Configurer
|
3
|
-
|
4
|
-
class StubActivatorRequest < Net::HTTP::Post
|
5
|
-
|
6
|
-
def initialize(activation_uri, stub_uri, options)
|
7
|
-
super("/stubs/activators")
|
8
|
-
stub_request = HttpStub::Configurer::StubRequest.new(stub_uri, options)
|
9
|
-
self.content_type = stub_request.content_type
|
10
|
-
self.body = JSON.parse(stub_request.body).merge({ "activation_uri" => activation_uri }).to_json
|
11
|
-
end
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
16
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module HttpStub
|
2
|
-
module Configurer
|
3
|
-
|
4
|
-
class StubRequest < Net::HTTP::Post
|
5
|
-
|
6
|
-
def initialize(uri, options)
|
7
|
-
super("/stubs")
|
8
|
-
self.content_type = "application/json"
|
9
|
-
self.body = {
|
10
|
-
"uri" => uri.is_a?(Regexp) ? "regexp:#{uri.source.gsub(/\\/, "")}" : uri,
|
11
|
-
"method" => options[:method],
|
12
|
-
"headers" => options[:headers] || {},
|
13
|
-
"parameters" => options[:parameters] || {},
|
14
|
-
"response" => {
|
15
|
-
"status" => options[:response][:status] || 200,
|
16
|
-
"body" => options[:response][:body]
|
17
|
-
}
|
18
|
-
}.to_json
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
end
|
@@ -1,129 +0,0 @@
|
|
1
|
-
describe HttpStub::Configurer::StubRequest do
|
2
|
-
|
3
|
-
describe "#initialize" do
|
4
|
-
|
5
|
-
describe "when provided a uri and stub options" do
|
6
|
-
|
7
|
-
let(:uri) { "/some/uri" }
|
8
|
-
let(:stub_method) { "Some Method" }
|
9
|
-
let(:headers) { { "header_name" => "value" } }
|
10
|
-
let(:parameters) { { "parameter_name" => "value" } }
|
11
|
-
let(:response_status) { 500 }
|
12
|
-
let(:response_body) { "Some body" }
|
13
|
-
|
14
|
-
let(:stub_options) do
|
15
|
-
{
|
16
|
-
method: stub_method,
|
17
|
-
headers: headers,
|
18
|
-
parameters: parameters,
|
19
|
-
response: {
|
20
|
-
status: response_status,
|
21
|
-
body: response_body
|
22
|
-
}
|
23
|
-
}
|
24
|
-
end
|
25
|
-
|
26
|
-
let(:request) { HttpStub::Configurer::StubRequest.new(uri, stub_options) }
|
27
|
-
let(:request_body) { JSON.parse(request.body) }
|
28
|
-
|
29
|
-
it "should create a HTTP POST request" do
|
30
|
-
request.method.should eql("POST")
|
31
|
-
end
|
32
|
-
|
33
|
-
it "should submit the request to '/stubs'" do
|
34
|
-
request.path.should eql("/stubs")
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should set the content type to json" do
|
38
|
-
request.content_type.should eql("application/json")
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "generates a JSON body which" do
|
42
|
-
|
43
|
-
describe "when the uri is a string" do
|
44
|
-
|
45
|
-
it "should have an entry containing the provided URI unaltered" do
|
46
|
-
request_body.should include({ "uri" => uri })
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
|
51
|
-
describe "when the uri is a regular expression" do
|
52
|
-
|
53
|
-
let(:uri) { /\/some\/uri/ }
|
54
|
-
|
55
|
-
it "should have an entry containing the provided URI converted to a string and prefixed with 'regexp:'" do
|
56
|
-
request_body.should include({ "uri" => "regexp:/some/uri" })
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should have an entry for the method option" do
|
62
|
-
request_body.should include({ "method" => stub_method })
|
63
|
-
end
|
64
|
-
|
65
|
-
describe "when a header option is provided" do
|
66
|
-
|
67
|
-
it "should have an entry for the option" do
|
68
|
-
request_body.should include({ "headers" => headers })
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
|
73
|
-
describe "when no header is provided" do
|
74
|
-
|
75
|
-
let(:headers) { nil }
|
76
|
-
|
77
|
-
it "should have an empty header entry" do
|
78
|
-
request_body.should include({ "headers" => {} })
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
82
|
-
|
83
|
-
describe "when a parameter option is provided" do
|
84
|
-
|
85
|
-
it "should have an entry for the option" do
|
86
|
-
request_body.should include({ "parameters" => parameters })
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
90
|
-
|
91
|
-
describe "when no parameter option is provided" do
|
92
|
-
|
93
|
-
let(:parameters) { nil }
|
94
|
-
|
95
|
-
it "should have an empty header entry" do
|
96
|
-
request_body.should include({ "parameters" => {} })
|
97
|
-
end
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
|
-
describe "when a status response option is provided" do
|
102
|
-
|
103
|
-
it "should have a response entry for the option" do
|
104
|
-
request_body["response"].should include({ "status" => response_status })
|
105
|
-
end
|
106
|
-
|
107
|
-
end
|
108
|
-
|
109
|
-
describe "when no status response option is provided" do
|
110
|
-
|
111
|
-
let(:response_status) { nil }
|
112
|
-
|
113
|
-
it "should have a response entry with status code of 200" do
|
114
|
-
request_body["response"].should include({ "status" => 200 })
|
115
|
-
end
|
116
|
-
|
117
|
-
end
|
118
|
-
|
119
|
-
it "should have an entry for the response body option" do
|
120
|
-
request_body["response"].should include({ "body" => response_body })
|
121
|
-
end
|
122
|
-
|
123
|
-
end
|
124
|
-
|
125
|
-
end
|
126
|
-
|
127
|
-
end
|
128
|
-
|
129
|
-
end
|