Skip to content

Commit

Permalink
Revert "spec/mspec/tool/wrap_with_guard.rb 'ruby_version_is ""..."3.4…
Browse files Browse the repository at this point in the history
…"' spec/ruby/library/getoptlong/**/*.rb"

This reverts commit 8538c30.
  • Loading branch information
eregon committed Feb 12, 2024
1 parent af01e55 commit ce834ad
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 214 deletions.
11 changes: 4 additions & 7 deletions library/getoptlong/each_option_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
require_relative '../../spec_helper'
require 'getoptlong'
require_relative 'shared/each'

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
describe "GetoptLong#each_option" do
it_behaves_like :getoptlong_each, :each_option
end
11 changes: 4 additions & 7 deletions library/getoptlong/each_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
require_relative '../../spec_helper'
require 'getoptlong'
require_relative 'shared/each'

ruby_version_is ""..."3.4" do
require 'getoptlong'
require_relative 'shared/each'

describe "GetoptLong#each" do
it_behaves_like :getoptlong_each, :each
end
describe "GetoptLong#each" do
it_behaves_like :getoptlong_each, :each
end
35 changes: 16 additions & 19 deletions library/getoptlong/error_message_spec.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
require_relative '../../spec_helper'
require 'getoptlong'

ruby_version_is ""..."3.4" do
require 'getoptlong'
describe "GetoptLong#error_message" do
it "returns nil if no error occurred" do
opts = GetoptLong.new
opts.error_message.should == nil
end

describe "GetoptLong#error_message" do
it "returns nil if no error occurred" do
it "returns the error message of the last error that occurred" do
argv [] do
opts = GetoptLong.new
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
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
11 changes: 4 additions & 7 deletions library/getoptlong/get_option_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
require_relative '../../spec_helper'
require 'getoptlong'
require_relative 'shared/get'

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
describe "GetoptLong#get_option" do
it_behaves_like :getoptlong_get, :get_option
end
11 changes: 4 additions & 7 deletions library/getoptlong/get_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
require_relative '../../spec_helper'
require 'getoptlong'
require_relative 'shared/get'

ruby_version_is ""..."3.4" do
require 'getoptlong'
require_relative 'shared/get'

describe "GetoptLong#get" do
it_behaves_like :getoptlong_get, :get
end
describe "GetoptLong#get" do
it_behaves_like :getoptlong_get, :get
end
41 changes: 19 additions & 22 deletions library/getoptlong/initialize_spec.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,28 @@
require_relative '../../spec_helper'
require 'getoptlong'

ruby_version_is ""..."3.4" do
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"] = ""

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
opt = GetoptLong.new
opt.ordering.should == GetoptLong::REQUIRE_ORDER
ensure
ENV["POSIXLY_CORRECT"] = old_env_value
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
end
opt = GetoptLong.new
opt.ordering.should == GetoptLong::PERMUTE
ensure
ENV["POSIXLY_CORRECT"] = old_env_value
end
end
end
57 changes: 27 additions & 30 deletions library/getoptlong/ordering_spec.rb
Original file line number Diff line number Diff line change
@@ -1,41 +1,38 @@
require_relative '../../spec_helper'
require 'getoptlong'

ruby_version_is ""..."3.4" do
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

-> {
opts.ordering = GetoptLong::PERMUTE
}.should raise_error(ArgumentError)
end
end

it "raises an ArgumentError if given an invalid value" do
opts = GetoptLong.new
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 = 12345
opts.ordering = GetoptLong::PERMUTE
}.should raise_error(ArgumentError)
end
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 "raises an ArgumentError if given an invalid value" do
opts = GetoptLong.new

opts = GetoptLong.new
opts.ordering = GetoptLong::PERMUTE
opts.ordering.should == GetoptLong::REQUIRE_ORDER
ensure
ENV['POSIXLY_CORRECT'] = old_env_value
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'] = ""

opts = GetoptLong.new
opts.ordering = GetoptLong::PERMUTE
opts.ordering.should == GetoptLong::REQUIRE_ORDER
ensure
ENV['POSIXLY_CORRECT'] = old_env_value
end
end
end
151 changes: 74 additions & 77 deletions library/getoptlong/set_options_spec.rb
Original file line number Diff line number Diff line change
@@ -1,101 +1,98 @@
require_relative '../../spec_helper'
require 'getoptlong'

ruby_version_is ""..."3.4" do
require 'getoptlong'

describe "GetoptLong#set_options" do
before :each do
@opts = GetoptLong.new
end
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
end
@opts.get.should == ["--size", "10k"]
@opts.get.should == ["--verbose", ""]
@opts.get.should == nil
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
end
@opts.get.should == ["-s", "10k"]
@opts.get.should == ["-v", ""]
@opts.get.should == nil
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)
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)
end
end

it "raises a RuntimeError if processing has already started" do
argv [] do
@opts.get
-> {
@opts.set_options()
}.should raise_error(RuntimeError)
end
it "raises a RuntimeError if processing has already started" do
argv [] do
@opts.get
-> {
@opts.set_options()
}.should raise_error(RuntimeError)
end
end

it "raises an ArgumentError if no argument flag was given" do
argv [] do
-> {
@opts.set_options(["--size"])
}.should raise_error(ArgumentError)
end
it "raises an ArgumentError if no argument flag was given" do
argv [] do
-> {
@opts.set_options(["--size"])
}.should raise_error(ArgumentError)
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)
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)
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)
end
-> {
@opts.set_options(
["--size", GetoptLong::NO_ARGUMENT],
["-s", "--size", GetoptLong::OPTIONAL_ARGUMENT])
}.should raise_error(ArgumentError)
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)
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)
end
end
end
Loading

0 comments on commit ce834ad

Please sign in to comment.