Sha256: 0a21e85565534b65e88744617597f684830eb7afb3d7c634837e8b4e66ed453f

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 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 = "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 => {})
        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    

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rest_baby-0.2 features/support/mock_rest_service.rb