http_stub 0.21.0 → 0.22.0
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 +5 -13
- data/lib/http_stub.rb +2 -1
- data/lib/http_stub/configurer/dsl/scenario_builder.rb +4 -4
- data/lib/http_stub/configurer/request/http/factory.rb +2 -2
- data/lib/http_stub/configurer/server/facade.rb +19 -9
- data/lib/http_stub/server/application.rb +22 -12
- data/lib/http_stub/server/{views → public}/favicon.ico +0 -0
- data/lib/http_stub/server/public/jquery-2.2.1.min.js +4 -0
- data/lib/http_stub/server/scenario/activator.rb +3 -3
- data/lib/http_stub/server/scenario/controller.rb +3 -3
- data/lib/http_stub/server/scenario/links.rb +22 -0
- data/lib/http_stub/server/scenario/scenario.rb +14 -11
- data/lib/http_stub/server/scenario/trigger.rb +18 -0
- data/lib/http_stub/server/stub/controller.rb +1 -1
- data/lib/http_stub/server/stub/registry.rb +2 -2
- data/lib/http_stub/server/views/_activate_scenario.haml +10 -0
- data/lib/http_stub/server/views/application.sass +4 -0
- data/lib/http_stub/server/views/index.haml +6 -0
- data/lib/http_stub/server/views/layout.haml +3 -2
- data/lib/http_stub/server/views/matches.haml +1 -0
- data/lib/http_stub/server/views/{_scenario.haml → scenario.haml} +4 -3
- data/lib/http_stub/server/views/scenarios.haml +10 -3
- data/lib/http_stub/server/views/stubs.haml +1 -0
- data/lib/http_stub/version.rb +1 -1
- data/spec/acceptance/endpoint_template_spec.rb +2 -2
- data/spec/acceptance/scenario_spec.rb +3 -3
- data/spec/lib/http_stub/configurer/request/http/factory_spec.rb +24 -4
- data/spec/lib/http_stub/configurer/request/scenario_spec.rb +2 -2
- data/spec/lib/http_stub/configurer/server/facade_spec.rb +18 -8
- data/spec/lib/http_stub/server/application_integration_spec.rb +270 -111
- data/spec/lib/http_stub/server/application_spec.rb +81 -15
- data/spec/lib/http_stub/server/scenario/activator_spec.rb +8 -3
- data/spec/lib/http_stub/server/scenario/controller_spec.rb +9 -7
- data/spec/lib/http_stub/server/scenario/links_spec.rb +41 -0
- data/spec/lib/http_stub/server/scenario/scenario_spec.rb +72 -30
- data/spec/lib/http_stub/server/scenario/trigger_spec.rb +36 -0
- data/spec/lib/http_stub/server/stub/controller_spec.rb +2 -2
- data/spec/lib/http_stub/server/stub/registry_spec.rb +23 -9
- data/spec/spec_helper.rb +1 -1
- data/spec/support/http_stub/scenario_fixture.rb +3 -3
- metadata +334 -342
- data/lib/http_stub/server/request_pipeline.rb +0 -27
- data/spec/lib/http_stub/server/request_pipeline_spec.rb +0 -80
data/lib/http_stub/version.rb
CHANGED
@@ -26,7 +26,7 @@ describe "Endpoint Template acceptance" do
|
|
26
26
|
|
27
27
|
context "that customises the request matching rules" do
|
28
28
|
|
29
|
-
let(:scenario_name) { "
|
29
|
+
let(:scenario_name) { "Custom request" }
|
30
30
|
|
31
31
|
let(:response) { issue_request("custom_scenario_uri") }
|
32
32
|
|
@@ -39,7 +39,7 @@ describe "Endpoint Template acceptance" do
|
|
39
39
|
|
40
40
|
context "that customises the response" do
|
41
41
|
|
42
|
-
let(:scenario_name) { "
|
42
|
+
let(:scenario_name) { "Custom response" }
|
43
43
|
|
44
44
|
let(:response) { issue_request("template_uri") }
|
45
45
|
|
@@ -11,7 +11,7 @@ describe "Scenario acceptance" do
|
|
11
11
|
|
12
12
|
context "containing stubs" do
|
13
13
|
|
14
|
-
before(:example) { configurer.activate!("
|
14
|
+
before(:example) { configurer.activate!("Scenario 1") }
|
15
15
|
|
16
16
|
(1..3).each do |stub_number|
|
17
17
|
|
@@ -32,7 +32,7 @@ describe "Scenario acceptance" do
|
|
32
32
|
|
33
33
|
context "containing triggered scenarios" do
|
34
34
|
|
35
|
-
before(:example) { configurer.activate!("
|
35
|
+
before(:example) { configurer.activate!("Scenario that activates another scenario") }
|
36
36
|
|
37
37
|
(1..3).each do |stub_number|
|
38
38
|
|
@@ -71,7 +71,7 @@ describe "Scenario acceptance" do
|
|
71
71
|
|
72
72
|
let(:configurer) { HttpStub::Examples::ConfigurerWithFileResponses.new }
|
73
73
|
|
74
|
-
before(:example) { configurer.activate!("
|
74
|
+
before(:example) { configurer.activate!("Scenario with file") }
|
75
75
|
|
76
76
|
context "and the stub request is made" do
|
77
77
|
|
@@ -25,7 +25,7 @@ describe HttpStub::Configurer::Request::Http::Factory do
|
|
25
25
|
|
26
26
|
describe "::get" do
|
27
27
|
|
28
|
-
let(:path) { "some/get/path" }
|
28
|
+
let(:path) { "/some/get/path" }
|
29
29
|
let(:get_request) { instance_double(Net::HTTP::Get) }
|
30
30
|
let(:basic_request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
|
31
31
|
|
@@ -91,10 +91,30 @@ describe HttpStub::Configurer::Request::Http::Factory do
|
|
91
91
|
subject
|
92
92
|
end
|
93
93
|
|
94
|
-
|
95
|
-
|
94
|
+
context "when parameters are provided" do
|
95
|
+
|
96
|
+
let(:parameters) { (1..3).each_with_object({}) { |i, result| result["key#{i}"] = "value#{i}" } }
|
97
|
+
|
98
|
+
subject { HttpStub::Configurer::Request::Http::Factory.post(path, parameters) }
|
99
|
+
|
100
|
+
it "establishes the provided parameters as the form data in the POST request" do
|
101
|
+
expect(post_request).to receive(:set_form_data).with(parameters)
|
102
|
+
|
103
|
+
subject
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
context "when no parameters are provided" do
|
109
|
+
|
110
|
+
subject { HttpStub::Configurer::Request::Http::Factory.post(path) }
|
111
|
+
|
112
|
+
it "establishes empty form data in the POST request" do
|
113
|
+
expect(post_request).to receive(:set_form_data).with({})
|
114
|
+
|
115
|
+
subject
|
116
|
+
end
|
96
117
|
|
97
|
-
subject
|
98
118
|
end
|
99
119
|
|
100
120
|
it "creates a basic request wrapping the POST request" do
|
@@ -1,8 +1,8 @@
|
|
1
1
|
describe HttpStub::Configurer::Request::Scenario do
|
2
2
|
|
3
|
-
let(:name) { "
|
3
|
+
let(:name) { "Some scenario name" }
|
4
4
|
let(:stubs) { (1..3).map { instance_double(HttpStub::Configurer::Request::Stub) } }
|
5
|
-
let(:triggered_scenario_names) { (1..3).map { |i| "
|
5
|
+
let(:triggered_scenario_names) { (1..3).map { |i| "Triggered scenario name #{i}" } }
|
6
6
|
|
7
7
|
let(:scenario) do
|
8
8
|
HttpStub::Configurer::Request::Scenario.new(
|
@@ -89,18 +89,28 @@ describe HttpStub::Configurer::Server::Facade do
|
|
89
89
|
|
90
90
|
describe "#activate" do
|
91
91
|
|
92
|
-
let(:
|
93
|
-
let(:request)
|
92
|
+
let(:scenario_name) { "some/scenario/name" }
|
93
|
+
let(:request) { instance_double(HttpStub::Configurer::Request::Http::Basic) }
|
94
94
|
|
95
|
-
subject { facade.activate(
|
95
|
+
subject { facade.activate(scenario_name) }
|
96
96
|
|
97
97
|
before(:example) do
|
98
|
-
allow(HttpStub::Configurer::Request::Http::Factory).to receive(:
|
98
|
+
allow(HttpStub::Configurer::Request::Http::Factory).to receive(:post).and_return(request)
|
99
99
|
allow(request_processor).to receive(:submit)
|
100
100
|
end
|
101
101
|
|
102
|
-
it "creates an
|
103
|
-
expect(HttpStub::Configurer::Request::Http::Factory).to
|
102
|
+
it "creates an POST request to activate a scenario" do
|
103
|
+
expect(HttpStub::Configurer::Request::Http::Factory).to(
|
104
|
+
receive(:post).with("/http_stub/scenarios/activate", anything).and_return(request)
|
105
|
+
)
|
106
|
+
|
107
|
+
subject
|
108
|
+
end
|
109
|
+
|
110
|
+
it "creates a POST request with the scenario name as a parameter" do
|
111
|
+
expect(HttpStub::Configurer::Request::Http::Factory).to(
|
112
|
+
receive(:post).with(anything, hash_including(:name => scenario_name)).and_return(request)
|
113
|
+
)
|
104
114
|
|
105
115
|
subject
|
106
116
|
end
|
@@ -111,8 +121,8 @@ describe HttpStub::Configurer::Server::Facade do
|
|
111
121
|
subject
|
112
122
|
end
|
113
123
|
|
114
|
-
it "describes the activation request
|
115
|
-
expect(request_processor).to receive(:submit).with(hash_including(description: "activating '#{
|
124
|
+
it "describes the activation request using the provided scenario name" do
|
125
|
+
expect(request_processor).to receive(:submit).with(hash_including(description: "activating '#{scenario_name}'"))
|
116
126
|
|
117
127
|
subject
|
118
128
|
end
|
@@ -3,7 +3,33 @@ describe HttpStub::Server::Application, "when the server is running" do
|
|
3
3
|
|
4
4
|
let(:response_document) { Nokogiri::HTML(response.body) }
|
5
5
|
|
6
|
-
describe "
|
6
|
+
describe "GET /http_stub" do
|
7
|
+
|
8
|
+
let(:response) { HTTParty.get("#{server_uri}/http_stub") }
|
9
|
+
|
10
|
+
it "returns a 200 response code" do
|
11
|
+
expect(response.code).to eql(200)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns a response whose body links to the stubs list" do
|
15
|
+
expect(link_for("stubs")).to eql("/http_stub/stubs")
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns a response whose body links to the scenarios list" do
|
19
|
+
expect(link_for("scenarios")).to eql("/http_stub/scenarios")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "returns a response whose body links to the matches list" do
|
23
|
+
expect(link_for("stub_matches")).to eql("/http_stub/stubs/matches")
|
24
|
+
end
|
25
|
+
|
26
|
+
def link_for(id)
|
27
|
+
response_document.at_css("a##{id}")["href"]
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "POST /http_stub/stubs" do
|
7
33
|
|
8
34
|
context "when provided with the minimum data required" do
|
9
35
|
|
@@ -40,178 +66,311 @@ describe HttpStub::Server::Application, "when the server is running" do
|
|
40
66
|
configurer.initialize!
|
41
67
|
end
|
42
68
|
|
43
|
-
|
69
|
+
describe "GET /http_stub/stubs" do
|
44
70
|
|
45
|
-
|
46
|
-
expect(response.code).to eql(200)
|
47
|
-
end
|
71
|
+
describe "when multiple stubs are configured" do
|
48
72
|
|
49
|
-
|
50
|
-
|
51
|
-
|
73
|
+
before(:context) do
|
74
|
+
(1..3).each do |i|
|
75
|
+
HTTParty.post("#{server_uri}/http_stub/scenarios/activate", :body => { :name => "Scenario #{i}" })
|
76
|
+
end
|
52
77
|
end
|
53
|
-
end
|
54
78
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
79
|
+
let(:response) { HTTParty.get("#{server_uri}/http_stub/stubs") }
|
80
|
+
|
81
|
+
it "returns a 200 response code" do
|
82
|
+
expect(response.code).to eql(200)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "returns a response whose body contains the uri of each stub" do
|
86
|
+
(1..3).each do |stub_number|
|
87
|
+
expect(response.body).to match(/#{escape_html("/path_#{stub_number}")}/)
|
59
88
|
end
|
60
89
|
end
|
61
|
-
end
|
62
90
|
|
63
|
-
|
64
|
-
|
65
|
-
|
91
|
+
it "returns a response whose body contains the uri of each stub trigger" do
|
92
|
+
(1..3).each do |stub_number|
|
93
|
+
(1..3).each do |trigger_number|
|
94
|
+
expect(response.body).to match(/#{escape_html("/path_#{stub_number}_trigger_#{trigger_number}")}/)
|
95
|
+
end
|
96
|
+
end
|
66
97
|
end
|
67
|
-
end
|
68
98
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
expected_header_key = "request_header_#{stub_number}_trigger_#{trigger_number}"
|
73
|
-
expected_header_value = "request_header_value_#{stub_number}_trigger_#{trigger_number}"
|
74
|
-
expect(response.body).to match(/#{expected_header_key}:#{expected_header_value}/)
|
99
|
+
it "returns a response whose body contains the request headers of each stub" do
|
100
|
+
(1..3).each do |stub_number|
|
101
|
+
expect(response.body).to match(/request_header_#{stub_number}:request_header_value_#{stub_number}/)
|
75
102
|
end
|
76
103
|
end
|
77
|
-
end
|
78
104
|
|
79
|
-
|
80
|
-
|
81
|
-
|
105
|
+
it "returns a response whose body contains the request headers of each stub trigger" do
|
106
|
+
(1..3).each do |stub_number|
|
107
|
+
(1..3).each do |trigger_number|
|
108
|
+
expected_header_key = "request_header_#{stub_number}_trigger_#{trigger_number}"
|
109
|
+
expected_header_value = "request_header_value_#{stub_number}_trigger_#{trigger_number}"
|
110
|
+
expect(response.body).to match(/#{expected_header_key}:#{expected_header_value}/)
|
111
|
+
end
|
112
|
+
end
|
82
113
|
end
|
83
|
-
end
|
84
114
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
expected_parameter_key = "parameter_#{stub_number}_trigger_#{trigger_number}"
|
89
|
-
expected_parameter_value = "parameter_value_#{stub_number}_trigger_#{trigger_number}"
|
90
|
-
expect(response.body).to match(/#{expected_parameter_key}=#{expected_parameter_value}/)
|
115
|
+
it "returns a response whose body contains the parameters of each stub" do
|
116
|
+
(1..3).each do |stub_number|
|
117
|
+
expect(response.body).to match(/parameter_#{stub_number}=parameter_value_#{stub_number}/)
|
91
118
|
end
|
92
119
|
end
|
93
|
-
end
|
94
120
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
121
|
+
it "returns a response whose body contains the parameters of each stub trigger" do
|
122
|
+
(1..3).each do |stub_number|
|
123
|
+
(1..3).each do |trigger_number|
|
124
|
+
expected_parameter_key = "parameter_#{stub_number}_trigger_#{trigger_number}"
|
125
|
+
expected_parameter_value = "parameter_value_#{stub_number}_trigger_#{trigger_number}"
|
126
|
+
expect(response.body).to match(/#{expected_parameter_key}=#{expected_parameter_value}/)
|
127
|
+
end
|
128
|
+
end
|
100
129
|
end
|
101
|
-
end
|
102
130
|
|
103
|
-
|
104
|
-
|
105
|
-
(1..3).each do |trigger_number|
|
106
|
-
expected_property_name = "property_#{stub_number}_trigger_#{trigger_number}"
|
107
|
-
expected_property_type = "property_#{stub_number}_trigger_#{trigger_number}_type"
|
131
|
+
it "returns a response whose body contains the bodies of each stub" do
|
132
|
+
(1..3).each do |stub_number|
|
108
133
|
expect(response.body).to(
|
109
|
-
match(/#{escape_html("\"#{
|
134
|
+
match(/#{escape_html("\"property_#{stub_number}\":{\"type\":\"property_#{stub_number}_type\"")}/)
|
110
135
|
)
|
111
136
|
end
|
112
137
|
end
|
113
|
-
end
|
114
|
-
|
115
|
-
it "returns a response whose body contains the response status of each stub" do
|
116
|
-
(1..3).each { |stub_number| expect(response.body).to match(/20#{stub_number}/) }
|
117
|
-
end
|
118
138
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
139
|
+
it "returns a response whose body contains the bodies of each stub trigger" do
|
140
|
+
(1..3).each do |stub_number|
|
141
|
+
(1..3).each do |trigger_number|
|
142
|
+
expected_property_name = "property_#{stub_number}_trigger_#{trigger_number}"
|
143
|
+
expected_property_type = "property_#{stub_number}_trigger_#{trigger_number}_type"
|
144
|
+
expect(response.body).to(
|
145
|
+
match(/#{escape_html("\"#{expected_property_name}\":{\"type\":\"#{expected_property_type}\"")}/)
|
146
|
+
)
|
147
|
+
end
|
123
148
|
end
|
124
149
|
end
|
125
|
-
end
|
126
150
|
|
127
|
-
|
128
|
-
|
129
|
-
expected_header_key = "response_header_#{stub_number}"
|
130
|
-
expected_header_value = "response_header_value_#{stub_number}"
|
131
|
-
expect(response.body).to match(/#{expected_header_key}:#{expected_header_value}/)
|
151
|
+
it "returns a response whose body contains the response status of each stub" do
|
152
|
+
(1..3).each { |stub_number| expect(response.body).to match(/20#{stub_number}/) }
|
132
153
|
end
|
133
|
-
end
|
134
154
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
155
|
+
it "returns a response whose body contains the response status of each stub trigger" do
|
156
|
+
(1..3).each do |stub_number|
|
157
|
+
(1..3).each do |trigger_number|
|
158
|
+
expect(response.body).to match(/30#{stub_number * trigger_number}/)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
it "returns a response whose body contains the response headers of each stub" do
|
164
|
+
(1..3).each do |stub_number|
|
165
|
+
expected_header_key = "response_header_#{stub_number}"
|
166
|
+
expected_header_value = "response_header_value_#{stub_number}"
|
140
167
|
expect(response.body).to match(/#{expected_header_key}:#{expected_header_value}/)
|
141
168
|
end
|
142
169
|
end
|
143
|
-
end
|
144
170
|
|
145
|
-
|
146
|
-
|
147
|
-
|
171
|
+
it "returns a response whose body contains the response headers of each stub trigger" do
|
172
|
+
(1..3).each do |stub_number|
|
173
|
+
(1..3).each do |trigger_number|
|
174
|
+
expected_header_key = "response_header_#{stub_number}_trigger_#{trigger_number}"
|
175
|
+
expected_header_value = "response_header_value_#{stub_number}_trigger_#{trigger_number}"
|
176
|
+
expect(response.body).to match(/#{expected_header_key}:#{expected_header_value}/)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
148
180
|
|
149
|
-
|
150
|
-
|
151
|
-
|
181
|
+
it "returns a response whose body contains the response body of stub returning JSON" do
|
182
|
+
expect(response.body).to match(/#{escape_html({ "key" => "JSON body" }.to_json)}/)
|
183
|
+
end
|
152
184
|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
end
|
185
|
+
it "returns a response whose body contains the response body of stub returning HTML" do
|
186
|
+
expect(response.body).to match(/#{escape_html("<html><body>HTML body</body></html>")}/)
|
187
|
+
end
|
157
188
|
|
158
|
-
|
159
|
-
|
160
|
-
(
|
161
|
-
|
189
|
+
it "returns a response whose body contains the response body of a stub returning a file" do
|
190
|
+
file_link = response_document.css("a.file").first
|
191
|
+
expect(file_link["href"]).to match(/^file:\/\/[^']+\.pdf$/)
|
192
|
+
end
|
193
|
+
|
194
|
+
it "returns a response whose body contains the response body of each stub trigger" do
|
195
|
+
(1..3).each do |stub_number|
|
196
|
+
(1..3).each do |trigger_number|
|
197
|
+
expect(response.body).to match(/Body of scenario stub #{stub_number}_trigger_#{trigger_number}/)
|
198
|
+
end
|
162
199
|
end
|
163
200
|
end
|
164
|
-
end
|
165
201
|
|
166
|
-
|
167
|
-
|
168
|
-
|
202
|
+
it "returns a response whose body contains the response delay of each stub" do
|
203
|
+
(1..3).each { |stub_number| expect(response.body).to include("#{8 * stub_number}") }
|
204
|
+
end
|
169
205
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
206
|
+
it "returns a response whose body contains the response delay of each stub trigger" do
|
207
|
+
(1..3).each do |stub_number|
|
208
|
+
(1..3).each do |trigger_number|
|
209
|
+
expect(response.body).to include("#{3 * stub_number * trigger_number}")
|
210
|
+
end
|
174
211
|
end
|
175
212
|
end
|
213
|
+
|
176
214
|
end
|
177
215
|
|
178
216
|
end
|
179
217
|
|
180
|
-
describe "GET /
|
181
|
-
|
182
|
-
describe "when multiple stubs are configured" do
|
218
|
+
describe "GET /http_stub/scenarios" do
|
183
219
|
|
184
|
-
|
220
|
+
let(:response) { HTTParty.get("#{server_uri}/http_stub/scenarios") }
|
185
221
|
|
186
|
-
|
222
|
+
it "returns a response whose body contains the name of each scenario in alphabetical order" do
|
223
|
+
expected_scenario_names = [ "Nested scenario", "Scenario" ].map do |scenario_name_prefix|
|
224
|
+
(1..3).map { |i| "#{scenario_name_prefix} #{i}" }
|
225
|
+
end.flatten
|
187
226
|
|
188
|
-
|
227
|
+
scenario_names = response_document.css(".scenario_name").map { |element| element.text }
|
189
228
|
|
229
|
+
expect(scenario_names).to eql(expected_scenario_names)
|
190
230
|
end
|
191
231
|
|
192
|
-
|
232
|
+
it "returns a response whose body contains links to activate each scenario" do
|
233
|
+
expected_activation_links = [ "/http_stub/scenarios/activate" ] * 6
|
193
234
|
|
194
|
-
|
235
|
+
activation_links = response_document.css("a.activate_scenario").map { |link| link["href"] }
|
195
236
|
|
196
|
-
|
237
|
+
expect(activation_links).to eql(expected_activation_links)
|
238
|
+
end
|
197
239
|
|
198
|
-
it "returns a response whose body contains links to
|
199
|
-
|
200
|
-
(1..3).map { |i| "
|
240
|
+
it "returns a response whose body contains links to the details of each scenario" do
|
241
|
+
expected_detail_links = %w{ Nested+scenario Scenario }.map do |scenario_name_prefix|
|
242
|
+
(1..3).map { |i| "/http_stub/scenarios?name=#{scenario_name_prefix}+#{i}" }
|
201
243
|
end.flatten
|
202
244
|
|
203
|
-
|
245
|
+
detail_links = response_document.css("a.view_scenario").map { |link| link["href"] }
|
204
246
|
|
205
|
-
expect(
|
247
|
+
expect(detail_links).to eql(expected_detail_links)
|
206
248
|
end
|
207
249
|
|
208
|
-
|
209
|
-
|
210
|
-
|
250
|
+
end
|
251
|
+
|
252
|
+
describe "GET /http/scenario?name" do
|
253
|
+
|
254
|
+
(1..3).each do |stub_number|
|
255
|
+
|
256
|
+
scenario_name = "Scenario #{stub_number}"
|
257
|
+
|
258
|
+
context "when the scenario with the name '#{scenario_name}' is requested" do
|
259
|
+
|
260
|
+
let(:response) do
|
261
|
+
HTTParty.get("#{server_uri}/http_stub/scenarios?#{URI.encode_www_form(:name => scenario_name)}")
|
262
|
+
end
|
263
|
+
|
264
|
+
it "should have a detail page for the scenario" do
|
265
|
+
expect(response.code).to eql(200)
|
266
|
+
end
|
267
|
+
|
268
|
+
it "returns a response whose body contains the uri of the scenario" do
|
269
|
+
expect(response.body).to match(/#{escape_html("/path_#{stub_number}")}/)
|
270
|
+
end
|
271
|
+
|
272
|
+
it "returns a response whose body contains the uri of each stub trigger" do
|
273
|
+
(1..3).each do |trigger_number|
|
274
|
+
expect(response.body).to match(/#{escape_html("/path_#{stub_number}_trigger_#{trigger_number}")}/)
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
it "returns a response whose body contains the request headers of each stub" do
|
279
|
+
expect(response.body).to match(/request_header_#{stub_number}:request_header_value_#{stub_number}/)
|
280
|
+
end
|
281
|
+
|
282
|
+
it "returns a response whose body contains the request headers of each stub trigger" do
|
283
|
+
(1..3).each do |trigger_number|
|
284
|
+
expected_header_key = "request_header_#{stub_number}_trigger_#{trigger_number}"
|
285
|
+
expected_header_value = "request_header_value_#{stub_number}_trigger_#{trigger_number}"
|
286
|
+
expect(response.body).to match(/#{expected_header_key}:#{expected_header_value}/)
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
it "returns a response whose body contains the parameters of each stub" do
|
291
|
+
expect(response.body).to match(/parameter_#{stub_number}=parameter_value_#{stub_number}/)
|
292
|
+
end
|
293
|
+
|
294
|
+
it "returns a response whose body contains the parameters of each stub trigger" do
|
295
|
+
(1..3).each do |trigger_number|
|
296
|
+
expected_parameter_key = "parameter_#{stub_number}_trigger_#{trigger_number}"
|
297
|
+
expected_parameter_value = "parameter_value_#{stub_number}_trigger_#{trigger_number}"
|
298
|
+
expect(response.body).to match(/#{expected_parameter_key}=#{expected_parameter_value}/)
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
it "returns a response whose body contains the bodies of each stub" do
|
303
|
+
expect(response.body).to(
|
304
|
+
match(/#{escape_html("\"property_#{stub_number}\":{\"type\":\"property_#{stub_number}_type\"")}/)
|
305
|
+
)
|
306
|
+
end
|
307
|
+
|
308
|
+
it "returns a response whose body contains the bodies of each stub trigger" do
|
309
|
+
(1..3).each do |trigger_number|
|
310
|
+
expected_property_name = "property_#{stub_number}_trigger_#{trigger_number}"
|
311
|
+
expected_property_type = "property_#{stub_number}_trigger_#{trigger_number}_type"
|
312
|
+
expect(response.body).to(
|
313
|
+
match(/#{escape_html("\"#{expected_property_name}\":{\"type\":\"#{expected_property_type}\"")}/)
|
314
|
+
)
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
it "returns a response whose body contains the response status of each stub" do
|
319
|
+
expect(response.body).to match(/20#{stub_number}/)
|
320
|
+
end
|
321
|
+
|
322
|
+
it "returns a response whose body contains the response status of each stub trigger" do
|
323
|
+
(1..3).each do |trigger_number|
|
324
|
+
expect(response.body).to match(/30#{stub_number * trigger_number}/)
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
it "returns a response whose body contains the response headers of each stub" do
|
329
|
+
expected_header_key = "response_header_#{stub_number}"
|
330
|
+
expected_header_value = "response_header_value_#{stub_number}"
|
331
|
+
expect(response.body).to match(/#{expected_header_key}:#{expected_header_value}/)
|
332
|
+
end
|
333
|
+
|
334
|
+
it "returns a response whose body contains the response headers of each stub trigger" do
|
335
|
+
(1..3).each do |trigger_number|
|
336
|
+
expected_header_key = "response_header_#{stub_number}_trigger_#{trigger_number}"
|
337
|
+
expected_header_value = "response_header_value_#{stub_number}_trigger_#{trigger_number}"
|
338
|
+
expect(response.body).to match(/#{expected_header_key}:#{expected_header_value}/)
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
it "returns a response whose body supports JSON responses" do
|
343
|
+
expect(response.body).to match(/#{escape_html({ "key" => "JSON body" }.to_json)}/)
|
344
|
+
end if stub_number == 1
|
345
|
+
|
346
|
+
it "returns a response whose body supports HTML responses" do
|
347
|
+
expect(response.body).to match(/#{escape_html("<html><body>HTML body</body></html>")}/)
|
348
|
+
end if stub_number == 2
|
349
|
+
|
350
|
+
it "returns a response whose body supports file responses" do
|
351
|
+
file_link = response_document.css("a.file").first
|
352
|
+
expect(file_link["href"]).to match(/^file:\/\/[^']+\.pdf$/)
|
353
|
+
end if stub_number == 3
|
354
|
+
|
355
|
+
it "returns a response whose body contains the response body of each stub trigger" do
|
356
|
+
(1..3).each do |trigger_number|
|
357
|
+
expect(response.body).to match(/Body of scenario stub #{stub_number}_trigger_#{trigger_number}/)
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
it "returns a response whose body contains the response delay of each stub" do
|
362
|
+
expect(response.body).to include("#{8 * stub_number}")
|
363
|
+
end
|
364
|
+
|
365
|
+
it "returns a response whose body contains the response delay of each stub trigger" do
|
366
|
+
(1..3).each do |trigger_number|
|
367
|
+
expect(response.body).to include("#{3 * stub_number * trigger_number}")
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
211
371
|
end
|
212
|
-
end
|
213
372
|
|
214
|
-
|
373
|
+
end
|
215
374
|
|
216
375
|
end
|
217
376
|
|