-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathrepetitive_definitions_spec.rb
71 lines (58 loc) · 1.48 KB
/
repetitive_definitions_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# frozen_string_literal: true
RSpec.describe "repetitive definitions" do
subject { Test::Foo.new }
context "of params" do
before do
class Test::Foo
extend Dry::Initializer
param :foo, default: proc { 0 }
param :bar, default: proc { 1 }
param :foo, default: proc { 2 }
end
end
it "reloads the attribute" do
expect(subject.foo).to eq 2
end
end
context "of options" do
before do
class Test::Foo
extend Dry::Initializer
option :foo, default: proc { 0 }
option :bar, default: proc { 1 }
option :foo, default: proc { 2 }
end
end
it "reloads the attribute" do
expect(subject.foo).to eq 2
end
end
context "of param and option" do
before do
class Test::Foo
extend Dry::Initializer
param :foo, default: proc { 0 }
option :bar, default: proc { 1 }
option :foo, default: proc { 2 }
end
end
it "reloads the attribute" do
expect(subject.foo).to eq 2
end
end
context "of optional param and option" do
before do
class Test::Foo
extend Dry::Initializer
param :baz, optional: true, as: :foo
option :bar, optional: true
option :foo, optional: true
end
end
it "allows various assignments" do
expect(Test::Foo.new(1).foo).to eq 1
expect(Test::Foo.new(foo: 2).foo).to eq 2
expect(Test::Foo.new(1, foo: 2).foo).to eq 2
end
end
end