Sha256: a691683d18ce46b12fde1d2e8e9ea330778086f9ee52410de651e30ed8577b62

Contents?: true

Size: 1.2 KB

Versions: 9

Compression:

Stored size: 1.2 KB

Contents

require "rspec/expectations"
require 'webmock/rspec'

require_relative '../lib/gerry'

class MockGerry < Gerry::Client
  URL = 'http://localhost'
  
  def initialize
    super(URL)
  end
end

def get_fixture(filename)
  return '' if filename.empty?
  file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
  File.read(file_path)
end

def stub_get(url, filename)
  body = get_fixture(filename)
  stub_request(:get, "#{MockGerry::URL}#{url}").
    to_return(:status => 200, :body => "#{body}", :headers => {'Content-Type' => 'application/json'})
end

def stub_put(url, body, response_body=nil)
  response = {
    status: 200,
    headers: {
      'Content-Type' => 'application/json'
    },
    body: response_body
  }
  stub_request(:put, "#{MockGerry::URL}#{url}").
    with(:body => body, :headers => { 'Content-Type' => 'application/json' }).
      to_return(response)
end

def stub_post(url, body, response_body=nil)
  response = {
    status: 200,
    headers: {
      'Content-Type' => 'application/json'
    },
    body: response_body
  }
  stub_request(:post, "#{MockGerry::URL}#{url}").
    with(:body => body, :headers => { 'Content-Type' => 'application/json' }).
      to_return(response)
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
gerry-0.1.6 spec/spec_helper.rb
gerry-0.1.5 spec/spec_helper.rb
gerry-0.1.4 spec/spec_helper.rb
gerry-0.1.3 spec/spec_helper.rb
gerry-0.1.2 spec/spec_helper.rb
gerry-0.1.1 spec/spec_helper.rb
gerry-0.1.0 spec/spec_helper.rb
gerry-0.0.4 spec/spec_helper.rb
gerry-0.0.3 spec/spec_helper.rb