Sha256: a500a494dc1574443c4bdb9b97fc89d4911e0ce42d2f6e97b884002ff552aab8

Contents?: true

Size: 1.22 KB

Versions: 3

Compression:

Stored size: 1.22 KB

Contents

gem 'minitest'
require 'minitest/autorun'
require 'yaml'

class Minitest::Test

  POWERTRACK_CONFIG_FILEPATH = File.join(File.dirname(__FILE__), "powertrack.yml")

  # Returns the PowerTrack configuration as defined in test/powertrack.yml.
  def powertrack_config
    unless defined?(@loaded) && @loaded
      begin
        if File.exist?(POWERTRACK_CONFIG_FILEPATH)
          @pwtk_config = (YAML.load_file(POWERTRACK_CONFIG_FILEPATH) || {})
        else
          $stderr.puts "No PowerTrack config file found at '#{POWERTRACK_CONFIG_FILEPATH}'"
        end
      rescue Exception
        $stderr.puts "Exception while loading PowerTrack config file: #{$!.message}"
      ensure
        @pwtk_config ||= {}
      end

      # symbolize keys
      @pwtk_config = Hash[@pwtk_config.map{ |k, v| [k.to_sym, v] }]
      @loaded = true
    end

    @pwtk_config
  end

  # Returns a brand-new stream based on the config found in test/powertrack.yml.
  def new_stream(replay=false)
    PowerTrack::Stream.new(
      powertrack_config[:username],
      powertrack_config[:password],
      powertrack_config[:account_name],
      powertrack_config[:data_source],
      replay ? 'prod' : powertrack_config[:stream_label],
      replay: replay)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
powertrack-2.0.0 test/minitest_helper.rb
powertrack-1.1.1 test/minitest_helper.rb
powertrack-1.1.0 test/minitest_helper.rb