Sha256: 15380fe3a8abfe624f3e3ac11b6df1e405b0c1d6ee01f78dde74d9f5e131e246

Contents?: true

Size: 1.57 KB

Versions: 6

Compression:

Stored size: 1.57 KB

Contents

require 'test_helper'

class TestConfigurationMethods < Minitest::Test

  ConfigurationMethodsClassModule = testmodule_for(Configurations)
  ConfigurationMethodsClassModule.module_eval do
    class MyClass
      attr_reader :props
      def initialize(*props)
        @props = props
      end
    end

    context = 'CONTEXT'
    configurable :property1, :property2
    configuration_method :method1 do
      MyClass.new(property1, property2)
    end
    configuration_method :method2 do
      context + property1.to_s
    end
    configuration_method :method3 do |arg|
      arg + property1.to_s
    end
    configuration_method :kernel_raise do
      raise StandardError, 'hell'
    end
  end

  def setup
    ConfigurationMethodsClassModule.configure do |c|
      c.property1 = :one
      c.property2 = :two
    end

    @configuration = ConfigurationMethodsClassModule.configuration
  end

  def test_configuration_method
    assert_equal [:one, :two], @configuration.method1.props
  end

  def test_configuration_method_with_context
    assert_equal 'CONTEXTone', @configuration.method2
  end

  def test_configuration_method_with_arguments
    assert_equal 'ARGone', @configuration.method3('ARG')
  end

  def test_kernel_methods_in_configuration_method
    assert_raises StandardError, 'hell' do
      @configuration.kernel_raise
    end
  end

  def test_configuration_method_overwrite
    assert_raises ArgumentError do
      ConfigurationMethodsClassModule.module_eval do
        configuration_method :property2 do |c|
          MyClass.new(c.property2)
        end
      end
    end
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
configurations-1.4.0 test/configurations/test_configuration_methods.rb
configurations-1.3.5 test/configurations/test_configuration_methods.rb
configurations-1.3.4 test/configurations/test_configuration_methods.rb
configurations-1.3.3 test/configurations/test_configuration_methods.rb
configurations-1.3.1 test/configurations/test_configuration_methods.rb
configurations-1.3.0 test/configurations/test_configuration_methods.rb