test/configurations/test_stricter_configuration.rb in configurations-1.4.0 vs test/configurations/test_stricter_configuration.rb in configurations-2.0.0.pre
- old
+ new
@@ -1,20 +1,30 @@
require 'test_helper'
class TestStricterConfiguration < Minitest::Test
+ module StrictConfigurationTestModule
+ include Configurations
- StrictConfigurationTestModule = testmodule_for(Configurations)
- StrictConfigurationTestModule.module_eval do
configurable :property1, :property2
configurable String, :property3
configurable Symbol, property4: :property5, property6: [:property7, :property8]
configurable Fixnum, property6: :property14
configurable Fixnum, property4: :property12
configurable Array, property9: { property10: { property11: :property12 } }
configurable Hash, property9: { property10: { property11: :property13 } }
end
+ module StrictConfigurationTestModuleDefaultsError
+ include Configurations
+
+ configurable :property1, :property2
+
+ not_configured do |prop|
+ raise StandardError, 'Problem here'
+ end
+ end
+
def setup
StrictConfigurationTestModule.configure do |c|
c.property1 = 'BASIC1'
c.property2 = 'BASIC2'
c.property3 = 'STRING'
@@ -24,12 +34,16 @@
c.property6.property8 = :everything
c.property6.property14 = 555
c.property9.property10.property11.property12 = %w(here I am)
c.property9.property10.property11.property13 = { hi: :bye }
end
+ StrictConfigurationTestModuleDefaultsError.configure do |c|
+ c.property1 = 'BASIC3'
+ end
@configuration = StrictConfigurationTestModule.configuration
+ @configuration_defaults_error = StrictConfigurationTestModuleDefaultsError.configuration
end
def test_configurable_when_set_configurable
assert_equal 'BASIC1', @configuration.property1
assert_equal 'BASIC2', @configuration.property2
@@ -63,21 +77,21 @@
},
property6: {
property7: :anything,
property8: :everything,
property14: 555
- },
+ },
property9: {
property10: {
property11: {
- property12: %w(here I am),
+ property12: %w(here I am),
property13: {
hi: :bye
}
}
}
- },
+ },
property1: 'BASIC1',
property2: 'BASIC2',
property3: 'STRING'
}, @configuration.to_h)
end
@@ -122,26 +136,38 @@
c.property4 = {}
end
end
end
+ def test_respond_to_with_undefined_property
+ assert_equal false, @configuration.respond_to?(:property12)
+ end
+
def test_not_callable_with_undefined_property
assert_raises NoMethodError do
@configuration.property12
end
end
+ def test_not_configured_callback
+ assert_raises StandardError do
+ @configuration_defaults_error.property2
+ end
+ end
+
+ def test_not_configured_callback_not_triggered_for_configured
+ assert_equal 'BASIC3', @configuration_defaults_error.property1
+ end
+
def test_not_configurable_with_undefined_nested_property
assert_raises NoMethodError do
StrictConfigurationTestModule.configure do |c|
c.property6.property9 = {}
end
end
end
- def test_not_callable_with_undefined_nested_property
- assert_raises NoMethodError do
- @configuration.property6.property9
- end
+ def test_callable_with_undefined_nested_property
+ assert_nil @configuration.property6.property9
end
end