switches.rb 0.12.0 → 0.13.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60984de78f4a7074bd1f41f4293bcf5c4fb4d837c138bb59f2b7d3519cf17372
4
- data.tar.gz: ed1fd8d58a77fd2335d047dea552326759291b7f985cc027004b0bde774e603b
3
+ metadata.gz: b590f038763df24590cd79b6646fb8ebb2edfb110f3b9d43c464ba29b8b6cf89
4
+ data.tar.gz: d3b8192ac3ba56d12c252cfb5d97cbe850bb4e1035f05e5bd9d70d6e837c0665
5
5
  SHA512:
6
- metadata.gz: '080a361c32b9e9db115abe54e677cbd4ceff39d8f895c8a2d4e4819bf27b81393e5f3636550f12b52e547d9aa58398302d29506fe67c0ff9e2215a27f78f6aa9'
7
- data.tar.gz: 4dc836fb4dc0195323b31013af2367657eb1d8ac21cb87a1ec09d0dc7b2d0e6aebe164ae49475a866053765ec5b9047734d64e580076fcf78f75c802107dc569
6
+ metadata.gz: 82248fe0a7aa10ebb8b4dd0bc5bad30d7f85232dcc46456ae4bb2274da1e78d9184e6beb33d77db28ffe2b46b4f94c9f1a717238c0f0f2a7b0799a0a68fb00f0
7
+ data.tar.gz: 2a930511b47f3ea6f4d1aedc2c9a0370fd092435890ec3b2a11ca86340a15c59432a19a6fa0f6a75c03de8964cc198c08a0d4f977b479c62becc92e7005ca6cc
data/CHANGELOG CHANGED
@@ -1,6 +1,22 @@
1
1
  # CHANGELOG
2
2
 
3
- ## 20260816
3
+ ## 20260817
4
+
5
+ 0.13.0: Convert the specs from RSpec to Minitest.
6
+
7
+ 1. ~ spec/all.rb: Minitest spec style throughout, + require 'minitest/autorun'. The 75 examples run as 75 runs and 92 assertions, a raise checked for its message becoming two. The substitutions are tabulated in ROADMAP.md, along with the four the mechanical pass got wrong.
8
+ 2. ~ Rakefile: Rake::TestTask in place of RSpec::Core::RakeTask, pointed at spec/all.rb.
9
+ 3. ~ switches.rb.gemspec: minitest and rake as the development dependencies, in place of rake and rspec.
10
+ 4. ~ spec/all.rb: the gemspec spec which asserts those dependencies, which the conversion otherwise fails against itself.
11
+ 5. ~ CHANGELOG: - item 5 of the 0.12.0 entry, which named ROADMAP.md and the header's Todo and Ideas sections. Both went out in 0.12.1 and 0.12.0 contains neither; it was left behind when the one commit was split into two.
12
+ 6. ~ ROADMAP.md: the conversion moves from Open questions into 0.13.0's section, and 0.12.0's section is dated 20260817, which is when it was made.
13
+ 7. ~ CHANGELOG: the date headings — 0.13.0, 0.12.1 and 0.12.0 under 20260817, and + 20260816 for 0.11.0, 0.10.5 and 0.10.4, which had been left under the one heading with them.
14
+
15
+ 0.12.1: Move the reasoning out of the CHANGELOG and the header into a ROADMAP.
16
+
17
+ 1. + ROADMAP.md: the design philosophy, a section per shipped version carrying why it went the way it did, the open questions, and the settled items. Not listed in the gemspec, so it does not ship. Follows namo's ROADMAP.md.
18
+ 2. - lib/Switches.rb: the # Todo: and # Ideas: header sections, now in ROADMAP.md, finishing what 0.10.2 began.
19
+ 3. ~ CHANGELOG: the 0.10.5 and 0.11.0 entries carried reasoning, measurement and outstanding work in prose between their numbered items; that is now in ROADMAP.md, and the entries record what changed.
4
20
 
5
21
  0.12.0: Refuse a switch whose accessor is a method the instance already has, rather than losing it.
6
22
 
@@ -9,23 +25,22 @@
9
25
  3. ~ README.md: + a Notes entry for the refusal, and for the booleans and OptionParser names it does not cover.
10
26
  4. + spec/all.rb: the refusal through #set and #perform, the message, that nothing reaches the parser first, and the two legal cases.
11
27
 
12
- 0.11.0: Forward to OptionParser, which #method_missing has never actually done.
13
28
 
