test/test_helper.rb in xeroizer-2.20.0 vs test/test_helper.rb in xeroizer-3.0.0
- old
+ new
@@ -2,68 +2,73 @@
require 'test/unit'
require 'mocha'
require 'shoulda'
require 'pp'
+require 'pry'
require File.dirname(__FILE__) + '/../lib/xeroizer.rb'
-$: << File.join(File.dirname(__FILE__), "acceptance")
+$: << File.join(File.dirname(__FILE__), "acceptance")
module TestHelper
# The integration tests can be run against the Xero test environment. You must 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
+ # export STUB_XERO_CALLS=false
# rake test
# (this probably won't work under OAuth?)
#
$VERBOSE=nil
-
+
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)
-
+
+ CLIENT_ID = ENV["XERO_CLIENT_ID"] || "fake_client_id" unless defined?(CLIENT_ID)
+ CLIENT_SECRET = ENV["XERO_CLIENT_SECRET"] || "fake_client_secret" unless defined?(CLIENT_SECRET)
+ ACCESS_TOKEN = ENV["XERO_ACCESS_TOKEN"] || "fake_access_token" unless defined?(ACCESS_TOKEN)
+ TENANT_ID = ENV["XERO_TENANT_ID"] || "fake_tenant_id" unless defined?(TENANT_ID)
+
# 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 get_report_xml(report_type)
get_file_as_string("reports/#{report_type.underscore}.xml")
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_s.to_sym))
@client.send(model_name.singularize.to_s.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_s.to_sym, record.id))
end
end
-
+
def mock_report_api(report_type)
@client.stubs(:http_get).with { | client, url, params | url =~ /Reports\/#{report_type}$/ }.returns(get_report_xml(report_type))
end
-
end
Shoulda::Context::ClassMethods.class_eval do
%w{it must can}.each do |m|
alias_method m, :should
end
-
+
alias_method :must_eventually, :should_eventually
end