回答編集履歴
1
ちゃんとかいた
answer
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
単純にbeforeでARGVをいじってあげればいいんじゃないでしょうか?
|
2
2
|
|
3
3
|
```ruby
|
4
|
+
# frozen_string_literal: true
|
4
|
-
require '
|
5
|
+
require 'optparse'
|
5
6
|
|
6
|
-
describe
|
7
|
+
RSpec.describe "ARGV.getopts('ab')" do
|
7
8
|
subject { ARGV.getopts('ab') }
|
8
9
|
|
9
10
|
before do
|
@@ -11,6 +12,18 @@
|
|
11
12
|
ARGV.concat(['-a', '-b'])
|
12
13
|
end
|
13
14
|
|
14
|
-
it { is_expected.to eq
|
15
|
+
it { is_expected.to eq('a' => true, 'b' => true) }
|
15
16
|
end
|
17
|
+
```
|
18
|
+
|
19
|
+
```
|
20
|
+
$ rspec spec/argv_spec.rb
|
21
|
+
|
22
|
+
Randomized with seed 53536
|
23
|
+
|
24
|
+
ARGV.getopts('ab')
|
25
|
+
should eq {"a"=>true, "b"=>true}
|
26
|
+
|
27
|
+
Finished in 0.00413 seconds (files took 0.79551 seconds to load)
|
28
|
+
1 example, 0 failures
|
16
29
|
```
|