http_stub 0.9.6 → 0.9.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/http_stub/configurer/request/controllable_value.rb +21 -0
- data/lib/http_stub/configurer/request/omittable.rb +18 -0
- data/lib/http_stub/configurer/request/regexpable.rb +2 -7
- data/lib/http_stub/configurer/request/stub.rb +3 -3
- data/lib/http_stub/models/exact_value_matcher.rb +13 -0
- data/lib/http_stub/models/hash_with_value_matchers.rb +20 -0
- data/lib/http_stub/models/omitted_value_matcher.rb +19 -0
- data/lib/http_stub/models/regexp_value_matcher.rb +14 -0
- data/lib/http_stub/models/stub_headers.rb +1 -1
- data/lib/http_stub/models/stub_parameters.rb +1 -1
- data/lib/http_stub/models/stub_uri.rb +1 -1
- data/lib/http_stub/models/value_matcher.rb +29 -0
- data/lib/http_stub/version.rb +1 -1
- data/lib/http_stub.rb +7 -2
- data/spec/lib/http_stub/configurer/request/controllable_value_spec.rb +34 -0
- data/spec/lib/http_stub/configurer/request/omittable_spec.rb +70 -0
- data/spec/lib/http_stub/configurer/request/stub_spec.rb +11 -11
- data/spec/lib/http_stub/configurer_integration_spec.rb +51 -9
- data/spec/lib/http_stub/models/exact_value_matcher_spec.rb +33 -0
- data/spec/lib/http_stub/models/hash_with_value_matchers_spec.rb +156 -0
- data/spec/lib/http_stub/models/omitted_value_matcher_spec.rb +58 -0
- data/spec/lib/http_stub/models/regexp_value_matcher_spec.rb +48 -0
- data/spec/lib/http_stub/models/stub_headers_spec.rb +4 -4
- data/spec/lib/http_stub/models/stub_parameters_spec.rb +4 -4
- data/spec/lib/http_stub/models/stub_uri_spec.rb +9 -9
- data/spec/lib/http_stub/models/value_matcher_spec.rb +81 -0
- data/spec/lib/http_stub/server_integration_spec.rb +33 -7
- data/spec/lib/http_stub/server_spec.rb +13 -16
- data/spec/spec_helper.rb +1 -1
- metadata +36 -21
- data/lib/http_stub/models/hash_with_regexpable_values.rb +0 -20
- data/lib/http_stub/models/regexpable_value.rb +0 -22
- data/spec/lib/http_stub/models/hash_with_regexpable_values_spec.rb +0 -149
- data/spec/lib/http_stub/models/regexpable_value_spec.rb +0 -69
@@ -0,0 +1,156 @@
|
|
1
|
+
describe HttpStub::Models::HashWithValueMatchers do
|
2
|
+
|
3
|
+
let(:stubbed_hash) do
|
4
|
+
(1..3).reduce({}) do |result, i|
|
5
|
+
result["key#{i}"] = "value#{i}"
|
6
|
+
result
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:value_matchers) do
|
11
|
+
stubbed_hash.values.map { |value| double(HttpStub::Models::ValueMatcher, to_s: value).as_null_object }
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:value_matcher_hash) { HttpStub::Models::HashWithValueMatchers.new(stubbed_hash) }
|
15
|
+
|
16
|
+
before(:each) do
|
17
|
+
value_matchers.each { |value| HttpStub::Models::ValueMatcher.stub(:new).with(value.to_s).and_return(value) }
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should be hash" do
|
21
|
+
value_matcher_hash.should be_a(Hash)
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "constructor" do
|
25
|
+
|
26
|
+
it "should create a value matcher representation of each value in the hash" do
|
27
|
+
value_matchers.each do |value|
|
28
|
+
HttpStub::Models::ValueMatcher.should_receive(:new).with(value.to_s).and_return(value)
|
29
|
+
end
|
30
|
+
|
31
|
+
value_matcher_hash.values.should eql(value_matchers)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#match?" do
|
37
|
+
|
38
|
+
context "when the stubbed hash contains multiple entries" do
|
39
|
+
|
40
|
+
context "and the provided hash has the same number of entries" do
|
41
|
+
|
42
|
+
context "and the keys match" do
|
43
|
+
|
44
|
+
let(:provided_hash) do
|
45
|
+
stubbed_hash.reduce({}) do |result, entry|
|
46
|
+
result[entry[0]] = "another #{entry[1]}"
|
47
|
+
result
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "and the values match" do
|
52
|
+
|
53
|
+
before(:each) do
|
54
|
+
value_matchers.each { |value| value.stub(:match?).with("another #{value}").and_return(true) }
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should return true" do
|
58
|
+
value_matcher_hash.match?(provided_hash).should be_true
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
context "and a value does not match" do
|
64
|
+
|
65
|
+
before(:each) do
|
66
|
+
value_matchers.each { |value| value.stub(:match?).with("another #{value}").and_return(true) }
|
67
|
+
|
68
|
+
non_matching_value = value_matchers[1]
|
69
|
+
non_matching_value.stub(:match?).with("another #{non_matching_value}").and_return(false)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "should return false" do
|
73
|
+
value_matcher_hash.match?(provided_hash).should be_false
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
context "and a key does not match" do
|
81
|
+
|
82
|
+
let(:provided_hash) { { "key1" => "value1", "differentkey2" => "another value2", "key3" => "value3" } }
|
83
|
+
|
84
|
+
it "should determine if the corresponding value matches nil" do
|
85
|
+
expected_values = [ "value1", nil, "value3" ]
|
86
|
+
value_matchers.zip(expected_values).each do |value_matcher, expected_value|
|
87
|
+
value_matcher.stub(:match?).with(expected_value)
|
88
|
+
end
|
89
|
+
|
90
|
+
value_matcher_hash.match?(provided_hash)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should return the result of evaluating the value matchers" do
|
94
|
+
value_matchers.each { |value| value.stub(:match?).and_return(true) }
|
95
|
+
|
96
|
+
value_matcher_hash.match?(provided_hash).should be_true
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
context "and the provided hash contains more entries" do
|
104
|
+
|
105
|
+
let(:provided_hash) do
|
106
|
+
(1..5).reduce({}) do |result, i|
|
107
|
+
result["key#{i}"] = "another value#{i}"
|
108
|
+
result
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context "and it has matching keys and values" do
|
113
|
+
|
114
|
+
before(:each) do
|
115
|
+
value_matchers.each { |value| value.stub(:match?).with("another #{value}").and_return(true) }
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should return true" do
|
119
|
+
value_matcher_hash.match?(provided_hash).should be_true
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
127
|
+
|
128
|
+
context "when the stubbed hash is empty" do
|
129
|
+
|
130
|
+
let(:stubbed_hash) { {} }
|
131
|
+
|
132
|
+
context "and the provided hash is not empty" do
|
133
|
+
|
134
|
+
let(:provided_hash) { { "key" => "value" } }
|
135
|
+
|
136
|
+
it "should return true" do
|
137
|
+
value_matcher_hash.match?(provided_hash).should be_true
|
138
|
+
end
|
139
|
+
|
140
|
+
end
|
141
|
+
|
142
|
+
context "and the provided hash is empty" do
|
143
|
+
|
144
|
+
let(:provided_hash) { {} }
|
145
|
+
|
146
|
+
it "should return true" do
|
147
|
+
value_matcher_hash.match?(provided_hash).should be_true
|
148
|
+
end
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|
155
|
+
|
156
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
describe HttpStub::Models::OmittedValueMatcher do
|
2
|
+
|
3
|
+
describe ".match?" do
|
4
|
+
|
5
|
+
context "when the stubbed value is 'control:omitted'" do
|
6
|
+
|
7
|
+
let(:stub_value) { "control:omitted" }
|
8
|
+
|
9
|
+
context "and the actual value is nil" do
|
10
|
+
|
11
|
+
let(:actual_value) { nil }
|
12
|
+
|
13
|
+
it "should return true" do
|
14
|
+
perform_match.should be_true
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
context "and the actual value is non-empty string" do
|
20
|
+
|
21
|
+
let(:actual_value) { "some non-empty string" }
|
22
|
+
|
23
|
+
it "should return false" do
|
24
|
+
perform_match.should be_false
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
context "and the actual value is an empty string" do
|
30
|
+
|
31
|
+
let(:actual_value) { "" }
|
32
|
+
|
33
|
+
it "should return false" do
|
34
|
+
perform_match.should be_false
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
context "when the stub value is not 'control:omitted'" do
|
42
|
+
|
43
|
+
let(:stub_value) { "some other stub value" }
|
44
|
+
let(:actual_value) { nil }
|
45
|
+
|
46
|
+
it "should return false" do
|
47
|
+
perform_match.should be_false
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
def perform_match
|
53
|
+
HttpStub::Models::OmittedValueMatcher.match?(stub_value, actual_value)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
describe HttpStub::Models::RegexpValueMatcher do
|
2
|
+
|
3
|
+
describe ".match?" do
|
4
|
+
|
5
|
+
context "when the stub value is a string prefixed with 'regexp:'" do
|
6
|
+
|
7
|
+
let(:stub_value) { "regexp:^a[0-9]*\\$z$" }
|
8
|
+
|
9
|
+
context "and the actual value matches the regular expression" do
|
10
|
+
|
11
|
+
let(:actual_value) { "a789$z" }
|
12
|
+
|
13
|
+
it "should return true" do
|
14
|
+
perform_match.should be_true
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
context "and the actual value does not match the regular expression" do
|
20
|
+
|
21
|
+
let(:actual_value) { "a789" }
|
22
|
+
|
23
|
+
it "should return false" do
|
24
|
+
perform_match.should be_false
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when the provided value is not a string prefixed with 'regexp'" do
|
32
|
+
|
33
|
+
let(:stub_value) { "does not start with regexp:" }
|
34
|
+
let(:actual_value) { "some actual value" }
|
35
|
+
|
36
|
+
it "should return false" do
|
37
|
+
perform_match.should be_false
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
def perform_match
|
43
|
+
HttpStub::Models::RegexpValueMatcher.match?(stub_value, actual_value)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
@@ -10,7 +10,7 @@ describe HttpStub::Models::StubHeaders do
|
|
10
10
|
it "should create a regexpable representation of the stubbed headers whose keys are downcased and underscored" do
|
11
11
|
downcased_and_underscored_hash = { "another_stub_key" => "value" }
|
12
12
|
stubbed_headers.should_receive(:downcase_and_underscore_keys).and_return(downcased_and_underscored_hash)
|
13
|
-
HttpStub::Models::
|
13
|
+
HttpStub::Models::HashWithValueMatchers.should_receive(:new).with(downcased_and_underscored_hash)
|
14
14
|
|
15
15
|
stub_headers
|
16
16
|
end
|
@@ -22,7 +22,7 @@ describe HttpStub::Models::StubHeaders do
|
|
22
22
|
let(:stubbed_headers) { nil }
|
23
23
|
|
24
24
|
it "should create a regexpable representation of an empty hash" do
|
25
|
-
HttpStub::Models::
|
25
|
+
HttpStub::Models::HashWithValueMatchers.should_receive(:new).with({})
|
26
26
|
|
27
27
|
stub_headers
|
28
28
|
end
|
@@ -32,10 +32,10 @@ describe HttpStub::Models::StubHeaders do
|
|
32
32
|
describe "#match?" do
|
33
33
|
|
34
34
|
let(:request_headers) { { "request_key" => "value" } }
|
35
|
-
let(:regexpable_stubbed_headers) { double(HttpStub::Models::
|
35
|
+
let(:regexpable_stubbed_headers) { double(HttpStub::Models::HashWithValueMatchers).as_null_object }
|
36
36
|
|
37
37
|
before(:each) do
|
38
|
-
HttpStub::Models::
|
38
|
+
HttpStub::Models::HashWithValueMatchers.stub(:new).and_return(regexpable_stubbed_headers)
|
39
39
|
HttpStub::Models::RequestHeaderParser.stub(:parse).with(request).and_return(request_headers)
|
40
40
|
end
|
41
41
|
|
@@ -4,14 +4,14 @@ 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::
|
7
|
+
let(:regexpable_stubbed_paremeters) { double(HttpStub::Models::HashWithValueMatchers).as_null_object }
|
8
8
|
|
9
9
|
let(:stub_parameters) { HttpStub::Models::StubParameters.new(stubbed_parameters) }
|
10
10
|
|
11
11
|
describe "when stubbed parameters are provided" do
|
12
12
|
|
13
13
|
it "should create a regexpable representation of the stubbed parameters" do
|
14
|
-
HttpStub::Models::
|
14
|
+
HttpStub::Models::HashWithValueMatchers.should_receive(:new).with(stubbed_parameters)
|
15
15
|
|
16
16
|
stub_parameters
|
17
17
|
end
|
@@ -23,7 +23,7 @@ describe HttpStub::Models::StubParameters do
|
|
23
23
|
let(:stubbed_parameters) { nil }
|
24
24
|
|
25
25
|
it "should create a regexpable representation of an empty hash" do
|
26
|
-
HttpStub::Models::
|
26
|
+
HttpStub::Models::HashWithValueMatchers.should_receive(:new).with({})
|
27
27
|
|
28
28
|
stub_parameters
|
29
29
|
end
|
@@ -33,7 +33,7 @@ describe HttpStub::Models::StubParameters do
|
|
33
33
|
describe "#match?" do
|
34
34
|
|
35
35
|
it "should delegate to the regexpable representation of the stubbed parameters to determine a match" do
|
36
|
-
HttpStub::Models::
|
36
|
+
HttpStub::Models::HashWithValueMatchers.stub(:new).and_return(regexpable_stubbed_paremeters)
|
37
37
|
regexpable_stubbed_paremeters.should_receive(:match?).with(request_parameters).and_return(true)
|
38
38
|
|
39
39
|
stub_parameters.match?(request).should be(true)
|
@@ -2,15 +2,15 @@ describe HttpStub::Models::StubUri do
|
|
2
2
|
|
3
3
|
let(:stubbed_uri) { "/some/uri" }
|
4
4
|
let(:request) { double("HttpRequest", path_info: request_uri) }
|
5
|
-
let(:
|
5
|
+
let(:value_matcher) { double(HttpStub::Models::ValueMatcher).as_null_object }
|
6
6
|
let(:stub_uri) { HttpStub::Models::StubUri.new(stubbed_uri) }
|
7
7
|
|
8
|
-
before(:each) { HttpStub::Models::
|
8
|
+
before(:each) { HttpStub::Models::ValueMatcher.stub(:new).and_return(value_matcher) }
|
9
9
|
|
10
10
|
describe "constructor" do
|
11
11
|
|
12
|
-
it "should create a
|
13
|
-
HttpStub::Models::
|
12
|
+
it "should create a value matcher for the provided uri" do
|
13
|
+
HttpStub::Models::ValueMatcher.should_receive(:new).with(stubbed_uri)
|
14
14
|
|
15
15
|
stub_uri
|
16
16
|
end
|
@@ -21,8 +21,8 @@ describe HttpStub::Models::StubUri do
|
|
21
21
|
|
22
22
|
let(:request_uri) { "/some/uri" }
|
23
23
|
|
24
|
-
it "should delegate to the
|
25
|
-
|
24
|
+
it "should delegate to the value matcher representation of the provided uri" do
|
25
|
+
value_matcher.should_receive(:match?).with(request_uri).and_return(true)
|
26
26
|
|
27
27
|
stub_uri.match?(request).should be_true
|
28
28
|
end
|
@@ -31,10 +31,10 @@ describe HttpStub::Models::StubUri do
|
|
31
31
|
|
32
32
|
describe "#to_s" do
|
33
33
|
|
34
|
-
it "should delegate to the
|
35
|
-
|
34
|
+
it "should delegate to the value matcher representation of the provided uri" do
|
35
|
+
value_matcher.should_receive(:to_s).and_return("some value matcher string")
|
36
36
|
|
37
|
-
stub_uri.to_s.should eql("some
|
37
|
+
stub_uri.to_s.should eql("some value matcher string")
|
38
38
|
end
|
39
39
|
|
40
40
|
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
describe HttpStub::Models::ValueMatcher do
|
2
|
+
|
3
|
+
let(:stub_value) { "some stub value" }
|
4
|
+
|
5
|
+
let(:value_matcher) { HttpStub::Models::ValueMatcher.new(stub_value) }
|
6
|
+
|
7
|
+
describe "#match?" do
|
8
|
+
|
9
|
+
let(:actual_value) { "some actual value" }
|
10
|
+
|
11
|
+
it "should determine if actual value should be omitted" do
|
12
|
+
HttpStub::Models::OmittedValueMatcher.should_receive(:match?).with(stub_value, actual_value)
|
13
|
+
|
14
|
+
perform_match
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should determine if the actual value matches a regular expression" do
|
18
|
+
HttpStub::Models::RegexpValueMatcher.should_receive(:match?).with(stub_value, actual_value)
|
19
|
+
|
20
|
+
perform_match
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should determine if the actual value exactly matches the stub value" do
|
24
|
+
HttpStub::Models::ExactValueMatcher.should_receive(:match?).with(stub_value, actual_value)
|
25
|
+
|
26
|
+
perform_match
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when an omitted match occurs" do
|
30
|
+
|
31
|
+
before(:each) { HttpStub::Models::OmittedValueMatcher.should_receive(:match?).and_return(true) }
|
32
|
+
|
33
|
+
it "should return true" do
|
34
|
+
perform_match.should be_true
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when a regular expression match occurs" do
|
40
|
+
|
41
|
+
before(:each) { HttpStub::Models::RegexpValueMatcher.should_receive(:match?).and_return(true) }
|
42
|
+
|
43
|
+
it "should return true" do
|
44
|
+
perform_match.should be_true
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
context "when an exact match occurs" do
|
50
|
+
|
51
|
+
before(:each) { HttpStub::Models::ExactValueMatcher.should_receive(:match?).and_return(true) }
|
52
|
+
|
53
|
+
it "should return true" do
|
54
|
+
perform_match.should be_true
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
context "when no match occurs" do
|
60
|
+
|
61
|
+
it "should return false" do
|
62
|
+
perform_match.should be_false
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
def perform_match
|
68
|
+
value_matcher.match?(actual_value)
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#to_s" do
|
74
|
+
|
75
|
+
it "should return the stub value provided" do
|
76
|
+
value_matcher.to_s.should eql(stub_value)
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -4,21 +4,47 @@ describe HttpStub::Server, "when the server is running" do
|
|
4
4
|
|
5
5
|
let(:configurer) { HttpStub::Examples::ConfigurerWithManyActivators.new }
|
6
6
|
|
7
|
+
describe "POST #stubs" do
|
8
|
+
|
9
|
+
context "when provided with the minimum data required" do
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
@response = HTTParty.post(
|
13
|
+
"#{server_uri}/stubs",
|
14
|
+
body: { uri: "/some/path", method: "get", response: { status: 200, body: "Some body" } }.to_json
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return a 200 response code" do
|
19
|
+
@response.code.should eql(200)
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should register a stub returning the provided response for a matching request" do
|
23
|
+
stubbed_response = HTTParty.get("#{server_uri}/some/path")
|
24
|
+
|
25
|
+
stubbed_response.code.should eql(200)
|
26
|
+
stubbed_response.body.should eql("Some body")
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
7
33
|
describe "and a configurer with multiple stub activators is initialized" do
|
8
34
|
|
9
35
|
before(:all) do
|
10
|
-
HttpStub::Examples::ConfigurerWithManyActivators.host
|
11
|
-
HttpStub::Examples::ConfigurerWithManyActivators.port
|
36
|
+
HttpStub::Examples::ConfigurerWithManyActivators.host(server_host)
|
37
|
+
HttpStub::Examples::ConfigurerWithManyActivators.port(server_port)
|
12
38
|
HttpStub::Examples::ConfigurerWithManyActivators.initialize!
|
13
39
|
end
|
14
40
|
|
15
41
|
describe "GET #stubs/activators" do
|
16
42
|
|
17
|
-
let(:response) {
|
43
|
+
let(:response) { HTTParty.get("#{server_uri}/stubs/activators") }
|
18
44
|
let(:response_document) { Nokogiri::HTML(response.body) }
|
19
45
|
|
20
46
|
it "should return a 200 response code" do
|
21
|
-
response.code.should eql(
|
47
|
+
response.code.should eql(200)
|
22
48
|
end
|
23
49
|
|
24
50
|
it "should return response whose body contains a link to each activator in alphabetical order" do
|
@@ -56,14 +82,14 @@ describe HttpStub::Server, "when the server is running" do
|
|
56
82
|
describe "when multiple stubs are configured" do
|
57
83
|
|
58
84
|
before(:all) do
|
59
|
-
(1..3).each { |i|
|
85
|
+
(1..3).each { |i| HTTParty.get("#{server_uri}/activator#{i}") }
|
60
86
|
end
|
61
87
|
|
62
|
-
let(:response) {
|
88
|
+
let(:response) { HTTParty.get("#{server_uri}/stubs") }
|
63
89
|
let(:response_document) { Nokogiri::HTML(response.body) }
|
64
90
|
|
65
91
|
it "should return a 200 response code" do
|
66
|
-
response.code.should eql(
|
92
|
+
response.code.should eql(200)
|
67
93
|
end
|
68
94
|
|
69
95
|
it "should return a response whose body contains the uri of each stub" do
|
@@ -37,12 +37,8 @@ describe HttpStub::Server do
|
|
37
37
|
|
38
38
|
def issue_stub_request
|
39
39
|
post "/stubs", {
|
40
|
-
|
41
|
-
|
42
|
-
"response" => {
|
43
|
-
"status" => 200,
|
44
|
-
"body" => "Foo"
|
45
|
-
}
|
40
|
+
uri: "/a_path", method: "a method",
|
41
|
+
response: { status: 200, body: "Foo" }
|
46
42
|
}.to_json
|
47
43
|
end
|
48
44
|
|
@@ -57,7 +53,9 @@ describe HttpStub::Server do
|
|
57
53
|
end
|
58
54
|
|
59
55
|
it "should respond with the response provided by the controller" do
|
60
|
-
stub_activator_controller.stub(:register).and_return(
|
56
|
+
stub_activator_controller.stub(:register).and_return(
|
57
|
+
HttpStub::Models::Response.new("status" => 302, "body" => "")
|
58
|
+
)
|
61
59
|
|
62
60
|
issue_stub_activator_request
|
63
61
|
|
@@ -66,13 +64,8 @@ describe HttpStub::Server do
|
|
66
64
|
|
67
65
|
def issue_stub_activator_request
|
68
66
|
post "/stubs/activators", {
|
69
|
-
|
70
|
-
|
71
|
-
"method" => "a method",
|
72
|
-
"response" => {
|
73
|
-
"status" => 200,
|
74
|
-
"body" => "Foo"
|
75
|
-
}
|
67
|
+
activation_uri: "/an_activation_path", uri: "/a_path", method: "a method",
|
68
|
+
response: { status: 200, body: "Foo" }
|
76
69
|
}.to_json
|
77
70
|
end
|
78
71
|
|
@@ -141,7 +134,9 @@ describe HttpStub::Server do
|
|
141
134
|
context "but the stub activator controller activates a stub" do
|
142
135
|
|
143
136
|
before(:each) do
|
144
|
-
stub_activator_controller.stub(:activate).and_return(
|
137
|
+
stub_activator_controller.stub(:activate).and_return(
|
138
|
+
HttpStub::Models::Response.new("status" => 300, "body" => "A body")
|
139
|
+
)
|
145
140
|
end
|
146
141
|
|
147
142
|
it "should respond with the activation response status code" do
|
@@ -185,7 +180,9 @@ describe HttpStub::Server do
|
|
185
180
|
end
|
186
181
|
|
187
182
|
it "should respond with the response's content type" do
|
188
|
-
stub_controller.stub(:replay).and_return(
|
183
|
+
stub_controller.stub(:replay).and_return(
|
184
|
+
HttpStub::Models::Response.new("status" => 200, "body" => "A body", "content_type" => "application/xhtml")
|
185
|
+
)
|
189
186
|
get "/some/stubbed/uri"
|
190
187
|
response.content_type.should eql("application/xhtml")
|
191
188
|
end
|