From 2ee48f034c9120b16d8e908f154abf92bf14cbc8 Mon Sep 17 00:00:00 2001 From: Jonic Linley Date: Thu, 10 Aug 2023 14:19:09 +0100 Subject: [PATCH 1/8] Fix formatter options --- .github/workflows/linters.yml | 2 +- .rspec | 1 - .rubocop | 1 - spec/spec_helper.rb | 12 +++++++++++- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 57ee7e2..1c5ec6f 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -18,4 +18,4 @@ jobs: with: bundler-cache: true - name: Run rubocop - run: bin/rubocop + run: bin/rubocop --format fuubar diff --git a/.rspec b/.rspec index 50bdfbb..83e16f8 100644 --- a/.rspec +++ b/.rspec @@ -1,3 +1,2 @@ --color ---format Fuubar --require spec_helper diff --git a/.rubocop b/.rubocop index 0b51484..ae3b82c 100644 --- a/.rubocop +++ b/.rubocop @@ -1,3 +1,2 @@ --display-style-guide ---format fuubar --parallel diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 7b29f15..3a27c30 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,13 @@ +# Setup Ruby deprecation warnings +# See https://rubyapi.org/2.7/o/warning +# +# Required before Gems to capture warnings from dependecies as well as our application code, will highlight dependencies +# that need to be upgraded or removed. +# +# See the `RubyWarnings` module in `config/initializers/ruby_warnings.rb` to see how we're selectively handling Ruby +# warnings, and how we're able to use that information to aid Ruby upgrades. +Warning[:deprecated] = true + unless ENV["DISABLE_COVERAGE"] require "simplecov" SimpleCov.start do @@ -34,7 +44,7 @@ config.disable_monkey_patching! config.backtrace_exclusion_patterns << /gems/ - config.default_formatter = "doc" if config.files_to_run.one? + config.default_formatter = config.files_to_run.one? ? "doc" : "Fuubar" config.example_status_persistence_file_path = "spec/examples.txt" config.filter_run_when_matching :focus config.order = :random From 9b8c4243a9c886f8206e536f3e8cf000aaec34c5 Mon Sep 17 00:00:00 2001 From: Jonic Linley Date: Thu, 10 Aug 2023 14:19:29 +0100 Subject: [PATCH 2/8] Update virtus and wisper --- Gemfile.lock | 34 ++++++++++++++++------------------ rectify.gemspec | 4 ++-- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1a39df4..1b7ee50 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -5,31 +5,31 @@ PATH activemodel (~> 7.0) activerecord (~> 7.0) activesupport (~> 7.0) - virtus (~> 1.0) - wisper (~> 1.6) + virtus (~> 2.0) + wisper (~> 2.0) GEM remote: https://rubygems.org/ specs: - actionpack (7.0.6) - actionview (= 7.0.6) - activesupport (= 7.0.6) + actionpack (7.0.7) + actionview (= 7.0.7) + activesupport (= 7.0.7) rack (~> 2.0, >= 2.2.4) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actionview (7.0.6) - activesupport (= 7.0.6) + actionview (7.0.7) + activesupport (= 7.0.7) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activemodel (7.0.6) - activesupport (= 7.0.6) - activerecord (7.0.6) - activemodel (= 7.0.6) - activesupport (= 7.0.6) - activesupport (7.0.6) + activemodel (7.0.7) + activesupport (= 7.0.7) + activerecord (7.0.7) + activemodel (= 7.0.7) + activesupport (= 7.0.7) + activesupport (7.0.7) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) @@ -53,7 +53,6 @@ GEM thread_safe (~> 0.3, >= 0.3.1) diff-lcs (1.5.0) docile (1.4.0) - equalizer (0.0.11) erubi (1.12.0) ffi (1.15.5) formatador (1.1.0) @@ -167,7 +166,7 @@ GEM rubocop-performance (1.18.0) rubocop (>= 1.7.0, < 2.0) rubocop-ast (>= 0.4.0) - rubocop-rspec (2.23.0) + rubocop-rspec (2.23.2) rubocop (~> 1.33) rubocop-capybara (~> 2.17) rubocop-factory_bot (~> 2.22) @@ -187,12 +186,11 @@ GEM tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode-display_width (2.4.2) - virtus (1.0.5) + virtus (2.0.0) axiom-types (~> 0.1) coercible (~> 1.0) descendants_tracker (~> 0.0, >= 0.0.3) - equalizer (~> 0.0, >= 0.0.9) - wisper (1.6.1) + wisper (2.0.1) wisper-rspec (1.1.0) PLATFORMS diff --git a/rectify.gemspec b/rectify.gemspec index 2040cdb..74bfff3 100644 --- a/rectify.gemspec +++ b/rectify.gemspec @@ -24,6 +24,6 @@ Gem::Specification.new do |spec| spec.add_dependency "activemodel", "~> 7.0" spec.add_dependency "activerecord", "~> 7.0" spec.add_dependency "activesupport", "~> 7.0" - spec.add_dependency "virtus", "~> 1.0" - spec.add_dependency "wisper", "~> 1.6" + spec.add_dependency "virtus", "~> 2.0" + spec.add_dependency "wisper", "~> 2.0" end From 5b81b54f31569da797e45321f2f841fa9c1ce0eb Mon Sep 17 00:00:00 2001 From: Jonic Linley Date: Thu, 10 Aug 2023 14:19:51 +0100 Subject: [PATCH 3/8] Remove Ruby warning config --- spec/spec_helper.rb | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3a27c30..4f33c0a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,13 +1,3 @@ -# Setup Ruby deprecation warnings -# See https://rubyapi.org/2.7/o/warning -# -# Required before Gems to capture warnings from dependecies as well as our application code, will highlight dependencies -# that need to be upgraded or removed. -# -# See the `RubyWarnings` module in `config/initializers/ruby_warnings.rb` to see how we're selectively handling Ruby -# warnings, and how we're able to use that information to aid Ruby upgrades. -Warning[:deprecated] = true - unless ENV["DISABLE_COVERAGE"] require "simplecov" SimpleCov.start do From b2c45c4fd7c0a13c66264390973a2bbbc6d95225 Mon Sep 17 00:00:00 2001 From: Jonic Linley Date: Tue, 15 Aug 2023 15:30:14 +0100 Subject: [PATCH 4/8] Wrap Command.call with ruby2_keywords --- lib/rectify/command.rb | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/rectify/command.rb b/lib/rectify/command.rb index 5e68fad..f40de1d 100644 --- a/lib/rectify/command.rb +++ b/lib/rectify/command.rb @@ -19,15 +19,17 @@ def respond_to_missing?(_method_name, _include_private = false) class Command include Wisper::Publisher - def self.call(*args, &block) - event_recorder = EventRecorder.new + class << self + ruby2_keywords def call(*args, &block) + event_recorder = EventRecorder.new - command = new(*args) - command.subscribe(event_recorder) - command.evaluate(&block) if block - command.call + command = new(*args) + command.subscribe(event_recorder) + command.evaluate(&block) if block + command.call - event_recorder.events + event_recorder.events + end end def evaluate(&block) From c4f5e74b6c45ac8cd270d34676ac85c8ee244d3d Mon Sep 17 00:00:00 2001 From: Jonic Linley Date: Tue, 15 Aug 2023 15:31:02 +0100 Subject: [PATCH 5/8] Add command specs for kwargs --- spec/lib/rectify/command_spec.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/lib/rectify/command_spec.rb b/spec/lib/rectify/command_spec.rb index bb476e9..4d7f7c1 100644 --- a/spec/lib/rectify/command_spec.rb +++ b/spec/lib/rectify/command_spec.rb @@ -46,6 +46,18 @@ expect(ArgsCommand).to have_received(:new).with(:a, :b, :c) { instance } expect(instance).to have_received(:call) end + + it "supports named arguments" do + NamedArgsCommand.call( + "Andy", + "Pike", + height: 185, + location: "UK", + hobbies: ["running", "climbing", "fishing with grenades"] + ) do + on(:ok) { |message| expect(message).to be_a(String) } + end + end end end From 89c58b0a3165ca8622ae5a8270b9e7146d556f4b Mon Sep 17 00:00:00 2001 From: Jonic Linley Date: Tue, 15 Aug 2023 15:31:18 +0100 Subject: [PATCH 6/8] Renamed fixtures dirs --- spec/fixtures/command/args_command.rb | 3 -- spec/fixtures/commands/args_command.rb | 15 +++++++ .../{command => commands}/error_command.rb | 0 spec/fixtures/commands/named_args_command.rb | 40 +++++++++++++++++++ .../{command => commands}/no_args_command.rb | 0 ...return_multi_event_multi_result_command.rb | 0 .../return_multi_result_command.rb | 0 .../return_single_result_command.rb | 0 .../{command => commands}/success_command.rb | 0 spec/fixtures/queries/users_over_using_sql.rb | 2 +- 10 files changed, 56 insertions(+), 4 deletions(-) delete mode 100644 spec/fixtures/command/args_command.rb create mode 100644 spec/fixtures/commands/args_command.rb rename spec/fixtures/{command => commands}/error_command.rb (100%) create mode 100644 spec/fixtures/commands/named_args_command.rb rename spec/fixtures/{command => commands}/no_args_command.rb (100%) rename spec/fixtures/{command => commands}/return_multi_event_multi_result_command.rb (100%) rename spec/fixtures/{command => commands}/return_multi_result_command.rb (100%) rename spec/fixtures/{command => commands}/return_single_result_command.rb (100%) rename spec/fixtures/{command => commands}/success_command.rb (100%) diff --git a/spec/fixtures/command/args_command.rb b/spec/fixtures/command/args_command.rb deleted file mode 100644 index 1cfbf7f..0000000 --- a/spec/fixtures/command/args_command.rb +++ /dev/null @@ -1,3 +0,0 @@ -class ArgsCommand < Rectify::Command - def initialize(_, _, _); end # rubocop:disable Lint/MissingSuper, Style/RedundantInitialize -end diff --git a/spec/fixtures/commands/args_command.rb b/spec/fixtures/commands/args_command.rb new file mode 100644 index 0000000..aa0cc4f --- /dev/null +++ b/spec/fixtures/commands/args_command.rb @@ -0,0 +1,15 @@ +class ArgsCommand < Rectify::Command + def initialize(a, b, c) # rubocop:disable Lint/MissingSuper, Naming/MethodParameterName + @a = a + @b = b + @c = c + end + + def call + [a, b, c].join(" ") + end + + private + + attr_reader :a, :b, :c +end diff --git a/spec/fixtures/command/error_command.rb b/spec/fixtures/commands/error_command.rb similarity index 100% rename from spec/fixtures/command/error_command.rb rename to spec/fixtures/commands/error_command.rb diff --git a/spec/fixtures/commands/named_args_command.rb b/spec/fixtures/commands/named_args_command.rb new file mode 100644 index 0000000..90bdf69 --- /dev/null +++ b/spec/fixtures/commands/named_args_command.rb @@ -0,0 +1,40 @@ +class NamedArgsCommand < Rectify::Command + def initialize(first_name, last_name, height:, location:, hobbies:) # rubocop:disable Lint/MissingSuper + @first_name = first_name + @last_name = last_name + @height = height + @location = location + @hobbies = hobbies + end + + def call + broadcast(:ok, message) + end + + def message + "#{full_name} is from #{location} and is #{height_in_inches} inches tall, and they enjoy #{hobbies_list}." + end + + private + + attr_reader :first_name, :last_name, :height, :location, :hobbies + + def full_name + [first_name, last_name].join(" ") + end + + def height_in_inches + height * 0.393 + end + + def hobbies_list + hobbies_array = [hobbies].flatten + + if hobbies_array.length > 1 + last_hobby = "and #{hobbies_array.pop}" + hobbies_array.push(last_hobby) + end + + hobbies_array.join(", ") + end +end diff --git a/spec/fixtures/command/no_args_command.rb b/spec/fixtures/commands/no_args_command.rb similarity index 100% rename from spec/fixtures/command/no_args_command.rb rename to spec/fixtures/commands/no_args_command.rb diff --git a/spec/fixtures/command/return_multi_event_multi_result_command.rb b/spec/fixtures/commands/return_multi_event_multi_result_command.rb similarity index 100% rename from spec/fixtures/command/return_multi_event_multi_result_command.rb rename to spec/fixtures/commands/return_multi_event_multi_result_command.rb diff --git a/spec/fixtures/command/return_multi_result_command.rb b/spec/fixtures/commands/return_multi_result_command.rb similarity index 100% rename from spec/fixtures/command/return_multi_result_command.rb rename to spec/fixtures/commands/return_multi_result_command.rb diff --git a/spec/fixtures/command/return_single_result_command.rb b/spec/fixtures/commands/return_single_result_command.rb similarity index 100% rename from spec/fixtures/command/return_single_result_command.rb rename to spec/fixtures/commands/return_single_result_command.rb diff --git a/spec/fixtures/command/success_command.rb b/spec/fixtures/commands/success_command.rb similarity index 100% rename from spec/fixtures/command/success_command.rb rename to spec/fixtures/commands/success_command.rb diff --git a/spec/fixtures/queries/users_over_using_sql.rb b/spec/fixtures/queries/users_over_using_sql.rb index 2010003..30315b7 100644 --- a/spec/fixtures/queries/users_over_using_sql.rb +++ b/spec/fixtures/queries/users_over_using_sql.rb @@ -12,7 +12,7 @@ def model end def sql - <<-SQL.strip_heredoc + <<~SQL.strip_heredoc SELECT * FROM users WHERE age > :age From 397c65ac84015f2fe3f101dcd381b5269921fc09 Mon Sep 17 00:00:00 2001 From: Jonic Linley Date: Tue, 15 Aug 2023 15:31:41 +0100 Subject: [PATCH 7/8] Update Guard rules to run relevant specs when updating fixtures --- Guardfile | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Guardfile b/Guardfile index a9a82c1..06d7295 100644 --- a/Guardfile +++ b/Guardfile @@ -13,6 +13,18 @@ guard(:rspec, cmd: "bin/rspec") do # Ruby files ruby = dsl.ruby dsl.watch_spec_files_for(ruby.lib_files) + + fixtures = [ + { dir: "commands", spec: "command" }, + { dir: "controllers", spec: "controller_helpers" }, + { dir: "forms", spec: "form" }, + { dir: "presenters", spec: "presenter" }, + { dir: "queries", spec: "query" } + ] + + fixtures.each do |dir:, spec:| + watch(%r{^spec/fixtures/#{dir}/.+\.rb$}) { rspec.spec.call("lib/rectify/#{spec}") } + end end guard(:rubocop, all_on_start: false) do From 96841e8d4095f9c2513d94dafb65c359c270bef3 Mon Sep 17 00:00:00 2001 From: Jonic Linley Date: Tue, 15 Aug 2023 15:31:56 +0100 Subject: [PATCH 8/8] Add logging of deprecation warnings in test suite --- spec/spec_helper.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 4f33c0a..4ea2ff6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,17 @@ +module WarningHandlers + module Ruby + class Warning < StandardError; end + + def warn(message) + logger = Logger.new("tmp/log/warnings.log") + logger.warn(message) + end + end +end + +Warning.singleton_class.prepend(WarningHandlers::Ruby) +Warning[:deprecated] = true + unless ENV["DISABLE_COVERAGE"] require "simplecov" SimpleCov.start do