Sha256: 7317f46b0b567d540f760d1a90728d0830c61accb1775ca7dec35f22967910d5

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

require 'test_helper'
require 'block_configurable'

class Configurable
  include BlockConfigurable

  config :value_with_default, 1
  config :value_without_default, nil
  config :value_to_change, 'a'
  config :value_to_test_hash, :test
end

module ConfigurableModule
  include BlockConfigurable

  config :value_with_default, 1
end

class BlockConfigurableTest < Minitest::Test
  attr_reader :configuration

  def setup
    @configuration = Configurable.configuration
  end

  def test_default_values
    assert_equal 1, configuration.value_with_default
    assert_nil configuration.value_without_default
  end

  def test_can_be_configured_with_block
    assert_equal 'a', configuration.value_to_change

    Configurable.configure do |c|
      c.value_to_change = 'b'
    end

    assert_equal 'b', configuration.value_to_change
  end

  def test_can_be_converted_to_hash
    assert_equal 4, configuration.to_hash.size
    assert_equal :test, configuration.to_h[:value_to_test_hash]
  end

  def test_can_be_included_in_a_module_too
    assert_equal 1, ConfigurableModule.configuration.value_with_default
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
block_configurable-0.9.0 test/block_configurable/block_configurable_test.rb