$:.unshift File.expand_path('../../lib', __FILE__) require 'rubygems' require 'test/unit' require 'mocha' require 'shoulda' require 'ruby_psigate' module RubyPsigate # => Borrowed heavily from ActiveMerchant module Assertions AssertionClass = RUBY_VERSION > '1.9' ? MiniTest::Assertion : Test::Unit::AssertionFailedError def assert_success(response) clean_backtrace do assert response.success?, "Response failed: #{response.inspect}" end end private def clean_backtrace(&block) yield rescue AssertionClass => e path = File.expand_path(__FILE__) raise AssertionClass, e.message, e.backtrace.reject { |line| File.expand_path(line) =~ /#{path}/ } end end module ValidModelInstances def valid_address @address = Address.new @address.firstname = "Bob" @address.lastname = "Parsons" @address.line1 = "1234 West Street" @address.line2 = "Apt 100" @address.city = "Toronto" @address.province = "Ontario" @address.country = "CA" @address.postalcode = "L3N9J2" @address.telephone = "416-333-3333" @address.fax = "416-322-2222" @address.company = "Bob Parson's Co." @address end def valid_address_hash { :Bname => "Bob Parsons", :Bcompany => "Bob Parson's Co.", :Baddress1 => "1234 West Street", :Baddress2 => "Apt 100", :Bcity => "Toronto", :Bprovince => "Ontario", :Bcountry => "CA", :Bpostalcode => "L3N9J2", :Phone => "416-333-3333", :Fax => "416-322-2222" } end def valid_credit_card @valid_attributes = { :number => "4111111111111111", :month => "12", :year => "2020", :verification_value => "123", :name => "Bob John" } @cc = CreditCard.new(@valid_attributes) @cc end def valid_credit_card_hash(type = nil) @cc = valid_credit_card @cc.to_hash(type) end def valid_item @item1 = Item.new @item1.unique_id = "PSI-BOOK" @item1.desc = "XML Interface Doc" @item1.qty = 2 @item1.price = 10.00 @item1 end def valid_coupon @item2 = Item.new @item2.unique_id = "COUPON" @item2.desc = "10% discount" @item2.qty = 1 @item2.price = -2.00 @item2 end def valid_option(option_hash) @option = ItemOption.new(option_hash) @option end def valid_recurring_charge @valid_attributes = { :rbcid => "9999999999", :rbname => "Charge123", :interval => "M", :rbtrigger => "25", # Trigger date :status => "Active", :starttime => "2010.08.01", :endtime => "2015.12.31", :processtype => "A" } @recurring_charge = RecurringCharge.new(@valid_attributes) end def valid_recurring_charge_hash @recurring_charge = valid_recurring_charge @recurring_charge.to_hash end def valid_recurring_item @recurring_item = RecurringItem.new( :product_id => "Newspaper", :description => "Toronto Star", :quantity => "1", :price => "25.00", :tax1 => "2.00", :tax2 => "1.25" ) @recurring_item end def valid_recurring_item_hash valid_recurring_item.to_hash end end end Test::Unit::TestCase.class_eval do include RubyPsigate::Assertions include RubyPsigate::ValidModelInstances end