-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathnested_type_spec.rb
50 lines (41 loc) · 1.08 KB
/
nested_type_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# frozen_string_literal: true
RSpec.describe "nested type argument" do
subject { Test::Xyz.new("bar" => {"baz" => 42}) }
context "with nested definition only" do
before do
class Test::Xyz
extend Dry::Initializer
param :foo, as: :x do
option :bar, as: :y do
option :baz, proc(&:to_s), as: :z
option :qux, as: :w, optional: true
end
end
end
end
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
before do
class Test::Xyz
extend Dry::Initializer
param :foo, [], as: :x do
option :bar, as: :y do
option :baz, proc(&:to_s), as: :z
option :qux, as: :w, optional: true
end
end
end
end
it "builds the type" do
x = subject.x
expect(x).to be_instance_of Array
expect(x.first.y.z).to eq "42"
end
end
end