Sha256: d1f7d283dca8b9328289bdfe6e8788d95e9f72cd88c95524176951c5b5185af4

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

require 'test_helper'

require File.join(File.dirname(__FILE__), '..', 'lib/cliutils/configurator')
require File.join(File.dirname(__FILE__), '..', 'lib/cliutils/configuration')

# Tests for the Configurator class
class TestConfiguration < Test::Unit::TestCase
  include CLIUtils::Configuration

  def setup
    @config_path = '/tmp/test.config'
    @expected_config_data = {
      my_app: {
        config_location: '/Users/bob/.my-app-config',
        log_level: 'WARN',
        version: '1.0.0'
      },
      user_data: {
        username: 'bob',
        age: 45
      }
    }
  end

  def teardown
    FileUtils.rm(@config_path) if File.file?(@config_path)
  end

  def test_before_loading
    assert_raise RuntimeError do
      configuration
    end
  end

  def test_empty_configuration
    load_configuration(@config_path)
    assert_equal(configuration.class, CLIUtils::Configurator)
    assert_equal(configuration.config_path, @config_path)
    assert_equal(configuration.data, {})
  end

  def test_existing_configuration
    FileUtils.cp(File.join(File.dirname(__FILE__), '..', 'test/test_files/configuration.yaml'), @config_path)
    load_configuration(@config_path)
    assert_equal(configuration.class, CLIUtils::Configurator)
    assert_equal(configuration.config_path, @config_path)
    assert_equal(configuration.data, @expected_config_data)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
cliutils-2.1.4 test/configuration_test.rb
cliutils-2.1.3 test/configuration_test.rb
cliutils-2.1.2 test/configuration_test.rb