File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,8 @@ def each
25
25
end
26
26
27
27
def call
28
- ( select ( &:param? ) . map ( &:call ) + %w( **__options__ ) ) . compact . join ( ", " )
28
+ options = all? ( &:param? ) ? %w( __options__={} ) : %w( **__options__ )
29
+ ( select ( &:param? ) . map ( &:call ) + options ) . compact . join ( ", " )
29
30
end
30
31
31
32
private
Original file line number Diff line number Diff line change @@ -48,4 +48,36 @@ def default_mox
48
48
subject = Test ::Foo . new
49
49
expect ( subject . mox ) . to eql :MOX
50
50
end
51
+
52
+ describe "when the last param has a default and there are no options" do
53
+ before do
54
+ class Test ::Bar
55
+ extend Dry ::Initializer ::Mixin
56
+
57
+ param :foo
58
+ param :bar , default : proc { { } }
59
+ end
60
+ end
61
+
62
+ it "instantiate arguments" do
63
+ subject = Test ::Bar . new ( 1 , 2 )
64
+
65
+ expect ( subject . foo ) . to eql 1
66
+ expect ( subject . bar ) . to eql 2
67
+ end
68
+
69
+ it "applies default values" do
70
+ subject = Test ::Bar . new ( 1 )
71
+
72
+ expect ( subject . foo ) . to eql 1
73
+ expect ( subject . bar ) . to eql ( { } )
74
+ end
75
+
76
+ it "instantiate arguments also if the last is an hash" do
77
+ subject = Test ::Bar . new ( 1 , { baz : 2 , qux : 3 } )
78
+
79
+ expect ( subject . foo ) . to eql 1
80
+ expect ( subject . bar ) . to eql ( { baz : 2 , qux : 3 } )
81
+ end
82
+ end
51
83
end
You can’t perform that action at this time.
0 commit comments