From 9c1a4c8fbc847c3137e936731605e3054b2c8543 Mon Sep 17 00:00:00 2001 From: Alessandro Fazzi Date: Mon, 3 Jan 2022 22:03:27 +0100 Subject: [PATCH] Update (and adapt code) for Ruby 3.0.2 --- .rubocop.yml | 2 +- .ruby-version | 2 +- lib/wordmove.rb | 4 +-- lib/wordmove/cli.rb | 16 +++++----- lib/wordmove/organizers/ftp/pull.rb | 4 ++- lib/wordmove/organizers/ftp/push.rb | 4 ++- lib/wordmove/organizers/ssh/pull.rb | 4 ++- lib/wordmove/organizers/ssh/push.rb | 4 ++- spec/{docotor_spec.rb => doctor_spec.rb} | 0 spec/hook_spec.rb | 38 ++++++++++++------------ spec/support/action_helpers.rb | 5 +--- wordmove.gemspec | 2 +- 12 files changed, 45 insertions(+), 40 deletions(-) rename spec/{docotor_spec.rb => doctor_spec.rb} (100%) diff --git a/.rubocop.yml b/.rubocop.yml index a23763b..2355089 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,5 @@ AllCops: - TargetRubyVersion: 2.7.1 + TargetRubyVersion: 3.0.2 DisplayCopNames: true DisplayStyleGuide: true NewCops: enable diff --git a/.ruby-version b/.ruby-version index 860487c..b502146 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.7.1 +3.0.2 diff --git a/lib/wordmove.rb b/lib/wordmove.rb index 337af73..7ed6da0 100644 --- a/lib/wordmove.rb +++ b/lib/wordmove.rb @@ -43,8 +43,8 @@ require 'wordmove/actions/helpers' require 'wordmove/actions/ssh/helpers' require 'wordmove/actions/ftp/helpers' -Dir[File.join(__dir__, 'wordmove/actions/**/*.rb')].sort.each { |file| require file } -Dir[File.join(__dir__, 'wordmove/organizers/**/*.rb')].sort.each { |file| require file } +Dir[File.join(__dir__, 'wordmove/actions/**/*.rb')].each { |file| require file } +Dir[File.join(__dir__, 'wordmove/organizers/**/*.rb')].each { |file| require file } module Wordmove # Interactors' namespce. Interactors are called "Actions", following the LightService convention. diff --git a/lib/wordmove/cli.rb b/lib/wordmove/cli.rb index f127227..ff9c42d 100644 --- a/lib/wordmove/cli.rb +++ b/lib/wordmove/cli.rb @@ -47,8 +47,8 @@ def movefile_from(**cli_options) exit 1 end - def call_organizer_with(klass:, movefile:, **cli_options) - result = klass.call(cli_options: cli_options, movefile: movefile) + def call_organizer_with(klass:, movefile:, cli_options:) + result = klass.call(cli_options, movefile) exit 0 if result.success? @@ -114,19 +114,19 @@ def call(**cli_options) private def call_pull_organizer_with(**cli_options) - movefile = movefile_from(**cli_options) + movefile = movefile_from(cli_options) if movefile.options.dig(movefile.environment, :ssh) call_organizer_with( klass: Wordmove::Organizers::Ssh::Pull, movefile: movefile, - **cli_options + cli_options: cli_options ) elsif movefile.options.dig(movefile.environment, :ftp) call_organizer_with( klass: Wordmove::Organizers::Ftp::Pull, movefile: movefile, - **cli_options + cli_options: cli_options ) else raise NoAdapterFound, 'No valid adapter found.' @@ -149,19 +149,19 @@ def call(**cli_options) private def call_push_organizer_with(**cli_options) - movefile = movefile_from(**cli_options) + movefile = movefile_from(cli_options) if movefile.options.dig(movefile.environment, :ssh) call_organizer_with( klass: Wordmove::Organizers::Ssh::Push, movefile: movefile, - **cli_options + cli_options: cli_options ) elsif movefile.options.dig(movefile.environment, :ftp) call_organizer_with( klass: Wordmove::Organizers::Ftp::Push, movefile: movefile, - **cli_options + cli_options: cli_options ) else raise NoAdapterFound, 'No valid adapter found.' diff --git a/lib/wordmove/organizers/ftp/pull.rb b/lib/wordmove/organizers/ftp/pull.rb index 4e3845d..e95a175 100644 --- a/lib/wordmove/organizers/ftp/pull.rb +++ b/lib/wordmove/organizers/ftp/pull.rb @@ -6,7 +6,9 @@ class Pull include Wordmove::Actions::Helpers include Wordmove::Actions::Ftp::Helpers - def self.call(cli_options:, movefile:) + # Can't use keyword arguments since LightService still has some problems with modern + # ruby syntax: https://github.com/adomokos/light-service/pull/224 + def self.call(cli_options, movefile) logger = Logger.new($stdout, movefile.secrets).tap { |l| l.level = Logger::DEBUG } remote_options = movefile.options[movefile.environment] ftp_opts = ftp_options(remote_options: remote_options) diff --git a/lib/wordmove/organizers/ftp/push.rb b/lib/wordmove/organizers/ftp/push.rb index 61bcc47..5e1519a 100644 --- a/lib/wordmove/organizers/ftp/push.rb +++ b/lib/wordmove/organizers/ftp/push.rb @@ -6,7 +6,9 @@ class Push include Wordmove::Actions::Helpers include Wordmove::Actions::Ftp::Helpers - def self.call(cli_options:, movefile:) + # Can't use keyword arguments since LightService still has some problems with modern + # ruby syntax: https://github.com/adomokos/light-service/pull/224 + def self.call(cli_options, movefile) logger = Logger.new($stdout, movefile.secrets).tap { |l| l.level = Logger::DEBUG } remote_options = movefile.options[movefile.environment] ftp_opts = ftp_options(remote_options: remote_options) diff --git a/lib/wordmove/organizers/ssh/pull.rb b/lib/wordmove/organizers/ssh/pull.rb index b5c2402..7bf2331 100644 --- a/lib/wordmove/organizers/ssh/pull.rb +++ b/lib/wordmove/organizers/ssh/pull.rb @@ -6,7 +6,9 @@ class Pull include Wordmove::Actions::Helpers include Wordmove::Actions::Ssh::Helpers - def self.call(cli_options:, movefile:) + # Can't use keyword arguments since LightService still has some problems with modern + # ruby syntax: https://github.com/adomokos/light-service/pull/224 + def self.call(cli_options, movefile) logger = Logger.new($stdout, movefile.secrets).tap { |l| l.level = Logger::DEBUG } remote_options = movefile.options[movefile.environment] ssh_opts = ssh_options(remote_options: remote_options, simulate: cli_options[:simulate]) diff --git a/lib/wordmove/organizers/ssh/push.rb b/lib/wordmove/organizers/ssh/push.rb index e1e03e8..e3548fd 100644 --- a/lib/wordmove/organizers/ssh/push.rb +++ b/lib/wordmove/organizers/ssh/push.rb @@ -6,7 +6,9 @@ class Push include Wordmove::Actions::Helpers include Wordmove::Actions::Ssh::Helpers - def self.call(cli_options:, movefile:) + # Can't use keyword arguments since LightService still has some problems with modern + # ruby syntax: https://github.com/adomokos/light-service/pull/224 + def self.call(cli_options, movefile) logger = Logger.new($stdout, movefile.secrets).tap { |l| l.level = Logger::DEBUG } remote_options = movefile.options[movefile.environment] ssh_opts = ssh_options(remote_options: remote_options, simulate: cli_options[:simulate]) diff --git a/spec/docotor_spec.rb b/spec/doctor_spec.rb similarity index 100% rename from spec/docotor_spec.rb rename to spec/doctor_spec.rb diff --git a/spec/hook_spec.rb b/spec/hook_spec.rb index 1903819..426ff2f 100644 --- a/spec/hook_spec.rb +++ b/spec/hook_spec.rb @@ -54,7 +54,7 @@ end it 'checks the order' do - Wordmove::Organizers::Ssh::Push.call(context) + Wordmove::Organizers::Ssh::Push.call(context[:cli_options], context[:movefile]) expect(Wordmove::Hook::Local).to( have_received(:run).with( @@ -107,31 +107,31 @@ let(:options) { common_options.merge(environment: 'ssh_with_hooks') } it 'runs registered before local hooks' do - expect { Wordmove::Organizers::Ssh::Push.call(context) } + expect { Wordmove::Organizers::Ssh::Push.call(context[:cli_options], context[:movefile]) } .to output(/Calling hook push before local/) .to_stdout end it 'runs registered before local hooks in the wordpress folder' do - expect { Wordmove::Organizers::Ssh::Push.call(context) } + expect { Wordmove::Organizers::Ssh::Push.call(context[:cli_options], context[:movefile]) } .to output(/#{Dir.tmpdir}/) .to_stdout end it 'runs registered before remote hooks' do - expect { Wordmove::Organizers::Ssh::Push.call(context) } + expect { Wordmove::Organizers::Ssh::Push.call(context[:cli_options], context[:movefile]) } .to output(/Calling hook push before remote/) .to_stdout end it 'runs registered after local hooks' do - expect { Wordmove::Organizers::Ssh::Push.call(context) } + expect { Wordmove::Organizers::Ssh::Push.call(context[:cli_options], context[:movefile]) } .to output(/Calling hook push after local/) .to_stdout end it 'runs registered after remote hooks' do - expect { Wordmove::Organizers::Ssh::Push.call(context) } + expect { Wordmove::Organizers::Ssh::Push.call(context[:cli_options], context[:movefile]) } .to output(/Calling hook push after remote/) .to_stdout end @@ -142,7 +142,7 @@ end it 'does not really run any commands' do - expect { Wordmove::Organizers::Ssh::Push.call(context) } + expect { Wordmove::Organizers::Ssh::Push.call(context[:cli_options], context[:movefile]) } .not_to output(/Output:/) .to_stdout end @@ -154,7 +154,7 @@ it 'logs an error and raises a LocalHookException' do expect do expect do - Wordmove::Organizers::Ssh::Push.call(context) + Wordmove::Organizers::Ssh::Push.call(context[:cli_options], context[:movefile]) end.to raise_exception(Wordmove::LocalHookException) end.to output(/Error code: 127/).to_stdout end @@ -167,7 +167,7 @@ it 'logs an error without raising an exeption' do expect do expect do - Wordmove::Organizers::Ssh::Push.call(context) + Wordmove::Organizers::Ssh::Push.call(context[:cli_options], context[:movefile]) end.to_not raise_exception end.to output(/Error code: 127/) .to_stdout @@ -187,31 +187,31 @@ let(:options) { common_options.merge(environment: 'ssh_with_hooks') } it 'runs registered before local hooks' do - expect { Wordmove::Organizers::Ssh::Pull.call(context) } + expect { Wordmove::Organizers::Ssh::Pull.call(context[:cli_options], context[:movefile]) } .to output(/Calling hook pull before local/) .to_stdout end it 'runs registered before remote hooks' do - expect { Wordmove::Organizers::Ssh::Pull.call(context) } + expect { Wordmove::Organizers::Ssh::Pull.call(context[:cli_options], context[:movefile]) } .to output(/Calling hook pull before remote/) .to_stdout end it 'runs registered after local hooks' do - expect { Wordmove::Organizers::Ssh::Pull.call(context) } + expect { Wordmove::Organizers::Ssh::Pull.call(context[:cli_options], context[:movefile]) } .to output(/Calling hook pull after local/) .to_stdout end it 'runs registered after remote hooks' do - expect { Wordmove::Organizers::Ssh::Pull.call(context) } + expect { Wordmove::Organizers::Ssh::Pull.call(context[:cli_options], context[:movefile]) } .to output(/Calling hook pull after remote/) .to_stdout end it 'return remote stdout' do - expect { Wordmove::Organizers::Ssh::Pull.call(context) } + expect { Wordmove::Organizers::Ssh::Pull.call(context[:cli_options], context[:movefile]) } .to output(/Stubbed remote stdout/) .to_stdout end @@ -227,7 +227,7 @@ it 'returns remote stdout and raise an exception' do expect do expect do - Wordmove::Organizers::Ssh::Pull.call(context) + Wordmove::Organizers::Ssh::Pull.call(context[:cli_options], context[:movefile]) end.to raise_exception(Wordmove::RemoteHookException) end.to output(/Stubbed remote stderr/) .to_stdout @@ -236,7 +236,7 @@ it 'raises a RemoteHookException' do expect do silence_stream($stdout) do - Wordmove::Organizers::Ssh::Pull.call(context) + Wordmove::Organizers::Ssh::Pull.call(context[:cli_options], context[:movefile]) end end.to raise_exception(Wordmove::RemoteHookException) end @@ -251,7 +251,7 @@ expect(Wordmove::Hook::Remote) .to_not receive(:run) - expect { Wordmove::Organizers::Ftp::Push.call(**context) } + expect { Wordmove::Organizers::Ftp::Push.call(context[:cli_options], context[:movefile]) } .to output( /You have configured remote hooks to run over an FTP connection, but this is not possible/ # rubocop:disable Layout/LineLength ).to_stdout @@ -269,12 +269,12 @@ .to_not receive(:run) silence_stream($stdout) do - Wordmove::Organizers::Ssh::Push.call(context) + Wordmove::Organizers::Ssh::Push.call(context[:cli_options], context[:movefile]) end end it "works silently ignoring 'before' step is not present" do - expect { Wordmove::Organizers::Ssh::Pull.call(context) } + expect { Wordmove::Organizers::Ssh::Pull.call(context[:cli_options], context[:movefile]) } .to output(/I've partially configured my hooks/) .to_stdout end diff --git a/spec/support/action_helpers.rb b/spec/support/action_helpers.rb index 5d56c7b..543472c 100644 --- a/spec/support/action_helpers.rb +++ b/spec/support/action_helpers.rb @@ -45,10 +45,7 @@ def self.make_for(action, wordmove_action, cli_options: {}) LightService::Testing::ContextFactory .make_from("Wordmove::Organizers::Ssh::#{wordmove_action.to_s.camelize}".constantize) .for(action) - .with( - cli_options: cli_options, - movefile: movefile - ) + .with(cli_options, movefile) end end diff --git a/wordmove.gemspec b/wordmove.gemspec index 2b5b272..ef7b8b3 100644 --- a/wordmove.gemspec +++ b/wordmove.gemspec @@ -41,7 +41,7 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency 'dry-cli', '~> 0.7.0' spec.add_runtime_dependency 'dry-files', '~> 0.1.0' - spec.required_ruby_version = '>= 2.6.0' # rubocop:disable Gemspec/RequiredRubyVersion + spec.required_ruby_version = '>= 3.0.2' spec.add_development_dependency 'bundler', '~> 2.3.3' spec.add_development_dependency 'pry-byebug', '~> 3.1'