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/error_message_spec.rb2
-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/ordering_spec.rb8
-rw-r--r--spec/ruby/library/getoptlong/set_options_spec.rb28
-rw-r--r--spec/ruby/library/getoptlong/shared/each.rb18
-rw-r--r--spec/ruby/library/getoptlong/shared/get.rb64
-rw-r--r--spec/ruby/library/getoptlong/terminate_spec.rb2
-rw-r--r--spec/ruby/library/getoptlong/terminated_spec.rb6
11 files changed, 105 insertions, 113 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/error_message_spec.rb b/spec/ruby/library/getoptlong/error_message_spec.rb
index 1ed9419f6c..10435b1350 100644
--- a/spec/ruby/library/getoptlong/error_message_spec.rb
+++ b/spec/ruby/library/getoptlong/error_message_spec.rb
@@ -14,7 +14,7 @@ describe "GetoptLong#error_message" do
opts.get
-> {
opts.ordering = GetoptLong::PERMUTE
- }.should raise_error(ArgumentError) { |e|
+ }.should.raise(ArgumentError) { |e|
e.message.should == "argument error"
opts.error_message.should == "argument error"
}
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/ordering_spec.rb b/spec/ruby/library/getoptlong/ordering_spec.rb
index e6b645018d..60ce73afaa 100644
--- a/spec/ruby/library/getoptlong/ordering_spec.rb
+++ b/spec/ruby/library/getoptlong/ordering_spec.rb
@@ -9,18 +9,18 @@ describe "GetoptLong#ordering=" do
opts.quiet = true
opts.get
- lambda {
+ -> {
opts.ordering = GetoptLong::PERMUTE
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
it "raises an ArgumentError if given an invalid value" do
opts = GetoptLong.new
- lambda {
+ -> {
opts.ordering = 12345
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
it "does not allow changing ordering to PERMUTE if ENV['POSIXLY_CORRECT'] is set" do
diff --git a/spec/ruby/library/getoptlong/set_options_spec.rb b/spec/ruby/library/getoptlong/set_options_spec.rb
index f2acccea28..f60dcc87a3 100644
--- a/spec/ruby/library/getoptlong/set_options_spec.rb
+++ b/spec/ruby/library/getoptlong/set_options_spec.rb
@@ -39,60 +39,60 @@ describe "GetoptLong#set_options" do
it "raises an ArgumentError if too many argument flags where given" do
argv [] do
- lambda {
+ -> {
@opts.set_options(["--size", GetoptLong::NO_ARGUMENT, GetoptLong::REQUIRED_ARGUMENT])
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
it "raises a RuntimeError if processing has already started" do
argv [] do
@opts.get
- lambda {
+ -> {
@opts.set_options()
- }.should raise_error(RuntimeError)
+ }.should.raise(RuntimeError)
end
end
it "raises an ArgumentError if no argument flag was given" do
argv [] do
- lambda {
+ -> {
@opts.set_options(["--size"])
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
it "raises an ArgumentError if one of the given arguments is not an Array" do
argv [] do
- lambda {
+ -> {
@opts.set_options(
["--size", GetoptLong::REQUIRED_ARGUMENT],
"test")
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
it "raises an ArgumentError if the same option is given twice" do
argv [] do
- lambda {
+ -> {
@opts.set_options(
["--size", GetoptLong::NO_ARGUMENT],
["--size", GetoptLong::OPTIONAL_ARGUMENT])
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
- lambda {
+ -> {
@opts.set_options(
["--size", GetoptLong::NO_ARGUMENT],
["-s", "--size", GetoptLong::OPTIONAL_ARGUMENT])
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
end
end
it "raises an ArgumentError if the given option is invalid" do
argv [] do
- lambda {
+ -> {
@opts.set_options(["-size", GetoptLong::NO_ARGUMENT])
- }.should raise_error(ArgumentError)
+ }.should.raise(ArgumentError)
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 91a0fbaacc..0000000000
--- a/spec/ruby/library/getoptlong/shared/get.rb
+++ /dev/null
@@ -1,64 +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
- lambda { @opts.send(@method) }.should raise_error(GetoptLong::MissingArgument)
- end
- end
-
- ruby_version_is "2.5" do
- # 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
-end
diff --git a/spec/ruby/library/getoptlong/terminate_spec.rb b/spec/ruby/library/getoptlong/terminate_spec.rb
index 287945fe9b..a12d1df2ef 100644
--- a/spec/ruby/library/getoptlong/terminate_spec.rb
+++ b/spec/ruby/library/getoptlong/terminate_spec.rb
@@ -19,7 +19,7 @@ describe "GetoptLong#terminate" do
end
end
- it "returns self when option processsing is terminated" do
+ it "returns self when option processing is terminated" do
@opts.terminate.should == @opts
end
diff --git a/spec/ruby/library/getoptlong/terminated_spec.rb b/spec/ruby/library/getoptlong/terminated_spec.rb
index 01a8feddea..6108a7f6e9 100644
--- a/spec/ruby/library/getoptlong/terminated_spec.rb
+++ b/spec/ruby/library/getoptlong/terminated_spec.rb
@@ -5,13 +5,13 @@ describe "GetoptLong#terminated?" do
it "returns true if option processing has terminated" do
argv [ "--size", "10k" ] do
opts = GetoptLong.new(["--size", GetoptLong::REQUIRED_ARGUMENT])
- opts.terminated?.should == false
+ opts.should_not.terminated?
opts.get.should == ["--size", "10k"]
- opts.terminated?.should == false
+ opts.should_not.terminated?
opts.get.should == nil
- opts.terminated?.should == true
+ opts.should.terminated?
end
end
end