Skip to content

Commit

Permalink
spec/mspec/tool/wrap_with_guard.rb 'ruby_version_is ""..."3.4"' spec/…
Browse files Browse the repository at this point in the history
…ruby/library/getoptlong/**/*.rb
  • Loading branch information
hsbt committed Jan 16, 2024
1 parent b68dab2 commit b3ff564
Show file tree
Hide file tree
Showing 10 changed files with 214 additions and 184 deletions.
11 changes: 7 additions & 4 deletions spec/ruby/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
11 changes: 7 additions & 4 deletions spec/ruby/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
35 changes: 19 additions & 16 deletions spec/ruby/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
11 changes: 7 additions & 4 deletions spec/ruby/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
11 changes: 7 additions & 4 deletions spec/ruby/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
41 changes: 22 additions & 19 deletions spec/ruby/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
57 changes: 30 additions & 27 deletions spec/ruby/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
151 changes: 77 additions & 74 deletions spec/ruby/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

0 comments on commit b3ff564

Please sign in to comment.