14
- 1. ~ lib/Switches.rb: #method_missing tested (@op.methods - Switches.instance_methods).include?(method_name.to_s), which compares a String against an array of Symbols and so was never true. Every call fell through to the settings OpenStruct, which accepts anything, so s.banner = '...' — documented in the README's "With a banner" example — silently became a setting named banner while the parser kept its default of "Usage: <program_name> [options]". The comparison is now made in symbols, and the forwarding works: #banner=, #separator, #program_name= and the other 58 OptionParser methods reach the parser.
15
- 2. ~ lib/Switches.rb: a declared switch takes precedence over an OptionParser method of the same name, + Switches#declared_switch?. Making the forwarding work otherwise shadows any switch sharing a name with the parser, and OptionParser has version, help, release, load, order, top, base, parse, warn, abort and banner among its 61, several of which are switches a program would reasonably want. The rule is that the program's own declarations beat the wrapper's interface, which also leaves any existing program's switches reading as they did.
16
- 3. ~ lib/Switches.rb: + Switches::NEVER_FORWARDED, the names Ruby may call implicitly, which are excluded from the forwarded set. The set has always been built by subtraction — everything the parser responds to, less everything Switches defines — which admits any such name Switches does not happen to define. OptionParser#to_a is `summarize("#{banner}".split(/^/))`, so without the exclusion Array(switches) and [*switches] answer with the parser's help. That was latent for as long as the branch was dead and became reachable the moment it was not, so it is part of this fix rather than a consequence of it. to_h was never at risk, but only because Switches happens to define it; the constant makes the exclusion deliberate rather than incidental.
17
- 4. ~ lib/Switches.rb: + Switches#option_parser_methods, memoised, since the difference was recomputed upon every settings read, and + Switches#option_parser_method?.
18
- 5. + spec/all.rb: forwarding of a writer, of a method taking an argument, and of a reader, each checked through the parser's own help output rather than by reading back what was written; that a declared switch wins over the OptionParser method of the same name, read and written; that a name which is neither still reaches the settings; and that #to_a, Array() and the splat are answered by the switches rather than the parser.
19
- 6. ~ README.md: the Notes entry claiming a Switches instance can't define a method whose name matches an OptionParser method now describes what happens, which is the reverse: the switch wins.
29
+ ## 20260816
20
30
 
21
- Not done: #respond_to_missing?, which ordinarily accompanies #method_missing. Note that it would not have prevented the to_a case above — Ruby's conversion check falls back to calling #method_missing directly when the ordinary dispatch fails, so Array() reaches #to_a whatever respond_to? answers. It wants deciding alongside the collision question below, both being about which names the object should own.
31
+ 0.11.0: Forward to OptionParser, which #method_missing has never actually done.
22
32
 
23
- Still outstanding: the converse fault, where #method_missing does not fire at all because the method exists. A switch named after a method Object already has — :tap, :class, :display, :hash, :method, :type — never reaches the settings, and Kernel#tap without a block raises LocalJumpError nowhere near the declaration.
33
+ 1. ~ lib/Switches.rb: #method_missing compared method_name.to_s against @op.methods, an array of Symbols, so the forwarding branch was never true; now compared in symbols.
34
+ 2. ~ lib/Switches.rb: + Switches#declared_switch?, giving a declared switch precedence over the OptionParser method of the same name.
35
+ 3. + lib/Switches.rb: Switches::NEVER_FORWARDED, the names Ruby may call implicitly, excluded from the forwarded set, OptionParser#to_a otherwise answering Array() with the help.
36
+ 4. ~ lib/Switches.rb: + Switches#option_parser_methods, memoised, and + Switches#option_parser_method?.
37
+ 5. + spec/all.rb: the forwarding, the precedence rule, the fall-through, and #to_a.
38
+ 6. ~ README.md: the Notes entry describing forwarding, which had it backwards.
24
39
 
25
40
  0.10.5: Specify and document that a multi-word switch may be supplied hyphenated, and name that form when it is missing.
26
41
 
