Sha256: 0c9ef9feb9bd04eb2365258c3c4ba965de11d94352a5c9915f7cc07fa5110850

Contents?: true

Size: 1.82 KB

Versions: 3

Compression:

Stored size: 1.82 KB

Contents

require "rubygems"

require 'test/unit'
require 'mocha'
require 'shoulda'
require 'pp'

require File.dirname(__FILE__) + '/../lib/xeroizer.rb'

module TestHelper

  # The integration tests can be run against the Xero test environment.  You mush have a company set up in the test
  # environment, and you must have set up a customer key for that account.
  #
  # You can then run the tests against the test environment using the commands (linux or mac):
  # export STUB_XERO_CALLS=false  
  # rake test
  # (this probably won't work under OAuth?)
  #
  
  STUB_XERO_CALLS   = ENV["STUB_XERO_CALLS"].nil? ? true : (ENV["STUB_XERO_CALLS"] == "true") unless defined? STUB_XERO_CALLS
  
  CONSUMER_KEY      = ENV["CONSUMER_KEY"]     || "fake_key"     unless defined?(CONSUMER_KEY)
  CONSUMER_SECRET   = ENV["CONSUMER_SECRET"]  || "fake_secret"  unless defined?(CONSUMER_SECRET)
  PRIVATE_KEY_PATH  = ENV["PRIVATE_KEY_PATH"] || "fake_key"     unless defined?(PRIVATE_KEY_PATH)
  
  # Helper constant for checking regex
  GUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/ unless defined?(GUID_REGEX)

  def get_file_as_string(filename)
    File.read(File.dirname(__FILE__) + "/stub_responses/" + filename)
  end
  
  def get_record_xml(type, id = nil)
    if id.nil?
      get_file_as_string("#{type}.xml")
    else
      get_file_as_string("records/#{type}-#{id}.xml")
    end
  end
  
  def mock_api(model_name)
    @client.stubs(:http_get).with {|client, url, params| url =~ /#{model_name}$/ }.returns(get_record_xml("#{model_name.underscore.pluralize}".to_sym))
    @client.send("#{model_name.singularize}".to_sym).all.each do | record |
      @client.stubs(:http_get).with {|client, url, params| url =~ /#{model_name}\/#{record.id}$/ }.returns(get_record_xml("#{model_name.underscore.singularize}".to_sym, record.id))
    end
  end
    
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
xeroizer-0.1.3 test/test_helper.rb
xeroizer-0.1.2 test/test_helper.rb
xeroizer-0.1.0 test/test_helper.rb