Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Ruby 3.4 #148

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ jobs:
fail-fast: false
matrix:
ruby:
- "3.4"
- "3.3"
- "3.2"
- "3.1"
- "3.0"
include:
- ruby: "3.2"
coverage: "true"
Expand Down
13 changes: 10 additions & 3 deletions spec/integration/inherited_commands_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@

it "works for subclasses" do
output = `based subrun application_name command_to_run`
expect(output).to eq(
"Run - App: application_name - Command: command_to_run - Options: {:verbosity=>\"INFO\"}\n"
)

if RUBY_VERSION < "3.4"
expect(output).to eq(
"Run - App: application_name - Command: command_to_run - Options: {:verbosity=>\"INFO\"}\n"
)
else
expect(output).to eq(
"Run - App: application_name - Command: command_to_run - Options: {verbosity: \"INFO\"}\n"
)
end
end
end
19 changes: 14 additions & 5 deletions spec/integration/inline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,20 @@

it "with underscored option_one" do
output = `inline first_arg -1 test2 -bd test3`
expect(output).to eq(
"mandatory_arg: first_arg. optional_arg: optional_arg. " \
'Options: {:option_with_default=>"test3", :option_one=>"test2", :boolean_option=>true}' \
"\n"
)

if RUBY_VERSION < "3.4"
expect(output).to eq(
"mandatory_arg: first_arg. optional_arg: optional_arg. " \
'Options: {:option_with_default=>"test3", :option_one=>"test2", :boolean_option=>true}' \
"\n"
)
else
expect(output).to eq(
"mandatory_arg: first_arg. optional_arg: optional_arg. " \
'Options: {option_with_default: "test3", option_one: "test2", boolean_option: true}' \
"\n"
)
end
end
end
end
32 changes: 24 additions & 8 deletions spec/integration/single_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,34 @@

it "with option_one" do
output = `baz first_arg --option-one=test2`
expect(output).to eq(
"mandatory_arg: first_arg. optional_arg: optional_arg. " \
"Options: {:option_with_default=>\"test\", :option_one=>\"test2\"}\n"
)

if RUBY_VERSION < "3.4"
expect(output).to eq(
"mandatory_arg: first_arg. optional_arg: optional_arg. " \
"Options: {:option_with_default=>\"test\", :option_one=>\"test2\"}\n"
)
else
expect(output).to eq(
"mandatory_arg: first_arg. optional_arg: optional_arg. " \
"Options: {option_with_default: \"test\", option_one: \"test2\"}\n"
)
end
end

it "with combination of aliases" do
output = `baz first_arg -bd test3`
expect(output).to eq(
"mandatory_arg: first_arg. optional_arg: optional_arg. " \
"Options: {:option_with_default=>\"test3\", :boolean_option=>true}\n"
)

if RUBY_VERSION < "3.4"
expect(output).to eq(
"mandatory_arg: first_arg. optional_arg: optional_arg. " \
"Options: {:option_with_default=>\"test3\", :boolean_option=>true}\n"
)
else
expect(output).to eq(
"mandatory_arg: first_arg. optional_arg: optional_arg. " \
"Options: {option_with_default: \"test3\", boolean_option: true}\n"
)
end
end
end

Expand Down
30 changes: 21 additions & 9 deletions spec/integration/third_party_gems_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,27 @@
it "allows to add callbacks as a block" do
output = `foo callbacks . --url=https://hanamirb.test`

