test/test_helper.rb in active_shipping-1.0.0.pre3 vs test/test_helper.rb in active_shipping-1.0.0.pre4
- old
+ new
@@ -3,14 +3,13 @@
require 'minitest/autorun'
require 'mocha/mini_test'
require 'timecop'
require 'active_shipping'
-require 'nokogiri'
require 'logger'
+require 'erb'
-
# 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
@@ -20,24 +19,33 @@
include ActiveShipping
end
module ActiveShipping::Test
module Credentials
+ class NoCredentialsFound < StandardError
+ def initialize(key)
+ super("No credentials were found for '#{key}'")
+ end
+ end
+
LOCAL_CREDENTIALS = ENV['HOME'] + '/.active_shipping/credentials.yml'
DEFAULT_CREDENTIALS = File.dirname(__FILE__) + '/credentials.yml'
def credentials(key)
- data = all_credentials[key] || raise(StandardError, "No credentials were found for '#{key}'")
+ data = all_credentials[key]
+ if data.nil? || data.all? { |k,v| v.nil? || v.empty? }
+ raise NoCredentialsFound.new(key)
+ end
data.symbolize_keys
end
private
def all_credentials
@@all_credentials ||= begin
[DEFAULT_CREDENTIALS, LOCAL_CREDENTIALS].inject({}) do |credentials, file_name|
if File.exist?(file_name)
- yaml_data = YAML.load(File.read(file_name)).symbolize_keys
+ yaml_data = YAML.load(ERB.new(File.read(file_name)).result(binding)).symbolize_keys
credentials.merge!(yaml_data)
end
credentials
end
end