lib/fake_braintree.rb in fake_braintree-0.0.2 vs lib/fake_braintree.rb in fake_braintree-0.0.3
- old
+ new
@@ -1,13 +1,12 @@
+require 'fileutils'
require 'braintree'
require 'sham_rack'
require 'fake_braintree/sinatra_app'
require 'fake_braintree/version'
-Braintree::Configuration.logger = Logger.new("tmp/log")
-
module FakeBraintree
class << self
@customers = {}
@subscriptions = {}
@failures = {}
@@ -24,18 +23,28 @@
Braintree::Configuration.private_key = "xxx"
clear!
ShamRack.mount(FakeBraintree::SinatraApp, "www.braintreegateway.com", 443)
end
+ def self.log_file_path
+ 'tmp/log'
+ end
+
def self.clear!
self.customers = {}
self.subscriptions = {}
self.failures = {}
self.transaction = {}
self.decline_all_cards = false
+ clear_log!
end
+ def self.clear_log!
+ FileUtils.mkdir_p(File.dirname(log_file_path))
+ File.new(log_file_path, 'w').close
+ end
+
def self.failure?(card_number)
self.failures.include?(card_number)
end
def self.failure_response(card_number)
@@ -159,5 +168,6 @@
"gateway_rejection_reason"=>nil}
end
end
FakeBraintree.activate!
+Braintree::Configuration.logger = Logger.new(FakeBraintree.log_file_path)