expected = <<~OUTPUT
before command callback Foo::Webpack::CLI::CallbacksCommand {:url=>"https://hanamirb.test", :dir=>"."}
before callback (class), 2 arg(s): {:url=>"https://hanamirb.test", :dir=>"."}
before callback (object), 2 arg(s): {:url=>"https://hanamirb.test", :dir=>"."}
dir: ., url: "https://hanamirb.test"
after command callback Foo::Webpack::CLI::CallbacksCommand {:url=>"https://hanamirb.test", :dir=>"."}
after callback (class), 2 arg(s): {:url=>"https://hanamirb.test", :dir=>"."}
after callback (object), 2 arg(s): {:url=>"https://hanamirb.test", :dir=>"."}
OUTPUT
if RUBY_VERSION < "3.4"
expected = <<~OUTPUT
before command callback Foo::Webpack::CLI::CallbacksCommand {:url=>"https://hanamirb.test", :dir=>"."}
before callback (class), 2 arg(s): {:url=>"https://hanamirb.test", :dir=>"."}
before callback (object), 2 arg(s): {:url=>"https://hanamirb.test", :dir=>"."}
dir: ., url: "https://hanamirb.test"
after command callback Foo::Webpack::CLI::CallbacksCommand {:url=>"https://hanamirb.test", :dir=>"."}
after callback (class), 2 arg(s): {:url=>"https://hanamirb.test", :dir=>"."}
after callback (object), 2 arg(s): {:url=>"https://hanamirb.test", :dir=>"."}
OUTPUT
else
expected = <<~OUTPUT
before command callback Foo::Webpack::CLI::CallbacksCommand {url: "https://hanamirb.test", dir: "."}
before callback (class), 2 arg(s): {url: "https://hanamirb.test", dir: "."}
before callback (object), 2 arg(s): {url: "https://hanamirb.test", dir: "."}
dir: ., url: "https://hanamirb.test"
after command callback Foo::Webpack::CLI::CallbacksCommand {url: "https://hanamirb.test", dir: "."}
after callback (class), 2 arg(s): {url: "https://hanamirb.test", dir: "."}
after callback (object), 2 arg(s): {url: "https://hanamirb.test", dir: "."}
OUTPUT
end
expect(output).to eq(expected)
end
end
106 changes: 88 additions & 18 deletions spec/support/shared_examples/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,34 +29,84 @@
context "works with params" do
it "without params" do
output = capture_output { cli.call(arguments: ["server"]) }
expect(output).to eq("server - {:code_reloading=>true, :deps=>[\"dep1\", \"dep2\"]}\n")

if RUBY_VERSION < "3.4"
expect(output).to eq("server - {:code_reloading=>true, :deps=>[\"dep1\", \"dep2\"]}\n")
else
expect(output).to eq("server - {code_reloading: true, deps: [\"dep1\", \"dep2\"]}\n")
end
end

it "a param using space" do
output = capture_output { cli.call(arguments: %w[server --server thin]) }
expect(output).to eq("server - {:code_reloading=>true, :deps=>[\"dep1\", \"dep2\"], :server=>\"thin\"}\n")

if RUBY_VERSION < "3.4"
expect(output).to eq("server - {:code_reloading=>true, :deps=>[\"dep1\", \"dep2\"], :server=>\"thin\"}\n")
else
expect(output).to eq("server - {code_reloading: true, deps: [\"dep1\", \"dep2\"], server: \"thin\"}\n")
end
end

it "a param using equal sign" do
output = capture_output { cli.call(arguments: %w[server --host=localhost]) }
expect(output).to eq("server - {:code_reloading=>true, :deps=>[\"dep1\", \"dep2\"], :host=>\"localhost\"}\n")

if RUBY_VERSION < "3.4"
expect(output).to eq("server - {:code_reloading=>true, :deps=>[\"dep1\", \"dep2\"], :host=>\"localhost\"}\n")
else
expect(output).to eq("server - {code_reloading: true, deps: [\"dep1\", \"dep2\"], host: \"localhost\"}\n")
end
end

it "a param using alias" do
output = capture_output { cli.call(arguments: %w[options-with-aliases -u test]) }
expect(output).to eq("options with aliases - {:opt=>false, :url=>\"test\"}\n")
context "with aliases" do
it "includes a space" do
output = capture_output { cli.call(arguments: %w[options-with-aliases -u test]) }

output = capture_output { cli.call(arguments: %w[options-with-aliases -utest]) }
expect(output).to eq("options with aliases - {:opt=>false, :url=>\"test\"}\n")
if RUBY_VERSION < "3.4"
expect(output).to eq("options with aliases - {:opt=>false, :url=>\"test\"}\n")
else
expect(output).to eq("options with aliases - {opt: false, url: \"test\"}\n")
end
end

output = capture_output { cli.call(arguments: %w[options-with-aliases -f -u test]) }
expect(output).to eq("options with aliases - {:opt=>false, :flag=>true, :url=>\"test\"}\n")
it "doesn't include a space" do
output = capture_output { cli.call(arguments: %w[options-with-aliases -utest]) }

if RUBY_VERSION < "3.4"
expect(output).to eq("options with aliases - {:opt=>false, :url=>\"test\"}\n")
else
expect(output).to eq("options with aliases - {opt: false, url: \"test\"}\n")
end
end

it "has multiple aliases" do
output = capture_output { cli.call(arguments: %w[options-with-aliases -f -u test]) }

if RUBY_VERSION < "3.4"
expect(output).to eq("options with aliases - {:opt=>false, :flag=>true, :url=>\"test\"}\n")
else
expect(output).to eq("options with aliases - {opt: false, flag: true, url: \"test\"}\n")
end
end

output = capture_output { cli.call(arguments: %w[options-with-aliases -o]) }
expect(output).to eq("options with aliases - {:opt=>true}\n")
it "uses an alias to override a default value" do
output = capture_output { cli.call(arguments: %w[options-with-aliases -o]) }

