2009-01-28 23:37:10 -05:00
|
|
|
Given /a remote service that returns '(.*)'/ do |response_body|
|
2010-06-08 17:16:09 -04:00
|
|
|
@handler = BasicMongrelHandler.new
|
2009-01-28 23:37:10 -05:00
|
|
|
Given "the response from the service has a body of '#{response_body}'"
|
|
|
|
end
|
|
|
|
|
|
|
|
Given /a remote service that returns a (\d+) status code/ do |code|
|
2010-06-08 17:16:09 -04:00
|
|
|
@handler = BasicMongrelHandler.new
|
2009-01-28 23:37:10 -05:00
|
|
|
@handler.response_code = code
|
|
|
|
end
|
|
|
|
|
|
|
|
Given /that service is accessed at the path '(.*)'/ do |path|
|
|
|
|
@server.register(path, @handler)
|
|
|
|
end
|
|
|
|
|
2009-09-12 22:32:59 -04:00
|
|
|
Given /^that service takes (\d+) seconds to generate a response$/ do |time|
|
2010-05-04 22:46:22 -04:00
|
|
|
@server_response_time = time.to_i
|
2011-12-01 17:10:30 -05:00
|
|
|
@handler.preprocessor = Proc.new { sleep time.to_i }
|
2009-09-12 22:32:59 -04:00
|
|
|
end
|
|
|
|
|
2010-06-09 19:00:41 -04:00
|
|
|
Given /^a remote deflate service$/ do
|
|
|
|
@handler = DeflateHandler.new
|
|
|
|
end
|
|
|
|
|
2010-06-12 00:41:11 -04:00
|
|
|
Given /^a remote gzip service$/ do
|
|
|
|
@handler = GzipHandler.new
|
|
|
|
end
|
|
|
|
|
2009-01-28 23:37:10 -05:00
|
|
|
Given /the response from the service has a Content-Type of '(.*)'/ do |content_type|
|
|
|
|
@handler.content_type = content_type
|
|
|
|
end
|
|
|
|
|
|
|
|
Given /the response from the service has a body of '(.*)'/ do |response_body|
|
|
|
|
@handler.response_body = response_body
|
|
|
|
end
|
|
|
|
|
|
|
|
Given /the url '(.*)' redirects to '(.*)'/ do |redirection_url, target_url|
|
|
|
|
@server.register redirection_url, new_mongrel_redirector(target_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
Given /that service is protected by Basic Authentication/ do
|
2010-06-08 17:16:09 -04:00
|
|
|
@handler.extend BasicAuthentication
|
2009-01-28 23:37:10 -05:00
|
|
|
end
|
|
|
|
|
2010-04-26 21:32:30 -04:00
|
|
|
Given /that service is protected by Digest Authentication/ do
|
2010-06-08 17:16:09 -04:00
|
|
|
@handler.extend DigestAuthentication
|
2010-04-26 21:32:30 -04:00
|
|
|
end
|
|
|
|
|
2009-01-28 23:37:10 -05:00
|
|
|
Given /that service requires the username '(.*)' with the password '(.*)'/ do |username, password|
|
|
|
|
@handler.username = username
|
|
|
|
@handler.password = password
|
|
|
|
end
|
|
|
|
|
|
|
|
Given /a restricted page at '(.*)'/ do |url|
|
|
|
|
Given "a remote service that returns 'A response I will never see'"
|
|
|
|
And "that service is accessed at the path '#{url}'"
|
|
|
|
And "that service is protected by Basic Authentication"
|
|
|
|
And "that service requires the username 'something' with the password 'secret'"
|
|
|
|
end
|
|
|
|
|
|
|
|
# This joins the server thread, and halts cucumber, so you can actually hit the
|
|
|
|
# server with a browser. Runs until you kill it with Ctrl-c
|
|
|
|
Given /I want to hit this in a browser/ do
|
|
|
|
@server.acceptor.join
|
|
|
|
end
|
2010-05-04 22:46:22 -04:00
|
|
|
|
|
|
|
Then /I wait for the server to recover/ do
|
|
|
|
timeout = @request_options[:timeout] || 0
|
|
|
|
sleep @server_response_time - timeout
|
2010-04-26 21:32:30 -04:00
|
|
|
end
|