Sha256: 442aa8292c7d00e99e696b9cfb22c3069c88eeccdd96af3ae642e0543b9ae0d4

Contents?: true

Size: 1.67 KB

Versions: 4

Compression:

Stored size: 1.67 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 = File.join(File.dirname(__FILE__), '..', '..', '.oauth')

    return nil unless File.exist? 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["PRIVATE_KEY_PATH"], "No PRIVATE_KEY_PATH environment variable specified."
    assert File.exist?(ENV["PRIVATE_KEY_PATH"]), "The file <#{ENV["PRIVATE_KEY_PATH"]}> does not exist."
    Xeroizer::OAuthCredentials.new ENV["CONSUMER_KEY"], ENV["CONSUMER_SECRET"], ENV["PRIVATE_KEY_PATH"]
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
xeroizer-2.20.0 test/acceptance/acceptance_test.rb
xeroizer-2.19.0 test/acceptance/acceptance_test.rb
xeroizer-2.18.1 test/acceptance/acceptance_test.rb
xeroizer-2.17.1 test/acceptance/acceptance_test.rb