test/test_helper.rb in activemerchant-1.4.2 vs test/test_helper.rb in activemerchant-1.5.0
- old
+ new
@@ -1,24 +1,15 @@
#!/usr/bin/env ruby
$:.unshift(File.dirname(__FILE__) + '/../lib')
-$:.unshift(File.dirname(__FILE__) + '/mocks')
-$:.unshift(File.dirname(__FILE__) + '/extra')
+require 'active_merchant'
require 'rubygems'
require 'money'
-require 'yaml'
-require 'net/http'
-require 'net/https'
require 'test/unit'
-require 'binding_of_caller'
-require 'breakpoint'
-require 'openssl'
require 'mocha'
-require 'digest/md5'
+require 'yaml'
-require File.dirname(__FILE__) + '/../lib/active_merchant'
-
begin
gem 'actionpack'
rescue LoadError
raise StandardError, "The view tests need ActionPack installed as gem to run"
end
@@ -37,10 +28,12 @@
end
module ActiveMerchant
module Assertions
+ AssertionClass = RUBY_VERSION > '1.9' ? MiniTest::Assertion : Test::Unit::AssertionFailedError
+
def assert_field(field, value)
clean_backtrace do
assert_equal value, @helper.fields[field]
end
end
@@ -99,94 +92,93 @@
end
end
private
def clean_backtrace(&block)
- yield
- rescue Test::Unit::AssertionFailedError => e
+ yield
+ rescue AssertionClass => e
path = File.expand_path(__FILE__)
- raise Test::Unit::AssertionFailedError, e.message, e.backtrace.reject { |line| File.expand_path(line) =~ /#{path}/ }
+ raise AssertionClass, e.message, e.backtrace.reject { |line| File.expand_path(line) =~ /#{path}/ }
end
end
-end
+
+ module Fixtures
+ HOME_DIR = RUBY_PLATFORM =~ /mswin32/ ? ENV['HOMEPATH'] : ENV['HOME'] unless defined?(HOME_DIR)
+ LOCAL_CREDENTIALS = File.join(HOME_DIR.to_s, '.active_merchant/fixtures.yml') unless defined?(LOCAL_CREDENTIALS)
+ DEFAULT_CREDENTIALS = File.join(File.dirname(__FILE__), 'fixtures.yml') unless defined?(DEFAULT_CREDENTIALS)
+
+ private
+ def credit_card(number = '4242424242424242', options = {})
+ defaults = {
+ :number => number,
+ :month => 9,
+ :year => Time.now.year + 1,
+ :first_name => 'Longbob',
+ :last_name => 'Longsen',
+ :verification_value => '123',
+ :type => 'visa'
+ }.update(options)
-module Test
- module Unit
- class TestCase
- HOME_DIR = RUBY_PLATFORM =~ /mswin32/ ? ENV['HOMEPATH'] : ENV['HOME'] unless defined?(HOME_DIR)
- LOCAL_CREDENTIALS = File.join(HOME_DIR.to_s, '.active_merchant/fixtures.yml') unless defined?(LOCAL_CREDENTIALS)
- DEFAULT_CREDENTIALS = File.join(File.dirname(__FILE__), 'fixtures.yml') unless defined?(DEFAULT_CREDENTIALS)
+ Billing::CreditCard.new(defaults)
+ end
+
+ def check(options = {})
+ defaults = {
+ :name => 'Jim Smith',
+ :routing_number => '244183602',
+ :account_number => '15378535',
+ :account_holder_type => 'personal',
+ :account_type => 'checking',
+ :number => '1'
+ }.update(options)
- include ActiveMerchant::Billing
- include ActiveMerchant::Assertions
- include ActiveMerchant::Utils
-
- private
- def credit_card(number = '4242424242424242', options = {})
- defaults = {
- :number => number,
- :month => 9,
- :year => Time.now.year + 1,
- :first_name => 'Longbob',
- :last_name => 'Longsen',
- :verification_value => '123',
- :type => 'visa'
- }.update(options)
-
- CreditCard.new(defaults)
- end
+ Billing::Check.new(defaults)
+ end
+
+ def address(options = {})
+ {
+ :name => 'Jim Smith',
+ :address1 => '1234 My Street',
+ :address2 => 'Apt 1',
+ :company => 'Widgets Inc',
+ :city => 'Ottawa',
+ :state => 'ON',
+ :zip => 'K1C2N6',
+ :country => 'CA',
+ :phone => '(555)555-5555',
+ :fax => '(555)555-6666'
+ }.update(options)
+ end
+
+ def all_fixtures
+ @@fixtures ||= load_fixtures
+ end
+
+ def fixtures(key)
+ data = all_fixtures[key] || raise(StandardError, "No fixture data was found for '#{key}'")
- def check(options = {})
- defaults = {
- :name => 'Jim Smith',
- :routing_number => '244183602',
- :account_number => '15378535',
- :account_holder_type => 'personal',
- :account_type => 'checking',
- :number => '1'
- }.update(options)
+ data.dup
+ end
- Check.new(defaults)
- end
+ def load_fixtures
+ file = File.exists?(LOCAL_CREDENTIALS) ? LOCAL_CREDENTIALS : DEFAULT_CREDENTIALS
+ yaml_data = YAML.load(File.read(file))
+ symbolize_keys(yaml_data)
+
+ yaml_data
+ end
+
+ def symbolize_keys(hash)
+ return unless hash.is_a?(Hash)
- def address(options = {})
- {
- :name => 'Jim Smith',
- :address1 => '1234 My Street',
- :address2 => 'Apt 1',
- :company => 'Widgets Inc',
- :city => 'Ottawa',
- :state => 'ON',
- :zip => 'K1C2N6',
- :country => 'CA',
- :phone => '(555)555-5555',
- :fax => '(555)555-6666'
- }.update(options)
- end
-
- def all_fixtures
- @@fixtures ||= load_fixtures
- end
-
- def fixtures(key)
- data = all_fixtures[key] || raise(StandardError, "No fixture data was found for '#{key}'")
-
- data.dup
- end
-
- def load_fixtures
- file = File.exists?(LOCAL_CREDENTIALS) ? LOCAL_CREDENTIALS : DEFAULT_CREDENTIALS
- yaml_data = YAML.load(File.read(file))
- symbolize_keys(yaml_data)
-
- yaml_data
- end
-
- def symbolize_keys(hash)
- return unless hash.is_a?(Hash)
-
- hash.symbolize_keys!
- hash.each{|k,v| symbolize_keys(v)}
- end
+ hash.symbolize_keys!
+ hash.each{|k,v| symbolize_keys(v)}
end
end
+end
+
+Test::Unit::TestCase.class_eval do
+ include ActiveMerchant::Billing
+ include ActiveMerchant::Assertions
+ include ActiveMerchant::Utils
+ include ActiveMerchant::Fixtures
end