/
config_spec.rb
153 lines (120 loc) · 4.32 KB
/
config_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# typed: true
# frozen_string_literal: true
require "spec_helper"
module Tapioca
class ConfigTest < SpecWithProject
describe "cli::configuration" do
before(:all) do
@project.bundle_install
end
after do
@project.remove("sorbet/rbi")
end
it "validates unknown configuration keys" do
@project.write("sorbet/tapioca/config.yml", <<~YAML)
foo: true
bar:
- 1
- 2
gem:
doc: true
dsl:
typed_overrides:
foo: "true"
YAML
result = @project.tapioca("gem")
assert_equal(<<~ERR, result.err)
Configuration file sorbet/tapioca/config.yml has the following errors:
- unknown key foo
- unknown key bar
- unknown key typed_overrides
ERR
assert_empty_stdout(result)
refute_success_status(result)
end
it "validates unknown configuration key options" do
@project.write("sorbet/tapioca/config.yml", <<~YAML)
gem:
doc: true
foo: 1
dsl:
bar: []
YAML
result = @project.tapioca("gem")
assert_equal(<<~ERR, result.err)
Configuration file sorbet/tapioca/config.yml has the following errors:
- unknown option foo for key gem
- unknown option bar for key dsl
ERR
assert_empty_stdout(result)
refute_success_status(result)
end
it "validates invalid configuration option values" do
@project.write("sorbet/tapioca/config.yml", <<~YAML)
gem:
doc: "true"
typed_overrides:
- "true"
- "false"
workers: "foo"
dsl:
exclude: true
YAML
result = @project.tapioca("gem")
assert_equal(<<~ERR, result.err)
Configuration file sorbet/tapioca/config.yml has the following errors:
- invalid value for option doc for key gem - expected Boolean but found String
- invalid value for option typed_overrides for key gem - expected Hash but found Array
- invalid value for option workers for key gem - expected Numeric but found String
- invalid value for option exclude for key dsl - expected Array but found Boolean
ERR
assert_empty_stdout(result)
refute_success_status(result)
end
it "validates invalid configuration option values inside arrays and hashes" do
@project.write("sorbet/tapioca/config.yml", <<~YAML)
dsl:
only: [1, false]
exclude: [1, false]
gem:
exclude: [1, false]
typed_overrides:
msgpack: false
YAML
result = @project.tapioca("gem")
assert_equal(<<~ERR, result.err)
Configuration file sorbet/tapioca/config.yml has the following errors:
- invalid value for option only for key dsl - expected Array[String] but found [1, false]
- invalid value for option exclude for key dsl - expected Array[String] but found [1, false]
- invalid value for option exclude for key gem - expected Array[String] but found [1, false]
- invalid value for option typed_overrides for key gem - expected Hash[String, String] but found {\"msgpack\"=>false}
ERR
assert_empty_stdout(result)
refute_success_status(result)
end
it "validates unknown configuration keys, options, and invalid values" do
@project.write("sorbet/tapioca/config.yml", <<~YAML)
gem:
doc: true
foo: 1
typed_overrides: []
dsl:
bar: []
exclude: true
typed_overrides:
YAML
result = @project.tapioca("gem")
assert_equal(<<~ERR, result.err)
Configuration file sorbet/tapioca/config.yml has the following errors:
- unknown option foo for key gem
- invalid value for option typed_overrides for key gem - expected Hash but found Array
- unknown option bar for key dsl
- invalid value for option exclude for key dsl - expected Array but found Boolean
- unknown key typed_overrides
ERR
assert_empty_stdout(result)
refute_success_status(result)
end
end
end
end