diff --git a/.rubocop.yml b/.rubocop.yml index 290e51f..0fd1fdb 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,6 +6,8 @@ AllCops: TargetRubyVersion: 2.3 Exclude: - lib/tasks/*.rake + - vendor/**/* + - tmp/**/* Bundler/DuplicatedGem: Enabled: false @@ -36,6 +38,9 @@ Style/Lambda: Style/LambdaCall: Enabled: false +Style/ModuleFunction: + Enabled: false + Style/RescueModifier: Exclude: - spec/**/*.rb diff --git a/.travis.yml b/.travis.yml index e4365d9..ca20c0a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,8 @@ language: ruby cache: bundler bundler_args: --without benchmarks tools script: - - bundle exec rake spec + - bundle exec rspec + - bundle exec rubocop rvm: - 2.3.8 - 2.4.6 @@ -11,7 +12,6 @@ rvm: - 2.6.3 - jruby-9.2.7.0 - jruby-9000 - - rbx-3 - ruby-head - truffleruby env: @@ -19,7 +19,6 @@ env: - JRUBY_OPTS='--dev -J-Xmx1024M' matrix: allow_failures: - - rvm: rbx-3 - rvm: ruby-head - rvm: jruby-head - rvm: truffleruby diff --git a/lib/dry/initializer/config.rb b/lib/dry/initializer/config.rb index 1000b9e..903e28e 100644 --- a/lib/dry/initializer/config.rb +++ b/lib/dry/initializer/config.rb @@ -142,7 +142,7 @@ def add_definition(option, name, type, block, **opts) source: name, type: type, block: block, - **opts, + **opts } options = Dispatchers.call(opts) diff --git a/lib/dry/initializer/struct.rb b/lib/dry/initializer/struct.rb index ab794b2..9d84673 100644 --- a/lib/dry/initializer/struct.rb +++ b/lib/dry/initializer/struct.rb @@ -8,7 +8,7 @@ class << self undef_method :param def new(options) - super Hash(options).transform_keys(&:to_sym) + super Hash(options).each_with_object({}) { |(k, v), h| h[k.to_sym] = v } end alias call new end @@ -22,8 +22,7 @@ def to_h .class .dry_initializer .attributes(self) - .transform_values { |v| __hashify(v) } - .stringify_keys + .each_with_object({}) { |(k, v), h| h[k.to_s] = __hashify(v) } end private diff --git a/spec/nested_type_spec.rb b/spec/nested_type_spec.rb index 1256dd3..db43431 100644 --- a/spec/nested_type_spec.rb +++ b/spec/nested_type_spec.rb @@ -18,6 +18,10 @@ class Test::Xyz it "builds the type" do expect(subject.x.y.z).to eq "42" end + + it "converts the nested type to hash" do + expect(subject.x.to_h).to eq("y" => { "z" => "42" }) + end end context "with nested and wrapped definitions" do diff --git a/spec/type_argument_spec.rb b/spec/type_argument_spec.rb index 69912b5..c78cbce 100644 --- a/spec/type_argument_spec.rb +++ b/spec/type_argument_spec.rb @@ -13,7 +13,7 @@ class Test::Foo subject { Test::Foo.new 1, bar: "2" } it "raises TypeError" do - expect { subject }.to raise_error TypeError, /1/ + expect { subject }.to raise_error Dry::Types::ConstraintError, /1/ end end @@ -21,7 +21,7 @@ class Test::Foo subject { Test::Foo.new "1", bar: 2 } it "raises TypeError" do - expect { subject }.to raise_error TypeError, /2/ + expect { subject }.to raise_error Dry::Types::ConstraintError, /2/ end end diff --git a/spec/type_constraint_spec.rb b/spec/type_constraint_spec.rb index 86f4364..9f2b40d 100644 --- a/spec/type_constraint_spec.rb +++ b/spec/type_constraint_spec.rb @@ -43,7 +43,7 @@ class Test::Foo subject { Test::Foo.new 1 } it "raises ArgumentError" do - expect { subject }.to raise_error TypeError, /1/ + expect { subject }.to raise_error Dry::Types::ConstraintError, /1/ end end diff --git a/spec/value_coercion_via_dry_types_spec.rb b/spec/value_coercion_via_dry_types_spec.rb index 20ee1b5..a963119 100644 --- a/spec/value_coercion_via_dry_types_spec.rb +++ b/spec/value_coercion_via_dry_types_spec.rb @@ -3,7 +3,7 @@ describe "value coercion via dry-types" do before do module Test::Types - include Dry::Types.module + include Dry.Types end class Test::Foo