Sha256: 8d677f8c06514542614561b4c73ea134689b1a880887b54ce8b88bcc9dfd93f2

Contents?: true

Size: 1.93 KB

Versions: 1

Compression:

Stored size: 1.93 KB

Contents

require 'test_helper'

class TestConfigurationMethods < Minitest::Test

  module ConfigurationMethodsClassModule
    include Configurations

    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

  module ConfigurationNoMethodsClassModule
    include Configurations

    configurable :property3
  end

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

    ConfigurationNoMethodsClassModule.configure do |c|
      c.property3 = :three
    end

    @configuration = ConfigurationMethodsClassModule.configuration
    @no_method_configuration = ConfigurationNoMethodsClassModule.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

  def test_configuration_methods_unaffected
    assert_raises NoMethodError do
      @no_method_configuration.method3('ARG')
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

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