Skip to content

Commit 107cbd2

Browse files
committed
GetoptLong#each_option should have the specs and #each be the alias for consistency
1 parent 644820c commit 107cbd2

2 files changed

Lines changed: 17 additions & 17 deletions

File tree

library/getoptlong/each_option_spec.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,20 @@
22
require 'getoptlong'
33

44
describe "GetoptLong#each_option" do
5-
it "is an alias of GetoptLong#each" do
6-
GetoptLong.instance_method(:each_option).should == GetoptLong.instance_method(:each)
5+
before :each do
6+
@opts = GetoptLong.new(
7+
[ '--size', '-s', GetoptLong::REQUIRED_ARGUMENT ],
8+
[ '--verbose', '-v', GetoptLong::NO_ARGUMENT ],
9+
[ '--query', '-q', GetoptLong::NO_ARGUMENT ],
10+
[ '--check', '--valid', '-c', GetoptLong::NO_ARGUMENT ]
11+
)
12+
end
13+
14+
it "passes each_option argument/value pair to the block" do
15+
argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do
16+
pairs = []
17+
@opts.each_option { |arg, val| pairs << [ arg, val ] }
18+
pairs.should == [ [ "--size", "10k" ], [ "--verbose", "" ], [ "--query", ""] ]
19+
end
720
end
821
end

library/getoptlong/each_spec.rb

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,7 @@
22
require 'getoptlong'
33

44
describe "GetoptLong#each" do
5-
before :each do
6-
@opts = GetoptLong.new(
7-
[ '--size', '-s', GetoptLong::REQUIRED_ARGUMENT ],
8-
[ '--verbose', '-v', GetoptLong::NO_ARGUMENT ],
9-
[ '--query', '-q', GetoptLong::NO_ARGUMENT ],
10-
[ '--check', '--valid', '-c', GetoptLong::NO_ARGUMENT ]
11-
)
12-
end
13-
14-
it "passes each argument/value pair to the block" do
15-
argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do
16-
pairs = []
17-
@opts.each { |arg, val| pairs << [ arg, val ] }
18-
pairs.should == [ [ "--size", "10k" ], [ "--verbose", "" ], [ "--query", ""] ]
19-
end
5+
it "is an alias of GetoptLong#each_option" do
6+
GetoptLong.instance_method(:each).should == GetoptLong.instance_method(:each_option)
207
end
218
end

0 commit comments

Comments
 (0)