Sha256: c35e5cb86ca7e96fc1e28f01e2ff7c5eaa6277517c52b039c6d81878bb5d5fc8

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 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
    PowerTrack::Stream.new(
      powertrack_config[:username],
      powertrack_config[:password],
      powertrack_config[:account_name],
      powertrack_config[:data_source],
      powertrack_config[:stream_label])
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
powertrack-1.0.3 test/minitest_helper.rb
powertrack-1.0.2 test/minitest_helper.rb
powertrack-1.0.1 test/minitest_helper.rb
powertrack-1.0.0 test/minitest_helper.rb