Sha256: 5e8d11b2f8d2879b8c17a139c41d6138c28b3f1ac4acdde1afc97bdc635c79a1

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

require 'test/unit'
require 'pathname'

require 'shoulda'
require 'matchy'
require 'mocha/setup'
require 'fakeweb'

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'createsend'

FakeWeb.allow_net_connect = false

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

def createsend_url(api_key, url)
  api_key.nil? ? url : url =~ /^http/ ? url : "https://#{api_key}:x@api.createsend.com/api/v3/#{url}"
end

def stub_request(method, api_key, url, filename, status=nil)
  options = {:body => ""}
  options.merge!({:body => fixture_file(filename)}) if filename
  options.merge!({:status => status}) if status
  options.merge!(:content_type => "application/json; charset=utf-8")
  FakeWeb.register_uri(method, createsend_url(api_key, url), options)
end

def stub_get(*args); stub_request(:get, *args) end
def stub_post(*args); stub_request(:post, *args) end
def stub_put(*args); stub_request(:put, *args) end
def stub_delete(*args); stub_request(:delete, *args) end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
createsend-2.5.1 test/helper.rb