Sha256: 5c5decd86df6644cb070dac5a38793c82460f812ba7fbe64ad99c66a76ec6749

Contents?: true

Size: 1.5 KB

Versions: 4

Compression:

Stored size: 1.5 KB

Contents

require 'fileutils'
require 'test_helper'

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

# Tests for the Configurator class
class TestConfigurator < Test::Unit::TestCase
  def setup
    @config_path = '/tmp/test.config'
    @config = CLIUtils::Configurator.new(@config_path)
  end

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

  def test_add_section
    @config.add_section(:test)
    assert_equal(@config.data, test: {})
  end

  def test_delete_section
    @config.add_section(:test)
    @config.add_section(:test2)
    @config.delete_section(:test)
    assert_equal(@config.data, test2: {})
  end

  def test_accessing
    @config.add_section(:test)
    @config.data[:test].merge!(name: 'Bob')
    assert_equal(@config.test, name: 'Bob')
  end

  def test_reset
    @config.add_section(:test)
    @config.data[:test].merge!(name: 'Bob')
    @config.reset
    assert_equal(@config.data, {})
  end

  def test_save
    @config.add_section(:section1)
    @config.section1.merge!(a: 'test', b: 'test')
    @config.save

    File.open(@config_path, 'r') do |f|
      assert_output("---\nsection1:\n  a: test\n  b: test\n") { puts f.read }
    end
  end
  
  def test_compare_version
    @config.add_section(:app_data)
    @config.app_data.merge!({ VERSION: '1.0.0' })

    @config.current_version = @config.app_data['VERSION']
    @config.last_version = '1.0.8'

    @config.compare_version do |c, l|
      assert_output('true') { print 'true' }
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cliutils-2.0.3 test/configurator_test.rb
cliutils-2.0.2 test/configurator_test.rb
cliutils-2.0.1 test/configurator_test.rb
cliutils-2.0.0 test/configurator_test.rb