From 8538c30a8a6ea45264b014a5990986aae8997aed Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Thu, 11 Jan 2024 14:17:53 +0900 Subject: [PATCH] spec/mspec/tool/wrap_with_guard.rb 'ruby_version_is ""..."3.4"' spec/ruby/library/getoptlong/**/*.rb --- library/getoptlong/each_option_spec.rb | 11 +- library/getoptlong/each_spec.rb | 11 +- library/getoptlong/error_message_spec.rb | 35 +++--- library/getoptlong/get_option_spec.rb | 11 +- library/getoptlong/get_spec.rb | 11 +- library/getoptlong/initialize_spec.rb | 41 +++--- library/getoptlong/ordering_spec.rb | 57 +++++---- library/getoptlong/set_options_spec.rb | 151 ++++++++++++----------- library/getoptlong/terminate_spec.rb | 47 +++---- library/getoptlong/terminated_spec.rb | 23 ++-- 10 files changed, 214 insertions(+), 184 deletions(-) diff --git a/library/getoptlong/each_option_spec.rb b/library/getoptlong/each_option_spec.rb index c6d82af86d..87dd825264 100644 --- a/library/getoptlong/each_option_spec.rb +++ b/library/getoptlong/each_option_spec.rb @@ -1,7 +1,10 @@ require_relative '../../spec_helper' -require 'getoptlong' -require_relative 'shared/each' -describe "GetoptLong#each_option" do - it_behaves_like :getoptlong_each, :each_option +ruby_version_is ""..."3.4" do + require 'getoptlong' + require_relative 'shared/each' + + describe "GetoptLong#each_option" do + it_behaves_like :getoptlong_each, :each_option + end end diff --git a/library/getoptlong/each_spec.rb b/library/getoptlong/each_spec.rb index d9022f02af..d40b17d8cb 100644 --- a/library/getoptlong/each_spec.rb +++ b/library/getoptlong/each_spec.rb @@ -1,7 +1,10 @@ require_relative '../../spec_helper' -require 'getoptlong' -require_relative 'shared/each' -describe "GetoptLong#each" do - it_behaves_like :getoptlong_each, :each +ruby_version_is ""..."3.4" do + require 'getoptlong' + require_relative 'shared/each' + + describe "GetoptLong#each" do + it_behaves_like :getoptlong_each, :each + end end diff --git a/library/getoptlong/error_message_spec.rb b/library/getoptlong/error_message_spec.rb index 1ed9419f6c..bcca728720 100644 --- a/library/getoptlong/error_message_spec.rb +++ b/library/getoptlong/error_message_spec.rb @@ -1,23 +1,26 @@ require_relative '../../spec_helper' -require 'getoptlong' -describe "GetoptLong#error_message" do - it "returns nil if no error occurred" do - opts = GetoptLong.new - opts.error_message.should == nil - end +ruby_version_is ""..."3.4" do + require 'getoptlong' - it "returns the error message of the last error that occurred" do - argv [] do + describe "GetoptLong#error_message" do + it "returns nil if no error occurred" do opts = GetoptLong.new - opts.quiet = true - opts.get - -> { - opts.ordering = GetoptLong::PERMUTE - }.should raise_error(ArgumentError) { |e| - e.message.should == "argument error" - opts.error_message.should == "argument error" - } + opts.error_message.should == nil + end + + it "returns the error message of the last error that occurred" do + argv [] do + opts = GetoptLong.new + opts.quiet = true + opts.get + -> { + opts.ordering = GetoptLong::PERMUTE + }.should raise_error(ArgumentError) { |e| + e.message.should == "argument error" + opts.error_message.should == "argument error" + } + end end end end diff --git a/library/getoptlong/get_option_spec.rb b/library/getoptlong/get_option_spec.rb index 3cb2044379..f8f81bce50 100644 --- a/library/getoptlong/get_option_spec.rb +++ b/library/getoptlong/get_option_spec.rb @@ -1,7 +1,10 @@ require_relative '../../spec_helper' -require 'getoptlong' -require_relative 'shared/get' -describe "GetoptLong#get_option" do - it_behaves_like :getoptlong_get, :get_option +ruby_version_is ""..."3.4" do + require 'getoptlong' + require_relative 'shared/get' + + describe "GetoptLong#get_option" do + it_behaves_like :getoptlong_get, :get_option + end end diff --git a/library/getoptlong/get_spec.rb b/library/getoptlong/get_spec.rb index a8ec586fc9..bb901dff78 100644 --- a/library/getoptlong/get_spec.rb +++ b/library/getoptlong/get_spec.rb @@ -1,7 +1,10 @@ require_relative '../../spec_helper' -require 'getoptlong' -require_relative 'shared/get' -describe "GetoptLong#get" do - it_behaves_like :getoptlong_get, :get +ruby_version_is ""..."3.4" do + require 'getoptlong' + require_relative 'shared/get' + + describe "GetoptLong#get" do + it_behaves_like :getoptlong_get, :get + end end diff --git a/library/getoptlong/initialize_spec.rb b/library/getoptlong/initialize_spec.rb index 782edbd981..f0e5d605b2 100644 --- a/library/getoptlong/initialize_spec.rb +++ b/library/getoptlong/initialize_spec.rb @@ -1,28 +1,31 @@ require_relative '../../spec_helper' -require 'getoptlong' -describe "GetoptLong#initialize" do - it "sets ordering to REQUIRE_ORDER if ENV['POSIXLY_CORRECT'] is set" do - begin - old_env_value = ENV["POSIXLY_CORRECT"] - ENV["POSIXLY_CORRECT"] = "" +ruby_version_is ""..."3.4" do + require 'getoptlong' - opt = GetoptLong.new - opt.ordering.should == GetoptLong::REQUIRE_ORDER - ensure - ENV["POSIXLY_CORRECT"] = old_env_value + describe "GetoptLong#initialize" do + it "sets ordering to REQUIRE_ORDER if ENV['POSIXLY_CORRECT'] is set" do + begin + old_env_value = ENV["POSIXLY_CORRECT"] + ENV["POSIXLY_CORRECT"] = "" + + opt = GetoptLong.new + opt.ordering.should == GetoptLong::REQUIRE_ORDER + ensure + ENV["POSIXLY_CORRECT"] = old_env_value + end end - end - it "sets ordering to PERMUTE if ENV['POSIXLY_CORRECT'] is not set" do - begin - old_env_value = ENV["POSIXLY_CORRECT"] - ENV["POSIXLY_CORRECT"] = nil + it "sets ordering to PERMUTE if ENV['POSIXLY_CORRECT'] is not set" do + begin + old_env_value = ENV["POSIXLY_CORRECT"] + ENV["POSIXLY_CORRECT"] = nil - opt = GetoptLong.new - opt.ordering.should == GetoptLong::PERMUTE - ensure - ENV["POSIXLY_CORRECT"] = old_env_value + opt = GetoptLong.new + opt.ordering.should == GetoptLong::PERMUTE + ensure + ENV["POSIXLY_CORRECT"] = old_env_value + end end end end diff --git a/library/getoptlong/ordering_spec.rb b/library/getoptlong/ordering_spec.rb index 695d1cafa7..b0b5b9be54 100644 --- a/library/getoptlong/ordering_spec.rb +++ b/library/getoptlong/ordering_spec.rb @@ -1,38 +1,41 @@ require_relative '../../spec_helper' -require 'getoptlong' -describe "GetoptLong#ordering=" do - it "raises an ArgumentError if called after processing has started" do - argv [ "--size", "10k", "--verbose" ] do - opts = GetoptLong.new([ '--size', GetoptLong::REQUIRED_ARGUMENT ], - [ '--verbose', GetoptLong::NO_ARGUMENT ]) - opts.quiet = true - opts.get +ruby_version_is ""..."3.4" do + require 'getoptlong' - -> { - opts.ordering = GetoptLong::PERMUTE - }.should raise_error(ArgumentError) + describe "GetoptLong#ordering=" do + it "raises an ArgumentError if called after processing has started" do + argv [ "--size", "10k", "--verbose" ] do + opts = GetoptLong.new([ '--size', GetoptLong::REQUIRED_ARGUMENT ], + [ '--verbose', GetoptLong::NO_ARGUMENT ]) + opts.quiet = true + opts.get + + -> { + opts.ordering = GetoptLong::PERMUTE + }.should raise_error(ArgumentError) + end end - end - it "raises an ArgumentError if given an invalid value" do - opts = GetoptLong.new + it "raises an ArgumentError if given an invalid value" do + opts = GetoptLong.new - -> { - opts.ordering = 12345 - }.should raise_error(ArgumentError) - end + -> { + opts.ordering = 12345 + }.should raise_error(ArgumentError) + end - it "does not allow changing ordering to PERMUTE if ENV['POSIXLY_CORRECT'] is set" do - begin - old_env_value = ENV['POSIXLY_CORRECT'] - ENV['POSIXLY_CORRECT'] = "" + it "does not allow changing ordering to PERMUTE if ENV['POSIXLY_CORRECT'] is set" do + begin + old_env_value = ENV['POSIXLY_CORRECT'] + ENV['POSIXLY_CORRECT'] = "" - opts = GetoptLong.new - opts.ordering = GetoptLong::PERMUTE - opts.ordering.should == GetoptLong::REQUIRE_ORDER - ensure - ENV['POSIXLY_CORRECT'] = old_env_value + opts = GetoptLong.new + opts.ordering = GetoptLong::PERMUTE + opts.ordering.should == GetoptLong::REQUIRE_ORDER + ensure + ENV['POSIXLY_CORRECT'] = old_env_value + end end end end diff --git a/library/getoptlong/set_options_spec.rb b/library/getoptlong/set_options_spec.rb index 36b9c579c4..0e77696a95 100644 --- a/library/getoptlong/set_options_spec.rb +++ b/library/getoptlong/set_options_spec.rb @@ -1,98 +1,101 @@ require_relative '../../spec_helper' -require 'getoptlong' -describe "GetoptLong#set_options" do - before :each do - @opts = GetoptLong.new - end +ruby_version_is ""..."3.4" do + require 'getoptlong' + + describe "GetoptLong#set_options" do + before :each do + @opts = GetoptLong.new + end - it "allows setting command line options" do - argv ["--size", "10k", "-v", "arg1", "arg2"] do - @opts.set_options( - ["--size", GetoptLong::REQUIRED_ARGUMENT], - ["--verbose", "-v", GetoptLong::NO_ARGUMENT] - ) + it "allows setting command line options" do + argv ["--size", "10k", "-v", "arg1", "arg2"] do + @opts.set_options( + ["--size", GetoptLong::REQUIRED_ARGUMENT], + ["--verbose", "-v", GetoptLong::NO_ARGUMENT] + ) - @opts.get.should == ["--size", "10k"] - @opts.get.should == ["--verbose", ""] - @opts.get.should == nil + @opts.get.should == ["--size", "10k"] + @opts.get.should == ["--verbose", ""] + @opts.get.should == nil + end end - end - it "discards previously defined command line options" do - argv ["--size", "10k", "-v", "arg1", "arg2"] do - @opts.set_options( - ["--size", GetoptLong::REQUIRED_ARGUMENT], - ["--verbose", "-v", GetoptLong::NO_ARGUMENT] - ) + it "discards previously defined command line options" do + argv ["--size", "10k", "-v", "arg1", "arg2"] do + @opts.set_options( + ["--size", GetoptLong::REQUIRED_ARGUMENT], + ["--verbose", "-v", GetoptLong::NO_ARGUMENT] + ) - @opts.set_options( - ["-s", "--size", GetoptLong::REQUIRED_ARGUMENT], - ["-v", GetoptLong::NO_ARGUMENT] - ) + @opts.set_options( + ["-s", "--size", GetoptLong::REQUIRED_ARGUMENT], + ["-v", GetoptLong::NO_ARGUMENT] + ) - @opts.get.should == ["-s", "10k"] - @opts.get.should == ["-v", ""] - @opts.get.should == nil + @opts.get.should == ["-s", "10k"] + @opts.get.should == ["-v", ""] + @opts.get.should == nil + end end - end - it "raises an ArgumentError if too many argument flags where given" do - argv [] do - -> { - @opts.set_options(["--size", GetoptLong::NO_ARGUMENT, GetoptLong::REQUIRED_ARGUMENT]) - }.should raise_error(ArgumentError) + it "raises an ArgumentError if too many argument flags where given" do + argv [] do + -> { + @opts.set_options(["--size", GetoptLong::NO_ARGUMENT, GetoptLong::REQUIRED_ARGUMENT]) + }.should raise_error(ArgumentError) + end end - end - it "raises a RuntimeError if processing has already started" do - argv [] do - @opts.get - -> { - @opts.set_options() - }.should raise_error(RuntimeError) + it "raises a RuntimeError if processing has already started" do + argv [] do + @opts.get + -> { + @opts.set_options() + }.should raise_error(RuntimeError) + end end - end - it "raises an ArgumentError if no argument flag was given" do - argv [] do - -> { - @opts.set_options(["--size"]) - }.should raise_error(ArgumentError) + it "raises an ArgumentError if no argument flag was given" do + argv [] do + -> { + @opts.set_options(["--size"]) + }.should raise_error(ArgumentError) + end end - end - it "raises an ArgumentError if one of the given arguments is not an Array" do - argv [] do - -> { - @opts.set_options( - ["--size", GetoptLong::REQUIRED_ARGUMENT], - "test") - }.should raise_error(ArgumentError) + it "raises an ArgumentError if one of the given arguments is not an Array" do + argv [] do + -> { + @opts.set_options( + ["--size", GetoptLong::REQUIRED_ARGUMENT], + "test") + }.should raise_error(ArgumentError) + end end - end - it "raises an ArgumentError if the same option is given twice" do - argv [] do - -> { - @opts.set_options( - ["--size", GetoptLong::NO_ARGUMENT], - ["--size", GetoptLong::OPTIONAL_ARGUMENT]) - }.should raise_error(ArgumentError) + it "raises an ArgumentError if the same option is given twice" do + argv [] do + -> { + @opts.set_options( + ["--size", GetoptLong::NO_ARGUMENT], + ["--size", GetoptLong::OPTIONAL_ARGUMENT]) + }.should raise_error(ArgumentError) - -> { - @opts.set_options( - ["--size", GetoptLong::NO_ARGUMENT], - ["-s", "--size", GetoptLong::OPTIONAL_ARGUMENT]) - }.should raise_error(ArgumentError) + -> { + @opts.set_options( + ["--size", GetoptLong::NO_ARGUMENT], + ["-s", "--size", GetoptLong::OPTIONAL_ARGUMENT]) + }.should raise_error(ArgumentError) + end end - end - it "raises an ArgumentError if the given option is invalid" do - argv [] do - -> { - @opts.set_options(["-size", GetoptLong::NO_ARGUMENT]) - }.should raise_error(ArgumentError) + it "raises an ArgumentError if the given option is invalid" do + argv [] do + -> { + @opts.set_options(["-size", GetoptLong::NO_ARGUMENT]) + }.should raise_error(ArgumentError) + end end end end diff --git a/library/getoptlong/terminate_spec.rb b/library/getoptlong/terminate_spec.rb index a12d1df2ef..f767fcaa0a 100644 --- a/library/getoptlong/terminate_spec.rb +++ b/library/getoptlong/terminate_spec.rb @@ -1,30 +1,33 @@ require_relative '../../spec_helper' -require 'getoptlong' -describe "GetoptLong#terminate" 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 +ruby_version_is ""..."3.4" do + require 'getoptlong' - it "terminates option processing" do - argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do - @opts.get.should == [ "--size", "10k" ] - @opts.terminate - @opts.get.should == nil + describe "GetoptLong#terminate" 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 - end - it "returns self when option processing is terminated" do - @opts.terminate.should == @opts - end + it "terminates option processing" do + argv [ "--size", "10k", "-v", "-q", "a.txt", "b.txt" ] do + @opts.get.should == [ "--size", "10k" ] + @opts.terminate + @opts.get.should == nil + end + end - it "returns nil when option processing was already terminated" do - @opts.terminate - @opts.terminate.should == nil + it "returns self when option processing is terminated" do + @opts.terminate.should == @opts + end + + it "returns nil when option processing was already terminated" do + @opts.terminate + @opts.terminate.should == nil + end end end diff --git a/library/getoptlong/terminated_spec.rb b/library/getoptlong/terminated_spec.rb index 6108a7f6e9..06c2ce71f4 100644 --- a/library/getoptlong/terminated_spec.rb +++ b/library/getoptlong/terminated_spec.rb @@ -1,17 +1,20 @@ require_relative '../../spec_helper' -require 'getoptlong' -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.should_not.terminated? +ruby_version_is ""..."3.4" do + require 'getoptlong' - opts.get.should == ["--size", "10k"] - opts.should_not.terminated? + 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.should_not.terminated? - opts.get.should == nil - opts.should.terminated? + opts.get.should == ["--size", "10k"] + opts.should_not.terminated? + + opts.get.should == nil + opts.should.terminated? + end end end end