Sha256: 41e380c269c082f3e1e895c86fa89aa0fcdbe47226e56264d37403f204066b03

Contents?: true

Size: 1.17 KB

Versions: 14

Compression:

Stored size: 1.17 KB

Contents

require 'fileutils'
require 'test/unit'

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

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.exists?(@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
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
cliutils-1.2.3 test/configurator_test.rb
cliutils-1.2.2 test/configurator_test.rb
cliutils-1.2.1 test/configurator_test.rb
cliutils-1.2.0 test/configurator_test.rb
cliutils-1.1.1 test/configurator_test.rb
cliutils-1.1.0 test/configurator_test.rb
cliutils-1.0.7 test/configurator_test.rb
cliutils-1.0.6 test/configurator_test.rb
cliutils-1.0.5 test/configurator_test.rb
cliutils-1.0.4 test/configurator_test.rb
cliutils-1.0.3 test/configurator_test.rb
cliutils-1.0.2 test/configurator_test.rb
cliutils-1.0.1 test/configurator_test.rb
cliutils-1.0.0 test/configurator_test.rb