27
- 1. + spec/all.rb: multi-word switches, in both their underscored and their hyphenated form, for a boolean, an optional argument (#set), a required argument (#set!) and a required switch (#required); that either form counts as supplied for a required switch; and that the setting is named for the symbol declared whichever form was supplied. This behaviour is OptionParser's rather than this library's — a long switch is filed under a lookup key with its underscores turned to hyphens, and whatever is supplied is converted the same way before the lookup, so --update_template and --update-template have always been the one switch. It went untested and undocumented here, which left it resting upon an implementation detail of a library this one only wraps. The specs now pin it, and would fail here rather than in a caller's script were it ever to change.
28
- 2. ~ lib/Switches.rb: the missing-switch message names the hyphenated form, so a switch declared :access_token is reported as --access-token, in place of the --access_token built from the symbol verbatim. Cosmetic, and it says the form to prefer at a command line.
42
+ 1. + spec/all.rb: multi-word switches in both their underscored and their hyphenated form, for a boolean, an optional argument (#set), a required argument (#set!) and a required switch (#required); that either form counts as supplied; and that the setting is named for the symbol declared. The behaviour is OptionParser's, a long switch being filed under a lookup key with its underscores turned to hyphens.
43
+ 2. ~ lib/Switches.rb: the missing-switch message names the hyphenated form, so a switch declared :access_token is reported as --access-token, in place of the --access_token built from the symbol verbatim.
29
44
  3. ~ lib/Switches.rb: + Switches#switch_string, which builds the switch string for an attribute, in place of the identical construction #on_args and #check_required_switches each carried.
30
45
  4. ~ README.md: + a multi-word switch to the Usage section, and + a note recording where the behaviour comes from, that the setting is named for the symbol declared, and that declaring the attribute hyphenated buys nothing and costs the accessor.
31
46
 
@@ -39,6 +54,7 @@ Still outstanding: the converse fault, where #method_missing does not fire at al
39
54
  6. ~ lib/Switches.rb: the header's Dependencies section names ostruct, since the Standard Ruby Library no longer covers it.
40
55
  7. ~ .gitignore: + a header, + .claude, ~ /tmp/ to tmp/, and - /test/tmp/, which tmp/ now covers.
41
56
 
57
+
42
58
  ## 20260812
43
59
 
44
60
  0.10.3: Move the version into a constant, and add the standard version and gemspec tests.
@@ -75,6 +91,7 @@ Still outstanding: the converse fault, where #method_missing does not fire at al
75
91
  5. + LICENSE.txt: the MIT licence.
76
92
  6. + CHANGELOG: this file.
77
93
 
94
+
78
95
  ## 20180404
79
96
 
80
97
  0.9.16: Add a Gemfile.
data/Rakefile CHANGED
@@ -1,9 +1,9 @@
1
1
  # Rakefile
2
2
 
3
- require 'rspec/core/rake_task'
3
+ require 'rake/testtask'
4
4
 
5
- RSpec::Core::RakeTask.new(:spec) do |t|
6
- t.pattern = 'spec/all.rb'
5
+ Rake::TestTask.new(:spec) do |t|
6
+ t.test_files = ['spec/all.rb']
7
7
  end
8
8
 
9
9
  task default: :spec
@@ -2,5 +2,5 @@
2
2
  # Switches::VERSION
3
3
 
4
4
  class Switches
5
- VERSION = '0.12.0'
5
+ VERSION = '0.13.0'
6
6
  end
data/lib/Switches.rb CHANGED
@@ -3,15 +3,6 @@
3
3
 
4
4
  # Description: Switches provides for a nice wrapper to OptionParser to also act as a store for switches supplied.
5
5
 
6
- # Todo:
7
- # 1. Clean up #set. Done as of 0.4.0.
8
- # 2. Reinstitute some specs. Done as of 0.9.8.
9
-
10
- # Ideas:
11
- # 1. Use ! for options with required switches? Done as of 0.6.0. (Changed to being for required arguments in 0.9.0 however.)
12
- # 2. Do away with optional arguments entirely. Since when does anyone want to specify a non-boolean switch and then supply no arguments anyway?... OK, maybe sometimes, but this is pretty obscure IMO. OK, bad idea. These can be used as action oriented sub-commands.
13
- # 3. Allow for any one of the switches OpenStruct methods to assign values for any of the other associated methods, so as it is more than a read once switch and can be used for storage through out the application; although this might be stepping on Attributes.rb's toes?...
14
-
15
6
  # Dependencies:
16
7
  # 1. Standard Ruby Library.
17
8
  # 2. ostruct, which ceased to be a default gem as of Ruby 4.0 and so is declared in the gemspec.
data/spec/all.rb CHANGED
@@ -1,11 +1,13 @@
1
1
  # spec/all.rb
2
2
 
3
+ require 'minitest/autorun'
4
+
3
5
  require_relative '../lib/Switches'
4
6
 
5
7
  describe Switches do
6
8
  describe ".new" do
7
9
  it "returns an object of class Switches" do
8
- expect(Switches.new.class).to eq(Switches)
10
+ _(Switches.new.class).must_equal Switches
9
11
  end
10
12
  end
11
13
 
@@ -21,40 +23,40 @@ describe Switches do
21
23
  end
22
24
 
23
25
  it "sets a short boolean switch to true when supplied with a short switch" do
24
- expect(build('-v').v?).to eq(true)
26
+ _(build('-v').v?).must_equal true
25
27
  end
26
28
 
27
29
  it "sets a long boolean switch to true when supplied with a short switch" do
28
- expect(build('-v').verbose?).to eq(true)
30
+ _(build('-v').verbose?).must_equal true
29
31
  end
30
32
 
31
33
  it "sets a short boolean switch to true when supplied with a long switch" do
32
- expect(build('--verbose').v?).to eq(true)
34
+ _(build('--verbose').v?).must_equal true
33
35
  end
34
36
 
35
37
  it "sets a long boolean switch to true when supplied with a long switch" do
36
- expect(build('--verbose').verbose?).to eq(true)
38
+ _(build('--verbose').verbose?).must_equal true
37
39
  end
38
40
 
39
41
  it "sets a short switch to the value supplied when supplied with a short switch" do
40
- expect(build('-p 22').p).to eq('22')
42
+ _(build('-p 22').p).must_equal '22'
41
43
  end
42
44
 
43
45
  it "sets a long switch to the value supplied when supplied with a short switch" do
44
- expect(build('-p 22').port).to eq('22')
46
+ _(build('-p 22').port).must_equal '22'
45
47
  end
46
48
 
47
49
  it "sets a short switch to the value supplied when supplied with a long switch" do
48
- expect(build('--port 22').p).to eq('22')
50
+ _(build('--port 22').p).must_equal '22'
49
51
  end
50
52
 
51
53
  it "sets a long switch to the value supplied when supplied with a long switch" do
52
- expect(build('--port 22').port).to eq('22')
54
+ _(build('--port 22').port).must_equal '22'
53
55
  end
54
56
 
55
57
  it "doesn't matter in which order the short and long switches are given" do
56
- expect(build('-h example.com').h).to eq('example.com')
57
- expect(build('--host example.com').h).to eq('example.com')
58
+ _(build('-h example.com').h).must_equal 'example.com'
59
+ _(build('--host example.com').h).must_equal 'example.com'
58
60
  end
59
61
  end
60
62
 
@@ -68,27 +70,27 @@ describe Switches do
68
70
  end
69
71
 
70
72
  it "sets a short switch to the argument supplied with a short switch" do
71
- expect(build('-p 22').p).to eq('22')
73
+ _(build('-p 22').p).must_equal '22'
72
74
  end
73
75
 
74
76
  it "sets a long switch to the argument supplied with a short switch" do
75
- expect(build('-p 22').port).to eq('22')
77
+ _(build('-p 22').port).must_equal '22'
76
78
  end
77
79
 
78
80
  it "sets a short switch to the argument supplied with a long switch" do
79
- expect(build('--port 22').p).to eq('22')
81
+ _(build('--port 22').p).must_equal '22'
80
82
  end
81
83
 
82
84
  it "sets a long switch to the argument supplied with a long switch" do
83
- expect(build('--port 22').port).to eq('22')
85
+ _(build('--port 22').port).must_equal '22'
84
86
  end
85
87
 
86
88
  it "raises OptionParser::MissingArgument when no argument is supplied to a short switch" do
87
- expect{build('-p')}.to raise_error(OptionParser::MissingArgument)
89
+ _{build('-p')}.must_raise OptionParser::MissingArgument
88
90
  end
89
91
 
90
92
  it "raises OptionParser::MissingArgument when no argument is supplied to a long switch" do
91
- expect{build('--port')}.to raise_error(OptionParser::MissingArgument)
93
+ _{build('--port')}.must_raise OptionParser::MissingArgument
92
94
  end
93
95
  end
94
96
 
@@ -102,27 +104,28 @@ describe Switches do
102
104
  end
103
105
 
104
106
  it "sets a short switch to the argument supplied with a short switch" do
105
- expect(build('-p 22').p).to eq('22')
107
+ _(build('-p 22').p).must_equal '22'
106
108
  end
107
109
 
108
110
  it "sets a long switch to the argument supplied with a short switch" do
109
- expect(build('-p 22').port).to eq('22')
111
+ _(build('-p 22').port).must_equal '22'
110
112
  end
111
113
 
112
114
  it "sets a short switch to the argument supplied with a long switch" do
113
- expect(build('--port 22').p).to eq('22')
115
+ _(build('--port 22').p).must_equal '22'
114
116
  end
115
117
 
116
118
  it "sets a long switch to the argument supplied with a long switch" do
117
- expect(build('--port 22').port).to eq('22')
119
+ _(build('--port 22').port).must_equal '22'
118
120
  end
119
121
 
120
122
  it "raises RequiredSwitchMissing when no switch is supplied" do
121
- expect{build}.to raise_error(RequiredSwitchMissing)
123
+ _{build}.must_raise RequiredSwitchMissing
122
124
  end
123
125
 
124
126
  it "names every missing switch in the RequiredSwitchMissing message" do
125
- expect{build}.to raise_error(RequiredSwitchMissing, /-p.*--port/m)
127
+ error = _{build}.must_raise RequiredSwitchMissing
128
+ _(error.message).must_match(/-p.*--port/m)
126
129
  end
127
130
  end
128
131
 
@@ -136,31 +139,31 @@ describe Switches do
136
139
  end
137
140
 
138
141
  it "sets a short switch to the argument supplied with a short switch" do
139
- expect(build('-p 22').p).to eq('22')
142
+ _(build('-p 22').p).must_equal '22'
140
143
  end
141
144
 
142
145
  it "sets a long switch to the argument supplied with a short switch" do
143
- expect(build('-p 22').port).to eq('22')
146
+ _(build('-p 22').port).must_equal '22'
144
147
  end
145
148
 
146
149
  it "sets a short switch to the argument supplied with a long switch" do
147
- expect(build('--port 22').p).to eq('22')
150
+ _(build('--port 22').p).must_equal '22'
148
151
  end
149
152
 
150
153
  it "sets a long switch to the argument supplied with a long switch" do
151
- expect(build('--port 22').port).to eq('22')
154
+ _(build('--port 22').port).must_equal '22'
152
155
  end
153
156
 
154
157
  it "raises OptionParser::MissingArgument when no argument is supplied to a short switch" do
155
- expect{build('-p')}.to raise_error(OptionParser::MissingArgument)
158
+ _{build('-p')}.must_raise OptionParser::MissingArgument
156
159
  end
157
160
 
158
161
  it "raises OptionParser::MissingArgument when no argument is supplied to a long switch" do
159
- expect{build('--port')}.to raise_error(OptionParser::MissingArgument)
162
+ _{build('--port')}.must_raise OptionParser::MissingArgument
160
163
  end
161
164
 
162
165
  it "raises RequiredSwitchMissing when no switch is supplied" do
163
- expect{build}.to raise_error(RequiredSwitchMissing)
166
+ _{build}.must_raise RequiredSwitchMissing
164
167
  end
165
168
  end
166
169
 
@@ -171,41 +174,44 @@ describe Switches do
171
174
  end
172
175
 
173
176
  it "refuses a switch named after a core method" do
174
- expect{build{|s| s.set(:tap)}}.to raise_error(SwitchNameCollision, /Kernel#tap/)
177
+ error = _{build{|s| s.set(:tap)}}.must_raise SwitchNameCollision
178
+ _(error.message).must_match(/Kernel#tap/)
175
179
  end
176
180
 
177
181
  it "refuses a switch named after a Switches method" do
178
- expect{build{|s| s.set(:settings)}}.to raise_error(SwitchNameCollision, /Switches#settings/)
182
+ error = _{build{|s| s.set(:settings)}}.must_raise SwitchNameCollision
183
+ _(error.message).must_match(/Switches#settings/)
179
184
  end
180
185
 
181
186
  it "refuses a colliding name declared through #perform" do
182
- expect{build{|s| s.perform(:display){}}}.to raise_error(SwitchNameCollision)
187
+ _{build{|s| s.perform(:display){}}}.must_raise SwitchNameCollision
183
188
  end
184
189
 
185
190
  it "names the switch in the form it would be supplied in" do
186
- expect{build{|s| s.set(:instance_variable_get)}}.to raise_error(SwitchNameCollision, /--instance_variable_get/)
191
+ error = _{build{|s| s.set(:instance_variable_get)}}.must_raise SwitchNameCollision
192
+ _(error.message).must_match(/--instance_variable_get/)
187
193
  end
188
194
 
189
195
  it "raises before the switch is declared to the parser" do
190
196
  switches = Switches.new
191
197
  begin; switches.set(:tap); rescue SwitchNameCollision; end
192
- expect(switches.to_h).to eq({})
198
+ _(switches.to_h).must_equal({})
193
199
  end
194
200
 
195
201
  it "accepts the name as a boolean, the accessor then carrying a question mark" do
196
202
  ARGV.clear
197
203
  ARGV << '--tap'
198
- expect(Switches.new{|s| s.boolean(:tap)}.tap?).to eq(true)
204
+ _(Switches.new{|s| s.boolean(:tap)}.tap?).must_equal true
199
205
  end
200
206
 
201
207
  it "accepts a name OptionParser has, a declared switch winning over the parser" do
202
208
  ARGV.clear
203
209
  %w{--banner text}.each{|a| ARGV << a}
204
- expect(Switches.new{|s| s.set(:banner)}.banner).to eq('text')
210
+ _(Switches.new{|s| s.set(:banner)}.banner).must_equal 'text'
205
211
  end
206
212
 
207
213
  it "raises a SwitchNameCollision, which is an ArgumentError" do
208
- expect(SwitchNameCollision.ancestors).to include(ArgumentError)
214
+ _(SwitchNameCollision.ancestors).must_include ArgumentError
209
215
  end
210
216
  end
211
217
 
@@ -216,47 +222,47 @@ describe Switches do
216
222
  end
217
223
 
218
224
  it "forwards a writer to the OptionParser" do
219
- expect(build{|s| s.banner = 'Usage: tap-audit [options]'}.help).to match(/\AUsage: tap-audit \[options\]/)
225
+ _(build{|s| s.banner = 'Usage: tap-audit [options]'}.help).must_match(/\AUsage: tap-audit \[options\]/)
220
226
  end
221
227
 
222
228
  it "forwards a method taking an argument to the OptionParser" do
223
- expect(build{|s| s.separator 'Options:'}.help).to match(/^Options:$/)
229
+ _(build{|s| s.separator 'Options:'}.help).must_match(/^Options:$/)
224
230
  end
225
231
 
226
232
  it "forwards a reader to the OptionParser" do
227
233
  switches = build{|s| s.program_name = 'tap-audit'}
228
- expect(switches.program_name).to eq('tap-audit')
229
- expect(switches.help).to match(/\AUsage: tap-audit/)
234
+ _(switches.program_name).must_equal 'tap-audit'
235
+ _(switches.help).must_match(/\AUsage: tap-audit/)
230
236
  end
231
237
 
232
238
  it "prefers a declared switch to the OptionParser method of the same name" do
233
239
  ARGV.clear
234
240
  %w{--version 2.1}.each{|a| ARGV << a}
235
- expect(Switches.new{|s| s.set(:version)}.version).to eq('2.1')
241
+ _(Switches.new{|s| s.set(:version)}.version).must_equal '2.1'
236
242
  end
237
243
 
238
244
  it "prefers a declared switch when it is written to as well" do
239
245
  switches = build{|s| s.set(:banner)}
240
246
  switches.banner = 'a setting, not the banner'
241
- expect(switches.to_h[:banner]).to eq('a setting, not the banner')
247
+ _(switches.to_h[:banner]).must_equal 'a setting, not the banner'
242
248
  end
243
249
 
244
250
  it "falls through to the settings for a name which is neither" do
245
- expect(build{|s| s.set(:port)}.nonesuch).to eq(nil)
251
+ _(build{|s| s.set(:port)}.nonesuch).must_be_nil
246
252
  end
247
253
 
248
254
  it "does not forward #to_a, which OptionParser answers with its help" do
249
- expect(build{|s| s.set(:port)}.to_a).to eq(nil)
255
+ _(build{|s| s.set(:port)}.to_a).must_be_nil
250
256
  end
251
257
 
252
258
  it "leaves Array() with the switches rather than the parser's help" do
253
259
  switches = build{|s| s.set(:port)}
254
- expect(Array(switches)).to eq([switches])
260
+ _(Array(switches)).must_equal [switches]
255
261
  end
256
262
 
257
263
  it "leaves the splat with the switches rather than the parser's help" do
258
264
  switches = build{|s| s.set(:port)}
259
- expect([*switches]).to eq([switches])
265
+ _([*switches]).must_equal [switches]
260
266
  end
261
267
  end
262
268
 
@@ -271,23 +277,23 @@ describe Switches do
271
277
  end
272
278
 
273
279
  it "sets a boolean switch supplied in its underscored form" do
274
- expect(build('--update_template').update_template?).to eq(true)
280
+ _(build('--update_template').update_template?).must_equal true
275
281
  end
276
282
 
277
283
  it "sets a boolean switch supplied in its hyphenated form" do
278
- expect(build('--update-template').update_template?).to eq(true)
284
+ _(build('--update-template').update_template?).must_equal true
279
285
  end
280
286
 
281
287
  it "sets a switch to the argument supplied in its underscored form" do
282
- expect(build('--access_token abc123').access_token).to eq('abc123')
288
+ _(build('--access_token abc123').access_token).must_equal 'abc123'
283
289
  end
284
290
 
285
291
  it "sets a switch to the argument supplied in its hyphenated form" do
286
- expect(build('--access-token abc123').access_token).to eq('abc123')
292
+ _(build('--access-token abc123').access_token).must_equal 'abc123'
287
293
  end
288
294
 
289
295
  it "names the setting for the symbol declared, whichever form is supplied" do
290
- expect(build('--update-template --access-token abc123').to_h).to eq({update_template?: true, access_token: 'abc123'})
296
+ _(build('--update-template --access-token abc123').to_h).must_equal({update_template?: true, access_token: 'abc123'})
291
297
  end
292
298
  end
293
299
 
@@ -301,19 +307,19 @@ describe Switches do
301
307
  end
302
308
 
303
309
  it "sets the switch to the argument supplied in its underscored form" do
304
- expect(build('--access_token abc123').access_token).to eq('abc123')
310
+ _(build('--access_token abc123').access_token).must_equal 'abc123'
305
311
  end
306
312
 
307
313
  it "sets the switch to the argument supplied in its hyphenated form" do
308
- expect(build('--access-token abc123').access_token).to eq('abc123')
314
+ _(build('--access-token abc123').access_token).must_equal 'abc123'
309
315
  end
310
316
 
311
317
  it "raises OptionParser::MissingArgument when no argument is supplied to the underscored form" do
312
- expect{build('--access_token')}.to raise_error(OptionParser::MissingArgument)
318
+ _{build('--access_token')}.must_raise OptionParser::MissingArgument
313
319
  end
314
320
 
315
321
  it "raises OptionParser::MissingArgument when no argument is supplied to the hyphenated form" do
316
- expect{build('--access-token')}.to raise_error(OptionParser::MissingArgument)
322
+ _{build('--access-token')}.must_raise OptionParser::MissingArgument
317
323
  end
318
324
  end
319
325
 
@@ -327,19 +333,20 @@ describe Switches do
327
333
  end
328
334
 
329
335
  it "counts the underscored form as supplied" do
330
- expect(build('--access_token abc123').access_token).to eq('abc123')
336
+ _(build('--access_token abc123').access_token).must_equal 'abc123'
331
337
  end
332
338
 
333
339
  it "counts the hyphenated form as supplied" do
334
- expect(build('--access-token abc123').access_token).to eq('abc123')
340
+ _(build('--access-token abc123').access_token).must_equal 'abc123'
335
341
  end
336
342
 
337
343
  it "raises RequiredSwitchMissing when neither form is supplied" do
338
- expect{build}.to raise_error(RequiredSwitchMissing)
344
+ _{build}.must_raise RequiredSwitchMissing
339
345
  end
340
346
 
341
347
  it "names the hyphenated form in the RequiredSwitchMissing message" do
342
- expect{build}.to raise_error(RequiredSwitchMissing, /--access-token/)
348
+ error = _{build}.must_raise RequiredSwitchMissing
349
+ _(error.message).must_match(/--access-token/)
343
350
  end
344
351
  end
345
352
 
@@ -353,23 +360,23 @@ describe Switches do
353
360
  it "calls the block when supplied with a short switch" do
354
361
  called = false
355
362
  build('-a'){called = true}
356
- expect(called).to eq(true)
363
+ _(called).must_equal true
357
364
  end
358
365
 
359
366
  it "calls the block when supplied with a long switch" do
360
367
  called = false
361
368
  build('--action'){called = true}
362
- expect(called).to eq(true)
369
+ _(called).must_equal true
363
370
  end
364
371
 
365
372
  it "doesn't call the block when the switch isn't supplied" do
366
373
  called = false
367
374
  build{called = true}
368
- expect(called).to eq(false)
375
+ _(called).must_equal false
369
376
  end
370
377
 
371
378
  it "doesn't require an argument" do
372
- expect{build('-a'){}}.not_to raise_error
379
+ _(build('-a'){}).must_be_kind_of Switches
373
380
  end
374
381
  end
375
382
 
@@ -383,23 +390,23 @@ describe Switches do
383
390
  it "passes the argument to the block when supplied with a short switch" do
384
391
  argument = nil
385
392
  build('-a value'){|o| argument = o}
386
- expect(argument).to eq('value')
393
+ _(argument).must_equal 'value'
387
394
  end
388
395
 
389
396
  it "passes the argument to the block when supplied with a long switch" do
390
397
  argument = nil
391
398
  build('--action value'){|o| argument = o}
392
- expect(argument).to eq('value')
399
+ _(argument).must_equal 'value'
393
400
  end
394
401
 
395
402
  it "doesn't call the block when the switch isn't supplied" do
396
403
  called = false
397
404
  build{called = true}
398
- expect(called).to eq(false)
405
+ _(called).must_equal false
399
406
  end
400
407
 
401
408
  it "raises OptionParser::MissingArgument when no argument is supplied" do
402
- expect{build('-a'){}}.to raise_error(OptionParser::MissingArgument)
409
+ _{build('-a'){}}.must_raise OptionParser::MissingArgument
403
410
  end
404
411
  end
405
412
  end
@@ -407,16 +414,16 @@ end
407
414
  describe Switches do
408
415
  describe "VERSION" do
409
416
  it "is a string" do
410
- expect(Switches::VERSION).to be_a(String)
417
+ _(Switches::VERSION).must_be_kind_of String
411
418
  end
412
419
 
413
420
  it "is three numbers separated by dots" do
414
- expect(Switches::VERSION).to match(/\A\d+\.\d+\.\d+\z/)
421
+ _(Switches::VERSION).must_match(/\A\d+\.\d+\.\d+\z/)
415
422
  end
416
423
 
417
424
  it "matches the newest entry in the CHANGELOG" do
418
425
  changelog = File.read(File.expand_path('../CHANGELOG', __dir__))
419
- expect(changelog[/^(\d+\.\d+\.\d+):/, 1]).to eq(Switches::VERSION)
426
+ _(changelog[/^(\d+\.\d+\.\d+):/, 1]).must_equal Switches::VERSION
420
427
  end
421
428
  end
422
429
  end
@@ -425,22 +432,22 @@ describe 'switches.rb.gemspec' do
425
432
  let(:spec){Gem::Specification.load(File.expand_path('../switches.rb.gemspec', __dir__))}
426
433
 
427
434
  it "is a valid specification" do
428
- expect(spec.validate).to eq(true)
435
+ _(spec.validate).must_equal true
429
436
  end
430
437
 
431
438
  it "does not pin a date" do
432
- expect(spec.date).to eq(Gem::Specification.new.date)
439
+ _(spec.date).must_equal Gem::Specification.new.date
433
440
  end
434
441
 
435
442
  it "takes its version from Switches::VERSION" do
436
- expect(spec.version.to_s).to eq(Switches::VERSION)
443
+ _(spec.version.to_s).must_equal Switches::VERSION
437
444
  end
438
445
 
439
446
  it "declares ostruct as its only runtime dependency" do
440
- expect(spec.runtime_dependencies.map(&:name).sort).to eq(%w{ostruct})
447
+ _(spec.runtime_dependencies.map(&:name).sort).must_equal %w{ostruct}
441
448
  end
442
449
 
443
450
  it "declares its development dependencies" do
444
- expect(spec.development_dependencies.map(&:name).sort).to eq(%w{rake rspec})
451
+ _(spec.development_dependencies.map(&:name).sort).must_equal %w{minitest rake}
445
452
  end
446
453
  end
data/switches.rb.gemspec CHANGED
@@ -41,8 +41,8 @@ Gem::Specification.new do |s|
41
41
  ]
42
42
 
43
43
  s.development_dependencies = [
44
- 'rake',
45
- 'rspec'
44
+ 'minitest',
45
+ 'rake'
46
46
  ]
47
47
 
48
48
  s.metadata = {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: switches.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thoran
@@ -24,7 +24,7 @@ dependencies:
24
24
  - !ruby/object:Gem::Version
25
25
  version: '0'
26
26
  - !ruby/object:Gem::Dependency
27
- name: rake
27
+ name: minitest
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - ">="
@@ -38,7 +38,7 @@ dependencies:
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0'
40
40
  - !ruby/object:Gem::Dependency
41
- name: rspec
41
+ name: rake
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - ">="