Sha256: e49bf02fa294ed3e1d2207ab38c9669dfa2c2a43e7a557b4b39257618ac8e450

Contents?: true

Size: 1.51 KB

Versions: 1

Compression:

Stored size: 1.51 KB

Contents

require 'test_helper'

class TestStricterConfigurationWithBlock < Minitest::Test

  module BlocksConfigurationTestModule
    include Configurations
    configurable :property1, :property2 do |value|
      value.to_s + 'oooh'
    end
    configurable String, :property3, property4: [:property5, :property6] do |value|
      raise ArgumentError, 'TEST2' unless %w(hello bye).include?(value)
      value
    end
  end

  def setup
    BlocksConfigurationTestModule.configure do |c|
      c.property1 = :one
      c.property2 = :two
      c.property3 = 'hello'
      c.property4.property5 = 'hello'
      c.property4.property6 = 'bye'
    end

    @configuration = BlocksConfigurationTestModule.configuration
  end

  def test_configurable_when_set_configurable_with_block
    assert_equal 'oneoooh', @configuration.property1
    assert_equal 'twooooh', @configuration.property2
  end

  def test_nested_configurable_when_set_configurable_with_block
    assert_equal 'hello', @configuration.property4.property5
    assert_equal 'bye', @configuration.property4.property6
  end

  def test_evaluates_block_after_type_assertion
    assert_raises Configurations::ConfigurationError, 'TEST2' do
      BlocksConfigurationTestModule.configure do |c|
        c.property4.property5 = :bla
      end
    end
  end

  def test_evaluates_block_for_nested_properties_when_set_configurable_with_block
    assert_raises ArgumentError, 'TEST2' do
      BlocksConfigurationTestModule.configure do |c|
        c.property4.property5 = 'oh'
      end
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
configurations-2.0.0.pre test/configurations/test_configurable_with_blocks_configuration.rb