Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make config file path customizable

  • Loading branch information...
commit 6cdcc4f628c143618a7db571495ce9ba596c0303 1 parent 4460525
@vinibaggio authored
View
11 lib/rbraspag.rb
@@ -1,4 +1,8 @@
require 'singleton'
+require 'httpi'
+require 'nokogiri'
+require 'json'
+
require "rbraspag/version"
require 'rbraspag/connection'
require 'rbraspag/payment_method'
@@ -12,4 +16,11 @@
require 'rbraspag/order'
module Braspag
+ def self.config_file_path=(path)
+ @config_path = path
+ end
+
+ def self.config_file_path
+ @config_path || 'config/braspag.yml'
+ end
end
View
2  lib/rbraspag/connection.rb
@@ -10,7 +10,7 @@ class Connection
def initialize
raise InvalidEnv if ENV["RACK_ENV"].nil? || ENV["RACK_ENV"].empty?
- @options = YAML.load_file('config/braspag.yml')[ ENV['RACK_ENV'] ]
+ @options = YAML.load_file(Braspag.config_file_path)[ ENV['RACK_ENV'] ]
@merchant_id = @options['merchant_id']
raise InvalidMerchantId unless @merchant_id =~ /\{[a-z0-9]{8}-([a-z0-9]{4}-){3}[a-z0-9]{12}\}/i
View
22 spec/connection_spec.rb
@@ -26,6 +26,28 @@
@connection = Braspag::Connection.clone
end
+ context "changing default config file path" do
+ before :each do
+ @original_path = Braspag.config_file_path
+ end
+
+ after :each do
+ Braspag.config_file_path = @original_path
+ end
+
+ it "should read config from a different path when specified" do
+ connection = Braspag::Connection.clone
+
+ Braspag.config_file_path = '/some/crazy/path'
+
+ YAML.should_receive(:load_file).
+ with("/some/crazy/path").
+ and_return(braspag_config)
+
+ connection.instance
+ end
+ end
+
it "should read config/braspag.yml when alloc first instance" do
YAML.should_receive(:load_file)
.with("config/braspag.yml")
Please sign in to comment.
Something went wrong with that request. Please try again.