Sha256: ae7cf2bc096935a9615be4c2033160beaaf0203a79cf3d36bb81b23d7fac56e8

Contents?: true

Size: 1.58 KB

Versions: 2

Compression:

Stored size: 1.58 KB

Contents

module AcceptanceTest
  class << self
    def included(klass)
      klass.class_eval do
        def self.log_to_console
          Xeroizer::Logging.const_set :Log, Xeroizer::Logging::StdOutLog
        end

        def self.no_log
          Xeroizer::Logging.const_set :Log, Xeroizer::Logging::DevNullLog
        end

        def self.let(symbol, &block)
          return unless block_given?

          unless respond_to? symbol
            define_method symbol, do
              cached_method_result = instance_variable_get ivar_name = "@#{symbol}"
              instance_variable_set(ivar_name, instance_eval(&block)) if cached_method_result.nil?
              instance_variable_get ivar_name
            end
          end
        end
      end
    end
  end

  def setup
    config = load_config_from_file || load_config_from_env

    @key_file = config.key_file
    @consumer_key = config.consumer_key
    @consumer_secret = config.consumer_secret
  end

  private

  def load_config_from_file
    the_file_name = ".oauth"

    return nil unless File.exists? the_file_name

    Xeroizer::OAuthConfig.load IO.read the_file_name
  end

  def load_config_from_env
    assert_not_nil ENV["CONSUMER_KEY"], "No CONSUMER_KEY environment variable specified."
    assert_not_nil ENV["CONSUMER_SECRET"], "No CONSUMER_SECRET environment variable specified."
    assert_not_nil ENV["KEY_FILE"], "No KEY_FILE environment variable specified."
    assert File.exists?(ENV["KEY_FILE"]), "The file <#{ENV["KEY_FILE"]}> does not exist."
    OAuthCredentials.new ENV["CONSUMER_KEY"], ENV["CONSUMER_SECRET"], ENV["KEY_FILE"]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
xeroizer-0.4.1 test/acceptance/acceptance_test.rb
xeroizer-0.4.0 test/acceptance/acceptance_test.rb