Skip to content

Commit

Permalink
Add shared spec helper with credentials loading function
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcin Kot committed Oct 15, 2014
1 parent fc744a5 commit c579921
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
8 changes: 4 additions & 4 deletions spec/cim_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

describe AuthorizeNet::CIM::Transaction do

let(:api_key) { CREDENTIALS['api_transaction_key'] }
let(:api_login) { CREDENTIALS['api_login_id'] }
let(:api_key) { credentials['api_transaction_key'] }
let(:api_login) { credentials['api_login_id'] }
let(:chrs) { [('a'..'z'),('A'..'Z'),('0'..'9')].map(&:to_a).flatten }
let(:gateway) { :sandbox }
let(:credit_card) { AuthorizeNet::CreditCard.new('4111111111111111', '01' + (Time.now + (3600 * 24 * 365)).strftime('%y')) }
Expand Down Expand Up @@ -442,8 +442,8 @@ def create_address(address, profile)
end

describe AuthorizeNet::CIM::Response do
let(:api_key) { CREDENTIALS['api_transaction_key'] }
let(:api_login) { CREDENTIALS['api_login_id'] }
let(:api_key) { credentials['api_transaction_key'] }
let(:api_login) { credentials['api_login_id'] }

it "should support instantiation" do
expect(AuthorizeNet::CIM::Response.new('', nil)).to be_instance_of(AuthorizeNet::CIM::Response)
Expand Down
10 changes: 3 additions & 7 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
require "authorize_net"
require "yaml"

Dir['./spec/support/**/*.rb'].each{ |f| require f }

RSpec.configure do |config|
config.before(:suite) do
begin
CREDENTIALS = YAML.load_file(File.dirname(__FILE__) + "/credentials.yml")
rescue Errno::ENOENT
warn "WARNING: Running w/o valid AuthorizeNet sandbox credentials. Create spec/credentials.yml."
end
end
config.include SharedHelper
end
7 changes: 7 additions & 0 deletions spec/support/shared_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module SharedHelper
def credentials
$credentials ||= YAML.load_file(File.dirname(__FILE__) + "/../credentials.yml")
rescue Errno::ENOENT
warn "WARNING: Running w/o valid AuthorizeNet sandbox credentials. Create spec/credentials.yml."
end
end

0 comments on commit c579921

Please sign in to comment.