-
Notifications
You must be signed in to change notification settings - Fork 257
Expand file tree
/
Copy pathserver_fixture_request_steps.rb
More file actions
42 lines (36 loc) · 1.07 KB
/
server_fixture_request_steps.rb
File metadata and controls
42 lines (36 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require 'net/http'
# Attempts to POST a string of request body data to a server.
#
# @step_input reqbody [String] body data to send.
# @step_input url [String] The URL to post data to.
# @step_input content_type [String] The content type of the data being sent.
When("I POST the data {string} to the URL {string} with the content type {string}") do |reqbody, url, content_type|
Net::HTTP.post(URI(url),
reqbody,
'Content-Type' => content_type)
end
When('I open the URL {string} tolerating any error') do |url|
begin
URI(url).open(&:read)
rescue
$logger.debug $!.inspect
end
end
When('I open the URL {string} and get a {int} response') do |url, expected_response_code|
begin
response = Net::HTTP.get_response(URI(url))
rescue
$logger.debug $!.inspect
end
Maze.check.equal(
expected_response_code,
response.code.to_i,
<<~TEXT
Unexpected response code "#{response.code}" received. Response body:
#{response.body}
TEXT
)
end
When('I stop all docker services') do
Maze::Docker.down_all_services
end