summaryrefslogtreecommitdiff
path: root/spec/ruby/library/getoptlong
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/library/getoptlong')
-rw-r--r--spec/ruby/library/getoptlong/each_option_spec.rb18
-rw-r--r--spec/ruby/library/getoptlong/each_spec.rb5
-rw-r--r--spec/ruby/library/getoptlong/get_option_spec.rb5
-rw-r--r--spec/ruby/library/getoptlong/get_spec.rb62
-rw-r--r--spec/ruby/library/getoptlong/shared/each.rb18
-rw-r--r--spec/ruby/library/getoptlong/shared/get.rb62
6 files changed, 82 insertions, 88 deletions
diff --git a/spec/ruby/library/getoptlong/each_option_spec.rb b/spec/ruby/library/getoptlong/each_option_spec.rb
index c6d82af86d..3349554aaa 100644
--- a/spec/ruby/library/getoptlong/each_option_spec.rb
+++ b/spec/ruby/library/getoptlong/each_option_spec.rb
@@ -1,7 +1,21 @@
require_relative '../../spec_helper'
require 'getoptlong'
-require_relative 'shared/each'
describe "GetoptLong#each_option" do
- it_behaves_like :getoptlong_each, :each_option
+ before :each do
+ @opts = GetoptLong.new(
+ [ '--size', '-s', GetoptLong::REQUIRED_ARGUMENT ],
+ [ '--verbose', '-v', GetoptLong::NO_ARGUMENT ],
+ [ '--query', '-q', GetoptLong::NO_ARGUMENT ],
+ [ '--check', '--valid', '-c', GetoptLong::NO_ARGUMENT ]
+ )
+ end
+
+ it "passes each_option argument/value pair to the block" do
+ argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do
+ pairs = []
+ @opts.each_option { |arg, val| pairs << [ arg, val ] }
+ pairs.should == [ [ "--size", "10k" ], [ "--verbose", "" ], [ "--query", ""] ]
+ end
+ end
end
diff --git a/spec/ruby/library/getoptlong/each_spec.rb b/spec/ruby/library/getoptlong/each_spec.rb
index d9022f02af..646c3297b5 100644
--- a/spec/ruby/library/getoptlong/each_spec.rb
+++ b/spec/ruby/library/getoptlong/each_spec.rb
@@ -1,7 +1,8 @@
require_relative '../../spec_helper'
require 'getoptlong'
-require_relative 'shared/each'
describe "GetoptLong#each" do
- it_behaves_like :getoptlong_each, :each
+ it "is an alias of GetoptLong#each_option" do
+ GetoptLong.instance_method(:each).should == GetoptLong.instance_method(:each_option)
+ end
end
diff --git a/spec/ruby/library/getoptlong/get_option_spec.rb b/spec/ruby/library/getoptlong/get_option_spec.rb
index 3cb2044379..1d80e3622e 100644
--- a/spec/ruby/library/getoptlong/get_option_spec.rb
+++ b/spec/ruby/library/getoptlong/get_option_spec.rb
@@ -1,7 +1,8 @@
require_relative '../../spec_helper'
require 'getoptlong'
-require_relative 'shared/get'
describe "GetoptLong#get_option" do
- it_behaves_like :getoptlong_get, :get_option
+ it "is an alias of GetoptLong#get" do
+ GetoptLong.instance_method(:get_option).should == GetoptLong.instance_method(:get)
+ end
end
diff --git a/spec/ruby/library/getoptlong/get_spec.rb b/spec/ruby/library/getoptlong/get_spec.rb
index a8ec586fc9..bfc6697a5a 100644
--- a/spec/ruby/library/getoptlong/get_spec.rb
+++ b/spec/ruby/library/getoptlong/get_spec.rb
@@ -1,7 +1,65 @@
require_relative '../../spec_helper'
require 'getoptlong'
-require_relative 'shared/get'
describe "GetoptLong#get" do
- it_behaves_like :getoptlong_get, :get
+ before :each do
+ @opts = GetoptLong.new(
+ [ '--size', '-s', GetoptLong::REQUIRED_ARGUMENT ],
+ [ '--verbose', '-v', GetoptLong::NO_ARGUMENT ],
+ [ '--query', '-q', GetoptLong::NO_ARGUMENT ],
+ [ '--check', '--valid', '-c', GetoptLong::NO_ARGUMENT ]
+ )
+ @opts.quiet = true # silence using $deferr
+ end
+
+ it "returns the next option name and its argument as an Array" do
+ argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do
+ @opts.get.should == [ "--size", "10k" ]
+ @opts.get.should == [ "--verbose", "" ]
+ @opts.get.should == [ "--query", ""]
+ @opts.get.should == nil
+ end
+ end
+
+ it "shifts ARGV on each call" do
+ argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do
+ @opts.get
+ ARGV.should == [ "-v", "-q", "a.txt", "b.txt" ]
+
+ @opts.get
+ ARGV.should == [ "-q", "a.txt", "b.txt" ]
+
+ @opts.get
+ ARGV.should == [ "a.txt", "b.txt" ]
+
+ @opts.get
+ ARGV.should == [ "a.txt", "b.txt" ]
+ end
+ end
+
+ it "terminates processing when encountering '--'" do
+ argv [ "--size", "10k", "--", "-v", "-q", "a.txt", "b.txt" ] do
+ @opts.get
+ ARGV.should == ["--", "-v", "-q", "a.txt", "b.txt"]
+
+ @opts.get
+ ARGV.should == ["-v", "-q", "a.txt", "b.txt"]
+
+ @opts.get
+ ARGV.should == ["-v", "-q", "a.txt", "b.txt"]
+ end
+ end
+
+ it "raises a if an argument was required, but none given" do
+ argv [ "--size" ] do
+ -> { @opts.get }.should.raise(GetoptLong::MissingArgument)
+ end
+ end
+
+ # https://bugs.ruby-lang.org/issues/13858
+ it "returns multiline argument" do
+ argv [ "--size=\n10k\n" ] do
+ @opts.get.should == [ "--size", "\n10k\n" ]
+ end
+ end
end
diff --git a/spec/ruby/library/getoptlong/shared/each.rb b/spec/ruby/library/getoptlong/shared/each.rb
deleted file mode 100644
index b534e24c0f..0000000000
--- a/spec/ruby/library/getoptlong/shared/each.rb
+++ /dev/null
@@ -1,18 +0,0 @@
-describe :getoptlong_each, shared: true do
- before :each do
- @opts = GetoptLong.new(
- [ '--size', '-s', GetoptLong::REQUIRED_ARGUMENT ],
- [ '--verbose', '-v', GetoptLong::NO_ARGUMENT ],
- [ '--query', '-q', GetoptLong::NO_ARGUMENT ],
- [ '--check', '--valid', '-c', GetoptLong::NO_ARGUMENT ]
- )
- end
-
- it "passes each argument/value pair to the block" do
- argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do
- pairs = []
- @opts.send(@method) { |arg, val| pairs << [ arg, val ] }
- pairs.should == [ [ "--size", "10k" ], [ "--verbose", "" ], [ "--query", ""] ]
- end
- end
-end
diff --git a/spec/ruby/library/getoptlong/shared/get.rb b/spec/ruby/library/getoptlong/shared/get.rb
deleted file mode 100644
index 8d24c4c255..0000000000
--- a/spec/ruby/library/getoptlong/shared/get.rb
+++ /dev/null
@@ -1,62 +0,0 @@
-describe :getoptlong_get, shared: true do
- before :each do
- @opts = GetoptLong.new(
- [ '--size', '-s', GetoptLong::REQUIRED_ARGUMENT ],
- [ '--verbose', '-v', GetoptLong::NO_ARGUMENT ],
- [ '--query', '-q', GetoptLong::NO_ARGUMENT ],
- [ '--check', '--valid', '-c', GetoptLong::NO_ARGUMENT ]
- )
- @opts.quiet = true # silence using $deferr
- end
-
- it "returns the next option name and its argument as an Array" do
- argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do
- @opts.send(@method).should == [ "--size", "10k" ]
- @opts.send(@method).should == [ "--verbose", "" ]
- @opts.send(@method).should == [ "--query", ""]
- @opts.send(@method).should == nil
- end
- end
-
- it "shifts ARGV on each call" do
- argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do
- @opts.send(@method)
- ARGV.should == [ "-v", "-q", "a.txt", "b.txt" ]
-
- @opts.send(@method)
- ARGV.should == [ "-q", "a.txt", "b.txt" ]
-
- @opts.send(@method)
- ARGV.should == [ "a.txt", "b.txt" ]
-
- @opts.send(@method)
- ARGV.should == [ "a.txt", "b.txt" ]
- end
- end
-
- it "terminates processing when encountering '--'" do
- argv [ "--size", "10k", "--", "-v", "-q", "a.txt", "b.txt" ] do
- @opts.send(@method)
- ARGV.should == ["--", "-v", "-q", "a.txt", "b.txt"]
-
- @opts.send(@method)
- ARGV.should == ["-v", "-q", "a.txt", "b.txt"]
-
- @opts.send(@method)
- ARGV.should == ["-v", "-q", "a.txt", "b.txt"]
- end
- end
-
- it "raises a if an argument was required, but none given" do
- argv [ "--size" ] do
- -> { @opts.send(@method) }.should.raise(GetoptLong::MissingArgument)
- end
- end
-
- # https://bugs.ruby-lang.org/issues/13858
- it "returns multiline argument" do
- argv [ "--size=\n10k\n" ] do
- @opts.send(@method).should == [ "--size", "\n10k\n" ]
- end
- end
-end