Sha256: 44180ba3233863a50171b8cc0f28c6b832f1e39cbc509fb961c6fbdde09ff261
Contents?: true
Size: 1.32 KB
Versions: 1
Compression:
Stored size: 1.32 KB
Contents
require "test/unit" require_relative '../lib/smart_init/main' class TestService extend SmartInit initialize_with :attribute_1, :attribute_2 is_callable def call [attribute_1, attribute_2] end end class TestServiceDefaults extend SmartInit initialize_with :attribute_1, attribute_2: "default_value_2", attribute_3: "default_value_3" is_callable def call [attribute_1, attribute_2, attribute_3] end end class TestHashIntegerDefaults extend SmartInit initialize_with :attribute_1, attribute_2: 2 is_callable def call [attribute_1, attribute_2] end end class HashApiTest < Test::Unit::TestCase def test_keywords assert_equal TestService.call(attribute_1: "a", attribute_2: "b"), ["a", "b"] assert_raise ArgumentError do TestService.new( attribute_1: "a" ) end end def test_keywords_defaults assert_equal TestServiceDefaults.call(attribute_1: "a"), ["a", "default_value_2", "default_value_3"] assert_equal TestServiceDefaults.call(attribute_1: "a", attribute_2: "b"), ["a", "b", "default_value_3"] end def test_integer_defaults assert_equal TestHashIntegerDefaults.call(attribute_1: 1), [1, 2] end def test_missing_attributes assert_raise ArgumentError do TestService.call(attribute_1: "a", invalid_attribute: "b") end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
smart_init-3.1.0 | test/test_api.rb |