/
test_helper.rb
45 lines (34 loc) · 1.22 KB
/
test_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
require 'bundler/setup'
require 'active_fulfillment'
require 'minitest/autorun'
require 'mocha/setup'
require 'timecop'
require 'pry'
require 'logger'
ActiveFulfillment::Service.logger = Logger.new(nil)
# This makes sure that Minitest::Test exists when an older version of Minitest
# (i.e. 4.x) is required by ActiveSupport.
unless defined?(Minitest::Test)
Minitest::Test = MiniTest::Unit::TestCase
end
module ActiveFulfillment::Test
module Fixtures
LOCAL_CREDENTIALS = ENV['HOME'] + '/.active_fulfillment/fixtures.yml' unless defined?(LOCAL_CREDENTIALS)
DEFAULT_CREDENTIALS = File.dirname(__FILE__) + '/fixtures.yml' unless defined?(DEFAULT_CREDENTIALS)
def fixtures(key)
data = all_fixtures[key] || raise(StandardError, "No fixture data was found for '#{key}'")
data.dup
end
def xml_fixture(path) # where path is like 'usps/beverly_hills_to_ottawa_response'
File.read(File.join(File.dirname(__FILE__),'fixtures','xml',"#{path}.xml"))
end
private
def all_fixtures
@@fixtures ||= load_fixtures
end
def load_fixtures
file = File.exists?(LOCAL_CREDENTIALS) ? LOCAL_CREDENTIALS : DEFAULT_CREDENTIALS
YAML.load(File.read(file)).deep_symbolize_keys
end
end
end