output = capture_output { cli.call(arguments: %w[options-with-aliases -of]) }
expect(output).to eq("options with aliases - {:opt=>true, :flag=>true}\n")
if RUBY_VERSION < "3.4"
expect(output).to eq("options with aliases - {:opt=>true}\n")
else
expect(output).to eq("options with aliases - {opt: true}\n")
end
end

it "uses an alias to override a default value, combined with a flag alias" do
output = capture_output { cli.call(arguments: %w[options-with-aliases -of]) }

if RUBY_VERSION < "3.4"
expect(output).to eq("options with aliases - {:opt=>true, :flag=>true}\n")
else
expect(output).to eq("options with aliases - {opt: true, flag: true}\n")
end
end
end

it "a param with unknown param" do
Expand All @@ -66,18 +116,38 @@

it "with boolean param" do
output = capture_output { cli.call(arguments: ["server"]) }
expect(output).to eq("server - {:code_reloading=>true, :deps=>[\"dep1\", \"dep2\"]}\n")

if RUBY_VERSION < "3.4"
expect(output).to eq("server - {:code_reloading=>true, :deps=>[\"dep1\", \"dep2\"]}\n")
else
expect(output).to eq("server - {code_reloading: true, deps: [\"dep1\", \"dep2\"]}\n")
end

output = capture_output { cli.call(arguments: %w[server --no-code-reloading]) }
expect(output).to eq("server - {:code_reloading=>false, :deps=>[\"dep1\", \"dep2\"]}\n")

if RUBY_VERSION < "3.4"
expect(output).to eq("server - {:code_reloading=>false, :deps=>[\"dep1\", \"dep2\"]}\n")
else
expect(output).to eq("server - {code_reloading: false, deps: [\"dep1\", \"dep2\"]}\n")
end
end

it "with flag param" do
output = capture_output { cli.call(arguments: ["server"]) }
expect(output).to eq("server - {:code_reloading=>true, :deps=>[\"dep1\", \"dep2\"]}\n")

if RUBY_VERSION < "3.4"
expect(output).to eq("server - {:code_reloading=>true, :deps=>[\"dep1\", \"dep2\"]}\n")
else
expect(output).to eq("server - {code_reloading: true, deps: [\"dep1\", \"dep2\"]}\n")
end

output = capture_output { cli.call(arguments: %w[server --quiet]) }
expect(output).to eq("server - {:code_reloading=>true, :deps=>[\"dep1\", \"dep2\"], :quiet=>true}\n")

if RUBY_VERSION < "3.4"
expect(output).to eq("server - {:code_reloading=>true, :deps=>[\"dep1\", \"dep2\"], :quiet=>true}\n")
else
expect(output).to eq("server - {code_reloading: true, deps: [\"dep1\", \"dep2\"], quiet: true}\n")
end
end

context "with array param" do
Expand Down
28 changes: 24 additions & 4 deletions spec/support/shared_examples/inherited_commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,26 +143,46 @@
context "with inherited options" do
it "run has default verbosity_level" do
output = capture_output { cli.call(arguments: %w[i run application_name command_name]) }
expect(output).to include('Options: {:verbosity=>"INFO"}')

if RUBY_VERSION < "3.4"
expect(output).to include('Options: {:verbosity=>"INFO"}')
else
expect(output).to include('Options: {verbosity: "INFO"}')
end
end

it "subrun has default verbosity_level too" do
output = capture_output { cli.call(arguments: %w[i subrun application_name command_name]) }
expect(output).to include('Options: {:verbosity=>"INFO"}')

if RUBY_VERSION < "3.4"
expect(output).to include('Options: {:verbosity=>"INFO"}')
else
expect(output).to include('Options: {verbosity: "INFO"}')
end
end

it "addons has verbosity_level set to debug" do
output = capture_output do
cli.call(arguments: %w[i addons application_name --verbosity=DEBUG])
end
expect(output).to include("Options: {:verbosity=>\"DEBUG\", :json=>false}")

if RUBY_VERSION < "3.4"
expect(output).to include("Options: {:verbosity=>\"DEBUG\", :json=>false}")
else
expect(output).to include("Options: {verbosity: \"DEBUG\", json: false}")
end
end

it "logs has verbosity_level set to WARNING" do
output = capture_output do
cli.call(arguments: %w[i logs application_name --verbosity=WARNING])
end
expect(output).to include("Options: {:verbosity=>\"WARNING\"}")

if RUBY_VERSION < "3.4"
expect(output).to include("Options: {:verbosity=>\"WARNING\"}")
else
expect(output).to include("Options: {verbosity: \"WARNING\"}")
end
end
end

Expand Down
Loading