-
-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathinvalid_default_spec.rb
More file actions
87 lines (67 loc) · 1.72 KB
/
invalid_default_spec.rb
File metadata and controls
87 lines (67 loc) · 1.72 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# frozen_string_literal: true
RSpec.describe "invalid default value assignment" do
shared_examples "it has a TypeError" do
it "raises TypeError" do
expect { subject }.to raise_error TypeError
end
end
subject do
class Test::Foo
extend Dry::Initializer
param :foo, default: 1
end
end
it_behaves_like "it has a TypeError"
context "when default is a lambda one attribute with splat operator" do
subject do
class Test::Foo
extend Dry::Initializer
param :foo, default: ->(a) { a.to_i }
end
end
it_behaves_like "it has a TypeError"
end
context "when default is a proc with attributes" do
subject do
class Test::Foo
extend Dry::Initializer
param :foo, default: proc { |a| a.to_i }
end
end
it_behaves_like "it has a TypeError"
end
context "when default is a callable with attributes" do
subject do
class Test::Callbale
def self.call(a)
a.to_i
end
end
class Test::Foo
extend Dry::Initializer
param :foo, default: Test::Callbale
end
end
it_behaves_like "it has a TypeError"
end
context "when default is a proc with multiple attributes" do
subject do
class Test::Foo
extend Dry::Initializer
param :foo, default: proc { |a, *b| a.to_i }
end
end
it_behaves_like "it has a TypeError"
end
context "when default is a lambda one attribute with splat operator" do
subject do
class Test::Foo
extend Dry::Initializer
param :foo, default: ->(*a) { a.size }
end
end
it "does not raise TypeError" do
expect { subject }.not_to raise_error
end
end
end