class MockWebService::Server
Public Instance Methods
add(response, opts = ResponseOptions.new)
click to toggle source
# File lib/mock-web-service/server.rb, line 41 def add(response, opts = ResponseOptions.new) @@responses[opts.path] = response set_response(opts) do status(opts.status) content_type opts.content_type headers opts.headers @@requests.push(request) return @@responses[opts.path] end end
add_response(response)
click to toggle source
# File lib/mock-web-service/server.rb, line 24 def add_response(response) warn "[DEPRECATION] `add_response` is no longer supported. Please use `add` instead." Sinatra::Base.reset! Sinatra::Base.post '*/*' do content_type 'text/xml' @@requests.push(request.body.read) response end end
add_soap_response(response)
click to toggle source
# File lib/mock-web-service/server.rb, line 34 def add_soap_response(response) set_response(ResponseOptions.new {|opts| opts.path = '*/*'; opts.method = :post}) do content_type 'text/xml' response end end
clear_requests()
click to toggle source
# File lib/mock-web-service/server.rb, line 14 def clear_requests @@requests = [] end
get_all_requests()
click to toggle source
# File lib/mock-web-service/server.rb, line 10 def get_all_requests @@requests end
get_latest_request()
click to toggle source
# File lib/mock-web-service/server.rb, line 6 def get_latest_request @@requests.pop end
reset_server()
click to toggle source
# File lib/mock-web-service/server.rb, line 62 def reset_server Sinatra::Base.reset! @@requests = [] @@responses = {} end
set_response(opts, &block)
click to toggle source
# File lib/mock-web-service/server.rb, line 68 def set_response(opts, &block) Sinatra::Base.send(opts.method, opts.path, &block) end
start(overrides = {})
click to toggle source
# File lib/mock-web-service/server.rb, line 18 def start(overrides = {}) disable_logging = {AccessLog: []} options = {:bind => '0.0.0.0', :server_settings => disable_logging}.merge(overrides) Async.instance.run { Sinatra::Base.start!(options)} end
wait_for_next_request(timeout_seconds = 5, retry_interval = 0.5)
click to toggle source
# File lib/mock-web-service/server.rb, line 52 def wait_for_next_request(timeout_seconds = 5, retry_interval = 0.5) start = Time.now current_requests_count = @@requests.length while (@@requests.length == current_requests_count) break if (Time.now - start).to_i >= timeout_seconds sleep(retry_interval) end @@requests.last end