Sha256: 600b2d0591a2e9aaac7d90b263f20771cc2a05f0841addbbaa71a444b131c421

Contents?: true

Size: 1.29 KB

Versions: 1

Compression:

Stored size: 1.29 KB

Contents

require 'simplecov'
require 'coveralls'

SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter,
                        Coveralls::SimpleCov::Formatter]

SimpleCov.start

require 'json'
require 'rspec'
require 'webmock/rspec'
require 'postmates'

RSpec.configure do |config|
  config.expect_with(:rspec) { |c| c.syntax = :expect }
end

WebMock.disable_net_connect!(allow: 'coveralls.io')

def postmates_test_client
  Postmates.new.tap do |client|
    client.configure do |config|
      config.api_key = '1234'
      config.customer_id = 'abcd'
    end
  end
end

HTTP_REQUEST_METHODS = [:get, :post]

HTTP_REQUEST_METHODS.each do |verb|
  Object.send(:define_method, "stub_#{verb}") do |path, options = {}|
    file = options.delete(:returns)
    code = options.delete(:response_code) || 200
    endpoint = 'https://1234:@api.postmates.com/v1/' + path
    headers  = Postmates::Configuration::DEFAULT_HEADERS
    stub_request(verb, endpoint)
      .with(headers: headers, body: options)
      .to_return(body: fixture(file), status: code)
  end
end

def fixture_path
  File.expand_path('../fixtures', __FILE__)
end

def fixture(file)
  File.new(fixture_path + '/' + file)
end

def payload(params_file)
  JSON.parse(IO.read(fixture(params_file)))
end

def path_to(endpoint)
  "customers/#{customer_id}/#{endpoint}"
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
postmates-0.1.0 spec/spec_helper.rb