clamp 1.3.2 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -30,27 +30,41 @@ describe Clamp::Help::Builder do
30
30
 
31
31
  context "with multiple rows" do
32
32
 
33
- it "arranges them in two columns" do
33
+ before do
34
+
34
35
  builder.row("foo", "bar")
35
36
  builder.row("flibble", "blurk")
36
37
  builder.row("x", "y")
37
- expect(output.lines).to eq [
38
+
39
+ end
40
+
41
+ let(:expected_output) do
42
+ [
38
43
  " foo bar\n",
39
44
  " flibble blurk\n",
40
45
  " x y\n"
41
46
  ]
42
47
  end
43
48
 
49
+ it "arranges them in two columns" do
50
+ expect(output.lines).to eq expected_output
51
+ end
52
+
44
53
  end
45
54
 
46
55
  context "with a mixture of lines and rows" do
47
56
 
48
- it "still arranges them in two columns" do
57
+ before do
58
+
49
59
  builder.line("ABCDEFGHIJKLMNOP")
50
60
  builder.row("flibble", "blurk")
51
61
  builder.line("Another section heading")
52
62
  builder.row("x", "y")
53
- expect(output.lines).to eq [
63
+
64
+ end
65
+
66
+ let(:expected_output) do
67
+ [
54
68
  "ABCDEFGHIJKLMNOP\n",
55
69
  " flibble blurk\n",
56
70
  "Another section heading\n",
@@ -58,6 +72,10 @@ describe Clamp::Help::Builder do
58
72
  ]
59
73
  end
60
74
 
75
+ it "still arranges them in two columns" do
76
+ expect(output.lines).to eq expected_output
77
+ end
78
+
61
79
  end
62
80
 
63
81
  end
@@ -17,28 +17,33 @@ describe Clamp::Messages do
17
17
  end
18
18
 
19
19
  it "allows setting custom messages" do
20
- expect(Clamp.message(:too_many_arguments)).to eql "Way too many!"
20
+ expect(Clamp.message(:too_many_arguments)).to eq "Way too many!"
21
21
  end
22
22
 
23
23
  it "fallbacks to a default message" do
24
- expect(Clamp.message(:no_value_provided)).to eql "no value provided"
24
+ expect(Clamp.message(:no_value_provided)).to eq "no value provided"
25
25
  end
26
26
 
27
27
  it "formats the message" do
28
- expect(Clamp.message(:custom_message, what: "hello", whom: "Clamp")).to eql "Say hello to Clamp"
28
+ expect(Clamp.message(:custom_message, what: "hello", whom: "Clamp")).to eq "Say hello to Clamp"
29
29
  end
30
30
  end
31
31
 
32
32
  describe "clear_messages!" do
33
- it "clears messages to the defualt state" do
34
- default_msg = Clamp.message(:too_many_arguments).clone
33
+ let!(:default_msg) { Clamp.message(:too_many_arguments).clone }
34
+
35
+ before do
35
36
 
36
37
  Clamp.messages = {
37
38
  too_many_arguments: "Way too many!"
38
39
  }
40
+
39
41
  Clamp.clear_messages!
40
42
 
41
- expect(Clamp.message(:too_many_arguments)).to eql default_msg
43
+ end
44
+
45
+ it "clears messages to the defualt state" do
46
+ expect(Clamp.message(:too_many_arguments)).to eq default_msg
42
47
  end
43
48
  end
44
49
 
@@ -11,26 +11,26 @@ describe Clamp::Option::Definition do
11
11
  end
12
12
 
13
13
  it "has a long_switch" do
14
- expect(option.long_switch).to eql "--key-file"
14
+ expect(option.long_switch).to eq "--key-file"
15
15
  end
16
16
 
17
17
  it "has a type" do
18
- expect(option.type).to eql "FILE"
18
+ expect(option.type).to eq "FILE"
19
19
  end
20
20
 
21
21
  it "has a description" do
22
- expect(option.description).to eql "SSH identity"
22
+ expect(option.description).to eq "SSH identity"
23
23
  end
24
24
 
25
25
  describe "#attribute_name" do
26
26
 
27
27
  it "is derived from the (long) switch" do
28
- expect(option.attribute_name).to eql "key_file"
28
+ expect(option.attribute_name).to eq "key_file"
29
29
  end
30
30
 
31
31
  it "can be overridden" do
32
32
  option = described_class.new("--key-file", "FILE", "SSH identity", attribute_name: "ssh_identity")
33
- expect(option.attribute_name).to eql "ssh_identity"
33
+ expect(option.attribute_name).to eq "ssh_identity"
34
34
  end
35
35
 
36
36
  end
@@ -38,7 +38,7 @@ describe Clamp::Option::Definition do
38
38
  describe "#write_method" do
39
39
 
40
40
  it "is derived from the attribute_name" do
41
- expect(option.write_method).to eql "key_file="
41
+ expect(option.write_method).to eq "key_file="
42
42
  end
43
43
 
44
44
  end
@@ -47,12 +47,12 @@ describe Clamp::Option::Definition do
47
47
 
48
48
  it "defaults to nil" do
49
49
  option = described_class.new("-n", "N", "iterations")
50
- expect(option.default_value).to eql nil
50
+ expect(option.default_value).to be_nil
51
51
  end
52
52
 
53
53
  it "can be overridden" do
54
54
  option = described_class.new("-n", "N", "iterations", default: 1)
55
- expect(option.default_value).to eql 1
55
+ expect(option.default_value).to eq 1
56
56
  end
57
57
 
58
58
  end
@@ -60,14 +60,14 @@ describe Clamp::Option::Definition do
60
60
  describe "#help" do
61
61
 
62
62
  it "combines switch, type and description" do
63
- expect(option.help).to eql ["--key-file FILE", "SSH identity"]
63
+ expect(option.help).to eq ["--key-file FILE", "SSH identity"]
64
64
  end
65
65
 
66
66
  end
67
67
 
68
68
  end
69
69
 
70
- context "flag" do
70
+ context "when flag" do
71
71
 
72
72
  let(:option) do
73
73
  described_class.new("--verbose", :flag, "Blah blah blah")
@@ -75,14 +75,28 @@ describe Clamp::Option::Definition do
75
75
 
76
76
  describe "#default_conversion_block" do
77
77
 
78
- it "converts truthy values to true" do
79
- expect(option.default_conversion_block.call("true")).to eql true
80
- expect(option.default_conversion_block.call("yes")).to eql true
78
+ context "with 'true' value" do
79
+ it "converts to true" do
80
+ expect(option.default_conversion_block.call("true")).to be true
81
+ end
81
82
  end
82
83
 
83
- it "converts falsey values to false" do
84
- expect(option.default_conversion_block.call("false")).to eql false
85
- expect(option.default_conversion_block.call("no")).to eql false
84
+ context "with 'yes' value" do
85
+ it "converts to true" do
86
+ expect(option.default_conversion_block.call("yes")).to be true
87
+ end
88
+ end
89
+
90
+ context "with 'false' value" do
91
+ it "converts to false" do
92
+ expect(option.default_conversion_block.call("false")).to be false
93
+ end
94
+ end
95
+
96
+ context "with 'no' value" do
97
+ it "converts to false" do
98
+ expect(option.default_conversion_block.call("no")).to be false
99
+ end
86
100
  end
87
101
 
88
102
  end
@@ -90,29 +104,43 @@ describe Clamp::Option::Definition do
90
104
  describe "#help" do
91
105
 
92
106
  it "excludes option argument" do
93
- expect(option.help).to eql ["--verbose", "Blah blah blah"]
107
+ expect(option.help).to eq ["--verbose", "Blah blah blah"]
94
108
  end
95
109
 
96
110
  end
97
111
 
98
112
  end
99
113
 
100
- context "negatable flag" do
114
+ context "when negatable flag" do
101
115
 
102
116
  let(:option) do
103
117
  described_class.new("--[no-]force", :flag, "Force installation")
104
118
  end
105
119
 
106
- it "handles both positive and negative forms" do
107
- expect(option.handles?("--force")).to be true
108
- expect(option.handles?("--no-force")).to be true
120
+ describe "positive form" do
121
+ it "handles this" do
122
+ expect(option.handles?("--force")).to be true
123
+ end
109
124
  end
110
125
 
111
- describe "#flag_value" do
126
+ describe "negative form" do
127
+ it "handles this" do
128
+ expect(option.handles?("--no-force")).to be true
129
+ end
130
+ end
131
+
132
+ describe "#flag_set?" do
133
+
134
+ describe "positive variant" do
135
+ it "returns true" do
136
+ expect(option.flag_set?("--force")).to be true
137
+ end
138
+ end
112
139
 
113
- it "returns true for the positive variant" do
114
- expect(option.flag_value("--force")).to be true
115
- expect(option.flag_value("--no-force")).to be false
140
+ describe "negative variant" do
141
+ it "returns false" do
142
+ expect(option.flag_set?("--no-force")).to be false
143
+ end
116
144
  end
117
145
 
118
146
  end
@@ -120,7 +148,7 @@ describe Clamp::Option::Definition do
120
148
  describe "#attribute_name" do
121
149
 
122
150
  it "is derived from the (long) switch" do
123
- expect(option.attribute_name).to eql "force"
151
+ expect(option.attribute_name).to eq "force"
124
152
  end
125
153
 
126
154
  end
@@ -133,15 +161,22 @@ describe Clamp::Option::Definition do
133
161
  described_class.new(["-k", "--key-file"], "FILE", "SSH identity")
134
162
  end
135
163
 
136
- it "handles both switches" do
137
- expect(option.handles?("--key-file")).to be true
138
- expect(option.handles?("-k")).to be true
164
+ describe "long switch" do
165
+ it "handles this" do
166
+ expect(option.handles?("--key-file")).to be true
167
+ end
168
+ end
169
+
170
+ describe "short switch" do
171
+ it "handles this" do
172
+ expect(option.handles?("-k")).to be true
173
+ end
139
174
  end
140
175
 
141
176
  describe "#help" do
142
177
 
143
178
  it "includes both switches" do
144
- expect(option.help).to eql ["-k, --key-file FILE", "SSH identity"]
179
+ expect(option.help).to eq ["-k, --key-file FILE", "SSH identity"]
145
180
  end
146
181
 
147
182
  end
@@ -157,12 +192,12 @@ describe Clamp::Option::Definition do
157
192
  describe "#help" do
158
193
 
159
194
  it "describes environment variable" do
160
- expect(option.help).to eql ["-x X", "mystery option (default: $APP_X)"]
195
+ expect(option.help).to eq ["-x X", "mystery option (default: $APP_X)"]
161
196
  end
162
197
 
163
198
  end
164
199
 
165
- context "and a default value" do
200
+ context "with a default value" do
166
201
 
167
202
  let(:option) do
168
203
  described_class.new("-x", "X", "mystery option", environment_variable: "APP_X", default: "xyz")
@@ -171,7 +206,23 @@ describe Clamp::Option::Definition do
171
206
  describe "#help" do
172
207
 
173
208
  it "describes both environment variable and default" do
174
- expect(option.help).to eql ["-x X", %{mystery option (default: $APP_X, or "xyz")}]
209
+ expect(option.help).to eq ["-x X", %{mystery option (default: $APP_X, or "xyz")}]
210
+ end
211
+
212
+ end
213
+
214
+ end
215
+
216
+ context "when it is required" do
217
+
218
+ let(:option) do
219
+ described_class.new("-x", "X", "mystery option", environment_variable: "APP_X", required: true)
220
+ end
221
+
222
+ describe "#help" do
223
+
224
+ it "describes the environment variable as the default" do
225
+ expect(option.help).to eql ["-x X", %{mystery option (required, default: $APP_X)}]
175
226
  end
176
227
 
177
228
  end
@@ -180,7 +231,7 @@ describe Clamp::Option::Definition do
180
231
 
181
232
  end
182
233
 
183
- context "multivalued" do
234
+ context "when multivalued" do
184
235
 
185
236
  let(:option) do
186
237
  described_class.new(["-H", "--header"], "HEADER", "extra header", multivalued: true)
@@ -193,12 +244,12 @@ describe Clamp::Option::Definition do
193
244
  describe "#default_value" do
194
245
 
195
246
  it "defaults to an empty Array" do
196
- expect(option.default_value).to eql []
247
+ expect(option.default_value).to be_empty
197
248
  end
198
249
 
199
250
  it "can be overridden" do
200
251
  option = described_class.new("-H", "HEADER", "extra header", multivalued: true, default: [1, 2, 3])
201
- expect(option.default_value).to eql [1, 2, 3]
252
+ expect(option.default_value).to eq [1, 2, 3]
202
253
  end
203
254
 
204
255
  end
@@ -206,7 +257,7 @@ describe Clamp::Option::Definition do
206
257
  describe "#attribute_name" do
207
258
 
208
259
  it "gets a _list suffix" do
209
- expect(option.attribute_name).to eql "header_list"
260
+ expect(option.attribute_name).to eq "header_list"
210
261
  end
211
262
 
212
263
  end
@@ -214,7 +265,7 @@ describe Clamp::Option::Definition do
214
265
  describe "#append_method" do
215
266
 
216
267
  it "is derived from the attribute_name" do
217
- expect(option.append_method).to eql "append_to_header_list"
268
+ expect(option.append_method).to eq "append_to_header_list"
218
269
  end
219
270
 
220
271
  end
@@ -238,7 +289,7 @@ describe Clamp::Option::Definition do
238
289
  it "includes help for each option exactly once" do
239
290
  subcommand = command_class.send(:find_subcommand, "foo")
240
291
  subcommand_help = subcommand.subcommand_class.help("")
241
- expect(subcommand_help.lines.grep(/--bar BAR/).count).to eql 1
292
+ expect(subcommand_help.lines.grep(/--bar BAR/).count).to eq 1
242
293
  end
243
294
 
244
295
  end
@@ -262,6 +313,7 @@ describe Clamp::Option::Definition do
262
313
 
263
314
  describe "a hidden option" do
264
315
  let(:option) { described_class.new("--unseen", :flag, "Something", hidden: true) }
316
+
265
317
  it "is hidden" do
266
318
  expect(option).to be_hidden
267
319
  end
@@ -285,7 +337,7 @@ describe Clamp::Option::Definition do
285
337
  it "sets the expected accessor" do
286
338
  command = command_class.new("foo")
287
339
  command.run(["--unseen"])
288
- expect(command.unseen?).to be_truthy
340
+ expect(command).to be_unseen
289
341
  end
290
342
  end
291
343
  end