Sha256: 81d7ca9191f1e798afd9a7abb104a85518cf92c45f46d06cee693b714a325a9f
Contents?: true
Size: 1.66 KB
Versions: 1
Compression:
Stored size: 1.66 KB
Contents
require 'webmock/cucumber' include WebMock::API class MockRestService # STANDARD_HEADERS = {'Accept'=>'*/*', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'User-Agent'=>'Ruby'} STANDARD_HEADERS = {'Accept'=>'*/*', 'User-Agent'=>'Ruby'} STANDARD = "http" SECURE = "https" def initialize(host, port, protocol = STANDARD) @protocol = protocol @host = host @port = port @messages = {} end def store_msg(type, path, message, headers = {}, user = nil, password = nil) new_headers = STANDARD_HEADERS.merge(headers) auth_string = "#{user}:#{password}@" unless (user.nil? || password.nil?) case type.downcase when "get", "delete" WebMock.stub_request(type.downcase.to_sym, "#{@protocol}://#{auth_string}#{@host}:#{@port}#{path}"). with(:headers => new_headers). to_return({:body => "#{message}", :status => 200}, :headers => {}) when "post", "put" WebMock.stub_request(type.downcase.to_sym, "#{@protocol}://#{auth_string}#{@host}:#{@port}#{path}"). with(:headers => new_headers). to_return(:status => 200, :body => "#{message}", :headers => {}) else raise "Unsupported type: #{type}" end end def store_get_query(path, headers = {}, user = nil, password = nil) new_headers = STANDARD_HEADERS.merge(headers) params = Hash.new message = path.split('?').last auth_string = "#{user}:#{password}@" unless (user.nil? || password.nil?) WebMock.stub_request(:get, "#{@protocol}://#{auth_string}#{@host}:#{@port}#{path}"). with(:headers => new_headers). to_return({:body => "#{message}", :status => 200}, :headers => {}) end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rest_baby-0.5 | features/support/mock_rest_service.rb |