lib/fake_braintree.rb in fake_braintree-0.6.0 vs lib/fake_braintree.rb in fake_braintree-0.7.0
- old
+ new
@@ -1,34 +1,29 @@
require 'braintree'
-require 'capybara'
-require 'digest/md5'
require 'fileutils'
-require 'active_support/core_ext'
-require 'sinatra/base'
+require 'active_support'
+require 'active_support/core_ext/module/attribute_accessors'
-require 'fake_braintree/helpers'
-require 'fake_braintree/customer'
-require 'fake_braintree/subscription'
-require 'fake_braintree/redirect'
-require 'fake_braintree/credit_card'
-require 'fake_braintree/address'
-
+require 'fake_braintree/version'
require 'fake_braintree/registry'
require 'fake_braintree/server'
-require 'fake_braintree/sinatra_app'
-require 'fake_braintree/valid_credit_cards'
-require 'fake_braintree/version'
module FakeBraintree
mattr_accessor :registry, :verify_all_cards, :decline_all_cards
- def self.activate!
+ # Public: Prepare FakeBraintree for use and start the API server.
+ #
+ # options: Hash options to configure (default: {}):
+ # :gateway_port - The port to start the API server on (optional).
+ # If not given, an ephemeral port will be used.
+ #
+ def self.activate!(options = {})
initialize_registry
self.verify_all_cards = false
- set_configuration
clear!
- boot_server
+ set_configuration
+ boot_server(port: options.fetch(:gateway_port, nil))
end
def self.log_file_path
'tmp/log'
end
@@ -111,18 +106,18 @@
def self.set_configuration
Braintree::Configuration.environment = :development
Braintree::Configuration.merchant_id = 'xxx'
Braintree::Configuration.public_key = 'xxx'
Braintree::Configuration.private_key = 'xxx'
+ Braintree::Configuration.logger = Logger.new(log_file_path)
end
- def self.boot_server
- Server.new.boot
+ def self.boot_server(options = {})
+ server = Server.new(options)
+ server.boot
+ ENV['GATEWAY_PORT'] = server.port.to_s
end
def self.initialize_registry
self.registry = Registry.new
end
end
-
-FakeBraintree.activate!
-Braintree::Configuration.logger = Logger.new(FakeBraintree.log_file_path)