From 111b43bc0a513133303523492b40bce8f4289595 Mon Sep 17 00:00:00 2001 From: Faisal N Jawdat Date: Sun, 1 Jun 2025 21:05:40 +0100 Subject: [PATCH 1/3] Apply or suppress changes suggested by more modern rubocop. --- CHANGELOG.md | 1 + features/support/env.rb | 1 + lib/rubycritic/analysers/attributes.rb | 1 + lib/rubycritic/analysers/churn.rb | 1 + lib/rubycritic/analysers/complexity.rb | 1 + lib/rubycritic/analysers/smells/flay.rb | 1 + lib/rubycritic/analysers/smells/flog.rb | 1 + lib/rubycritic/analysers/smells/reek.rb | 1 + lib/rubycritic/commands/status_reporter.rb | 4 ++-- lib/rubycritic/rake_task.rb | 2 +- lib/rubycritic/source_control_systems/git.rb | 4 ++-- lib/rubycritic/source_control_systems/perforce.rb | 2 ++ test/fakefs_helper.rb | 3 +++ .../rubycritic/analysers/helpers/methods_counter_test.rb | 3 +++ .../rubycritic/analysers/helpers/modules_locator_test.rb | 3 +++ test/lib/rubycritic/analysers/smells/flay_test.rb | 3 +++ test/lib/rubycritic/analysers/smells/flog_test.rb | 2 ++ test/lib/rubycritic/analysers/smells/reek_test.rb | 3 +++ test/lib/rubycritic/browser_test.rb | 1 + test/lib/rubycritic/commands/compare_test.rb | 2 ++ test/lib/rubycritic/commands/status_reporter_test.rb | 6 ++++++ test/lib/rubycritic/configuration_test.rb | 2 ++ test/lib/rubycritic/core/analysed_module_test.rb | 5 +++++ .../rubycritic/core/analysed_modules_collection_test.rb | 2 ++ test/lib/rubycritic/core/location_test.rb | 2 ++ test/lib/rubycritic/core/smell_test.rb | 5 +++++ test/lib/rubycritic/core/smells_array_test.rb | 3 +++ test/lib/rubycritic/generators/turbulence_test.rb | 1 + test/lib/rubycritic/smells_status_setter_test.rb | 2 ++ test/lib/rubycritic/source_control_systems/base_test.rb | 2 ++ .../rubycritic/source_control_systems/perforce_test.rb | 9 +++++++++ test/lib/rubycritic/source_locator_test.rb | 9 +++++++++ 32 files changed, 83 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bacaffc..77bb45d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # main [(unreleased)](https://github.com/whitesmith/rubycritic/compare/v4.9.2...main) +* [CHANGE] Add changes or suppress warnings for issues found by newer rubocop (by [@faisal][]) * [CHANGE] Update CI checkout action to v4 (by [@faisal][]) # v4.9.2 / 2025-04-08 [(commits)](https://github.com/whitesmith/rubycritic/compare/v4.9.1...v4.9.2) diff --git a/features/support/env.rb b/features/support/env.rb index 70eafd31..c822f943 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -11,6 +11,7 @@ # class RubyCriticWorld extend Minitest::Assertions + attr_accessor :assertions def initialize diff --git a/lib/rubycritic/analysers/attributes.rb b/lib/rubycritic/analysers/attributes.rb index 6ef9459e..f8fddbda 100644 --- a/lib/rubycritic/analysers/attributes.rb +++ b/lib/rubycritic/analysers/attributes.rb @@ -8,6 +8,7 @@ module RubyCritic module Analyser class Attributes include Colorize + def initialize(analysed_modules) @analysed_modules = analysed_modules end diff --git a/lib/rubycritic/analysers/churn.rb b/lib/rubycritic/analysers/churn.rb index d09fce85..b48d0549 100644 --- a/lib/rubycritic/analysers/churn.rb +++ b/lib/rubycritic/analysers/churn.rb @@ -6,6 +6,7 @@ module RubyCritic module Analyser class Churn include Colorize + attr_writer :source_control_system def initialize(analysed_modules) diff --git a/lib/rubycritic/analysers/complexity.rb b/lib/rubycritic/analysers/complexity.rb index 69800a13..fd46241d 100644 --- a/lib/rubycritic/analysers/complexity.rb +++ b/lib/rubycritic/analysers/complexity.rb @@ -7,6 +7,7 @@ module RubyCritic module Analyser class Complexity include Colorize + def initialize(analysed_modules) @flog = Flog.new @analysed_modules = analysed_modules diff --git a/lib/rubycritic/analysers/smells/flay.rb b/lib/rubycritic/analysers/smells/flay.rb index 743c2906..c1ca7148 100644 --- a/lib/rubycritic/analysers/smells/flay.rb +++ b/lib/rubycritic/analysers/smells/flay.rb @@ -8,6 +8,7 @@ module RubyCritic module Analyser class FlaySmells include Colorize + def initialize(analysed_modules) @analysed_modules = paths_to_analysed_modules(analysed_modules) @flay = Flay.new(@analysed_modules.keys) diff --git a/lib/rubycritic/analysers/smells/flog.rb b/lib/rubycritic/analysers/smells/flog.rb index c7cbd687..d779d3eb 100644 --- a/lib/rubycritic/analysers/smells/flog.rb +++ b/lib/rubycritic/analysers/smells/flog.rb @@ -8,6 +8,7 @@ module RubyCritic module Analyser class FlogSmells include Colorize + HIGH_COMPLEXITY_SCORE_THRESHOLD = 25 VERY_HIGH_COMPLEXITY_SCORE_THRESHOLD = 60 diff --git a/lib/rubycritic/analysers/smells/reek.rb b/lib/rubycritic/analysers/smells/reek.rb index f374dc47..5aea5afb 100644 --- a/lib/rubycritic/analysers/smells/reek.rb +++ b/lib/rubycritic/analysers/smells/reek.rb @@ -8,6 +8,7 @@ module RubyCritic module Analyser class ReekSmells include Colorize + def initialize(analysed_modules) @analysed_modules = analysed_modules end diff --git a/lib/rubycritic/commands/status_reporter.rb b/lib/rubycritic/commands/status_reporter.rb index 8977d231..35fc4cda 100644 --- a/lib/rubycritic/commands/status_reporter.rb +++ b/lib/rubycritic/commands/status_reporter.rb @@ -26,10 +26,10 @@ def update_status end def current_status - satisfy_minimum_score_rule ? SUCCESS : SCORE_BELOW_MINIMUM + satisfy_minimum_score_rule? ? SUCCESS : SCORE_BELOW_MINIMUM end - def satisfy_minimum_score_rule + def satisfy_minimum_score_rule? score >= @options[:minimum_score].to_f end diff --git a/lib/rubycritic/rake_task.rb b/lib/rubycritic/rake_task.rb index dac13602..5fc8c495 100644 --- a/lib/rubycritic/rake_task.rb +++ b/lib/rubycritic/rake_task.rb @@ -71,7 +71,7 @@ def run_task def print_starting_up_output puts "\n\n!!! Running `#{name}` rake command\n" - puts "!!! Inspecting #{paths} #{options.empty? ? '' : "with options #{options}"}\n\n" + puts "!!! Inspecting #{paths} #{"with options #{options}" unless options.empty?}\n\n" end def options_as_arguments diff --git a/lib/rubycritic/source_control_systems/git.rb b/lib/rubycritic/source_control_systems/git.rb index bed6a54a..428cd151 100644 --- a/lib/rubycritic/source_control_systems/git.rb +++ b/lib/rubycritic/source_control_systems/git.rb @@ -50,7 +50,7 @@ def head_reference end def travel_to_head - stash_successful = stash_changes + stash_successful = stash_changes? yield ensure travel_to_original_state if stash_successful @@ -88,7 +88,7 @@ def self.current_branch private - def stash_changes + def stash_changes? stashes_count_before = stashes_count git('stash') stashes_count_after = stashes_count diff --git a/lib/rubycritic/source_control_systems/perforce.rb b/lib/rubycritic/source_control_systems/perforce.rb index bffe94e4..759e528d 100644 --- a/lib/rubycritic/source_control_systems/perforce.rb +++ b/lib/rubycritic/source_control_systems/perforce.rb @@ -52,9 +52,11 @@ def date_of_last_commit(path) Time.strptime(perforce_files[Perforce.key_file(path)].last_commit, '%s').strftime('%Y-%m-%d %H:%M:%S %z') end + # rubocop:disable Style/CollectionQuerying def revision? !perforce_files.values.count(&:opened?).zero? end + # rubocop:enable Style/CollectionQuerying def head_reference perforce_files.values.map(&:head).max_by(&:to_i) diff --git a/test/fakefs_helper.rb b/test/fakefs_helper.rb index 1e6fbc77..a63f7abc 100644 --- a/test/fakefs_helper.rb +++ b/test/fakefs_helper.rb @@ -8,9 +8,12 @@ class File < StringIO # $VERBOSE = nil to suppress warnings when we override flock. original_verbose = $VERBOSE $VERBOSE = nil + + # rubocop:disable Naming/PredicateMethod def flock(*) true end + # rubocop:enable Naming/PredicateMethod $VERBOSE = original_verbose end end diff --git a/test/lib/rubycritic/analysers/helpers/methods_counter_test.rb b/test/lib/rubycritic/analysers/helpers/methods_counter_test.rb index c2faba96..ee889f05 100644 --- a/test/lib/rubycritic/analysers/helpers/methods_counter_test.rb +++ b/test/lib/rubycritic/analysers/helpers/methods_counter_test.rb @@ -8,6 +8,7 @@ context 'when a file contains Ruby code' do it 'calculates the number of methods' do analysed_module = AnalysedModuleDouble.new(path: 'test/samples/methods_count.rb') + _(RubyCritic::MethodsCounter.new(analysed_module).count).must_equal 2 end end @@ -15,6 +16,7 @@ context 'when a file is empty' do it 'returns 0 as the number of methods' do analysed_module = AnalysedModuleDouble.new(path: 'test/samples/empty.rb') + _(RubyCritic::MethodsCounter.new(analysed_module).count).must_equal 0 end end @@ -22,6 +24,7 @@ context 'when a file has no method' do it 'does not blow up and returns 0 as the number of methods' do analysed_module = AnalysedModuleDouble.new(path: 'test/samples/no_methods.rb') + capture_output_streams do _(RubyCritic::MethodsCounter.new(analysed_module).count).must_equal 0 end diff --git a/test/lib/rubycritic/analysers/helpers/modules_locator_test.rb b/test/lib/rubycritic/analysers/helpers/modules_locator_test.rb index 98986bc6..c2278fc9 100644 --- a/test/lib/rubycritic/analysers/helpers/modules_locator_test.rb +++ b/test/lib/rubycritic/analysers/helpers/modules_locator_test.rb @@ -13,6 +13,7 @@ pathname: Pathname.new('test/samples/module_names.rb'), methods_count: 1 ) + _(RubyCritic::ModulesLocator.new(analysed_module).names) .must_equal ['Foo', 'Foo::Bar', 'Foo::Baz', 'Foo::Qux', 'Foo::Quux::Corge'] end @@ -24,6 +25,7 @@ pathname: Pathname.new('test/samples/empty.rb'), methods_count: 1 ) + _(RubyCritic::ModulesLocator.new(analysed_module).names).must_equal ['Empty'] end end @@ -34,6 +36,7 @@ pathname: Pathname.new('test/samples/no_methods.rb'), methods_count: 0 ) + capture_output_streams do _(RubyCritic::ModulesLocator.new(analysed_module).names).must_equal ['Foo::NoMethods'] end diff --git a/test/lib/rubycritic/analysers/smells/flay_test.rb b/test/lib/rubycritic/analysers/smells/flay_test.rb index acf082e8..8578c6d0 100644 --- a/test/lib/rubycritic/analysers/smells/flay_test.rb +++ b/test/lib/rubycritic/analysers/smells/flay_test.rb @@ -21,16 +21,19 @@ it 'creates smells with messages' do smell = @analysed_modules.first.smells.first + _(smell.message).must_be_instance_of String end it 'creates smells with scores' do smell = @analysed_modules.first.smells.first + _(smell.score).must_be_kind_of Numeric end it 'creates smells with more than one location' do smell = @analysed_modules.first.smells.first + _(smell.multiple_locations?).must_equal true end diff --git a/test/lib/rubycritic/analysers/smells/flog_test.rb b/test/lib/rubycritic/analysers/smells/flog_test.rb index 8a1d29e6..5144ad76 100644 --- a/test/lib/rubycritic/analysers/smells/flog_test.rb +++ b/test/lib/rubycritic/analysers/smells/flog_test.rb @@ -17,11 +17,13 @@ it 'creates smells with messages' do smell = @analysed_module.smells.first + _(smell.message).must_be_instance_of String end it 'creates smells with scores' do smell = @analysed_module.smells.first + _(smell.score).must_be :>, 0 end end diff --git a/test/lib/rubycritic/analysers/smells/reek_test.rb b/test/lib/rubycritic/analysers/smells/reek_test.rb index 9a994892..eff29b0f 100644 --- a/test/lib/rubycritic/analysers/smells/reek_test.rb +++ b/test/lib/rubycritic/analysers/smells/reek_test.rb @@ -18,14 +18,17 @@ it 'respects the .reek file' do messages = @analysed_module.smells.map(&:message) + _(messages).wont_include "has the parameter name 'a'" end it 'creates smells with messages' do first_smell = @analysed_module.smells.first + _(first_smell.message).must_equal "has boolean parameter 'reek'" last_smell = @analysed_module.smells.last + _(last_smell.message).must_equal 'has no descriptive comment' end end diff --git a/test/lib/rubycritic/browser_test.rb b/test/lib/rubycritic/browser_test.rb index 707c7f9f..0b4490fd 100644 --- a/test/lib/rubycritic/browser_test.rb +++ b/test/lib/rubycritic/browser_test.rb @@ -12,6 +12,7 @@ describe '#open' do it 'should be open report with launch browser' do Launchy.stubs(:open).returns(true) + _(@browser.open).must_equal true end end diff --git a/test/lib/rubycritic/commands/compare_test.rb b/test/lib/rubycritic/commands/compare_test.rb index 9b6c3d70..91ba0aff 100644 --- a/test/lib/rubycritic/commands/compare_test.rb +++ b/test/lib/rubycritic/commands/compare_test.rb @@ -69,6 +69,7 @@ def abort(str); end comparison.expects(:abort).once status_reporter = comparison.execute + _(status_reporter.score).must_equal RubyCritic::Config.feature_branch_score _(status_reporter.score).wont_equal RubyCritic::Config.base_branch_score _(status_reporter.status_message).must_equal "Score: #{RubyCritic::Config.feature_branch_score}" @@ -87,6 +88,7 @@ def abort(str); end end RubyCritic::SourceControlSystem::Git.stub(:switch_branch, copy_proc) do status_reporter = RubyCritic::Command::Compare.new(options).execute + _(status_reporter.score).must_equal RubyCritic::Config.feature_branch_score _(status_reporter.score).must_equal RubyCritic::Config.base_branch_score _(status_reporter.status_message).must_equal "Score: #{RubyCritic::Config.feature_branch_score}" diff --git a/test/lib/rubycritic/commands/status_reporter_test.rb b/test/lib/rubycritic/commands/status_reporter_test.rb index 5a0f745a..a06ce7f3 100644 --- a/test/lib/rubycritic/commands/status_reporter_test.rb +++ b/test/lib/rubycritic/commands/status_reporter_test.rb @@ -22,12 +22,14 @@ it 'accept a score' do @reporter.score = 50.0 + _(@reporter.status).must_equal success_status _(@reporter.status_message).must_equal 'Score: 50.0' end it 'should format the score' do @reporter.score = 98.95258620689656 + _(@reporter.status).must_equal success_status _(@reporter.status_message).must_equal 'Score: 98.95' end @@ -49,12 +51,14 @@ let(:score) { 98.0 } it 'should return the correct status' do @reporter.score = score + _(@reporter.status).must_equal score_below_minimum _(@reporter.status_message).must_equal 'Score (98.0) is below the minimum 99.0' end it 'should format the score' do @reporter.score = 98.95258620689656 + _(@reporter.status).must_equal score_below_minimum _(@reporter.status_message).must_equal 'Score (98.95) is below the minimum 99.0' end @@ -64,6 +68,7 @@ let(:score) { 99.0 } it 'should return the correct status' do @reporter.score = score + _(@reporter.status).must_equal success_status _(@reporter.status_message).must_equal 'Score: 99.0' end @@ -73,6 +78,7 @@ let(:score) { 100.0 } it 'should return the correct status' do @reporter.score = score + _(@reporter.status).must_equal success_status _(@reporter.status_message).must_equal 'Score: 100.0' end diff --git a/test/lib/rubycritic/configuration_test.rb b/test/lib/rubycritic/configuration_test.rb index 224c5670..20d376fb 100644 --- a/test/lib/rubycritic/configuration_test.rb +++ b/test/lib/rubycritic/configuration_test.rb @@ -16,11 +16,13 @@ it 'can be set to a relative path' do RubyCritic::Config.root = 'foo' + _(RubyCritic::Config.root).must_equal File.expand_path('foo') end it 'can be set to an absolute path' do RubyCritic::Config.root = '/foo' + _(RubyCritic::Config.root).must_equal '/foo' end diff --git a/test/lib/rubycritic/core/analysed_module_test.rb b/test/lib/rubycritic/core/analysed_module_test.rb index 775c137c..a457fdc0 100644 --- a/test/lib/rubycritic/core/analysed_module_test.rb +++ b/test/lib/rubycritic/core/analysed_module_test.rb @@ -50,6 +50,7 @@ it 'returns the remediation cost of fixing the analysed_module' do smells = [SmellDouble.new(cost: 1), SmellDouble.new(cost: 2)] analysed_module = RubyCritic::AnalysedModule.new(smells: smells, complexity: 0) + _(analysed_module.cost).must_equal 3 end end @@ -58,6 +59,7 @@ context 'when the file has no methods' do it 'returns a placeholder' do analysed_module = RubyCritic::AnalysedModule.new(complexity: 0, methods_count: 0) + _(analysed_module.complexity_per_method).must_equal 'N/A' end end @@ -65,6 +67,7 @@ context 'when the file has at least one method' do it 'returns the average complexity per method' do analysed_module = RubyCritic::AnalysedModule.new(complexity: 10, methods_count: 2) + _(analysed_module.complexity_per_method).must_equal 5 end end @@ -73,6 +76,7 @@ describe '#smells?' do it 'returns true if the analysed_module has at least one smell' do analysed_module = RubyCritic::AnalysedModule.new(smells: [SmellDouble.new]) + _(analysed_module.smells?).must_equal true end end @@ -82,6 +86,7 @@ location = RubyCritic::Location.new('./foo', '42') smells = [RubyCritic::Smell.new(locations: [location])] analysed_module = RubyCritic::AnalysedModule.new(smells: smells) + _(analysed_module.smells_at_location(location)).must_equal smells end end diff --git a/test/lib/rubycritic/core/analysed_modules_collection_test.rb b/test/lib/rubycritic/core/analysed_modules_collection_test.rb index 77b6e5a9..651d9fd5 100644 --- a/test/lib/rubycritic/core/analysed_modules_collection_test.rb +++ b/test/lib/rubycritic/core/analysed_modules_collection_test.rb @@ -54,8 +54,10 @@ it 'registers one AnalysedModule element per existent file' do analysed_modules_collection = RubyCritic::AnalysedModulesCollection.new(paths, analysed_modules) + _(analysed_modules_collection.count).must_equal 1 analysed_module = analysed_modules_collection.first + _(analysed_module.name).must_equal 'Name' _(analysed_module.churn).must_equal 2 _(analysed_module.complexity).must_equal 2 diff --git a/test/lib/rubycritic/core/location_test.rb b/test/lib/rubycritic/core/location_test.rb index 31e49548..ad4806f5 100644 --- a/test/lib/rubycritic/core/location_test.rb +++ b/test/lib/rubycritic/core/location_test.rb @@ -27,6 +27,7 @@ it 'is comparable' do location1 = RubyCritic::Location.new('./foo', 42) location2 = RubyCritic::Location.new('./foo', 42) + _(location1).must_equal location2 end @@ -34,6 +35,7 @@ location1 = RubyCritic::Location.new('./foo', 42) location2 = RubyCritic::Location.new('./bar', 23) location3 = RubyCritic::Location.new('./bar', 16) + _([location1, location2, location3].sort).must_equal [location3, location2, location1] end end diff --git a/test/lib/rubycritic/core/smell_test.rb b/test/lib/rubycritic/core/smell_test.rb index 32db7cd2..ec0b190c 100644 --- a/test/lib/rubycritic/core/smell_test.rb +++ b/test/lib/rubycritic/core/smell_test.rb @@ -45,6 +45,7 @@ it 'returns true if the smell has a location that matches the location passed as argument' do location = RubyCritic::Location.new('./foo', '42') smell = RubyCritic::Smell.new(locations: [location]) + _(smell.at_location?(location)).must_equal true end end @@ -54,6 +55,7 @@ location1 = RubyCritic::Location.new('./foo', '42') location2 = RubyCritic::Location.new('./foo', '23') smell = RubyCritic::Smell.new(locations: [location1, location2]) + _(smell.multiple_locations?).must_equal true end end @@ -68,6 +70,7 @@ } smell1 = RubyCritic::Smell.new(attributes) smell2 = RubyCritic::Smell.new(attributes) + _(smell1).must_equal smell2 end end @@ -106,11 +109,13 @@ describe 'default attributes' do it 'has :new for status' do smell = RubyCritic::Smell.new + _(smell.status).must_equal(:new) end it 'is has an empty array for locations' do smell = RubyCritic::Smell.new + _(smell.locations).must_equal([]) end end diff --git a/test/lib/rubycritic/core/smells_array_test.rb b/test/lib/rubycritic/core/smells_array_test.rb index ec9aa544..ff1619a2 100644 --- a/test/lib/rubycritic/core/smells_array_test.rb +++ b/test/lib/rubycritic/core/smells_array_test.rb @@ -11,6 +11,7 @@ smell1 = RubyCritic::Smell.new(locations: [location1]) smell2 = RubyCritic::Smell.new(locations: [location2]) smell3 = RubyCritic::Smell.new(locations: [location3]) + _([smell1, smell2, smell3].sort).must_equal [smell3, smell2, smell1] end @@ -18,6 +19,7 @@ smell1 = RubyCritic::Smell.new(context: '#bar') smell2 = RubyCritic::Smell.new(context: '#bar') smell3 = RubyCritic::Smell.new(context: '#foo') + _([smell1, smell3] & [smell2]).must_equal [smell1] end @@ -25,6 +27,7 @@ smell1 = RubyCritic::Smell.new(context: '#bar') smell2 = RubyCritic::Smell.new(context: '#bar') smell3 = RubyCritic::Smell.new(context: '#foo') + _([smell1, smell3] | [smell2]).must_equal [smell1, smell3] end end diff --git a/test/lib/rubycritic/generators/turbulence_test.rb b/test/lib/rubycritic/generators/turbulence_test.rb index 9846bd5b..27a46142 100644 --- a/test/lib/rubycritic/generators/turbulence_test.rb +++ b/test/lib/rubycritic/generators/turbulence_test.rb @@ -9,6 +9,7 @@ files = [AnalysedModuleDouble.new(name: 'Foo', churn: 1, complexity: 2)] turbulence_data = RubyCritic::Turbulence.data(files) instance_parsed_json = JSON.parse(turbulence_data).first + _(instance_parsed_json['name']).must_equal 'Foo' _(instance_parsed_json['x']).must_equal 1 _(instance_parsed_json['y']).must_equal 2 diff --git a/test/lib/rubycritic/smells_status_setter_test.rb b/test/lib/rubycritic/smells_status_setter_test.rb index 2a92fdb2..79f336f1 100644 --- a/test/lib/rubycritic/smells_status_setter_test.rb +++ b/test/lib/rubycritic/smells_status_setter_test.rb @@ -13,11 +13,13 @@ it 'marks old smells' do RubyCritic::SmellsStatusSetter.set(@smells, @smells) + _(@smell.status).must_equal :old end it 'marks new smells' do RubyCritic::SmellsStatusSetter.set([], @smells) + _(@smell.status).must_equal :new end end diff --git a/test/lib/rubycritic/source_control_systems/base_test.rb b/test/lib/rubycritic/source_control_systems/base_test.rb index e7d9c1a4..3f8bd003 100644 --- a/test/lib/rubycritic/source_control_systems/base_test.rb +++ b/test/lib/rubycritic/source_control_systems/base_test.rb @@ -15,6 +15,7 @@ it 'creates an instance of that source control system' do RubyCritic::SourceControlSystem::Git.stubs(:supported?).returns(true) system = RubyCritic::SourceControlSystem::Base.create + _(system).must_be_instance_of RubyCritic::SourceControlSystem::Git end end @@ -23,6 +24,7 @@ it 'creates a source control system double' do capture_output_streams do system = RubyCritic::SourceControlSystem::Base.create + _(system).must_be_instance_of RubyCritic::SourceControlSystem::Double end end diff --git a/test/lib/rubycritic/source_control_systems/perforce_test.rb b/test/lib/rubycritic/source_control_systems/perforce_test.rb index 1c398200..dd7a6b45 100644 --- a/test/lib/rubycritic/source_control_systems/perforce_test.rb +++ b/test/lib/rubycritic/source_control_systems/perforce_test.rb @@ -80,6 +80,7 @@ it 'calls p4 info and parse the result' do RubyCritic::SourceControlSystem::Perforce.stubs(:`).with('p4 info').returns(p4_info) + _(RubyCritic::SourceControlSystem::Perforce.in_client_directory?).must_equal true end end @@ -100,6 +101,7 @@ it 'calls p4 info and parse the result' do RubyCritic::SourceControlSystem::Perforce.stubs(:`).with('p4 info').returns(p4_info) + _(RubyCritic::SourceControlSystem::Perforce.in_client_directory?).must_equal false end end @@ -125,9 +127,11 @@ it 'builds the perforce file cache' do RubyCritic::SourceControlSystem::Perforce.stubs(:`).returns(p4_stats) file_cache = @system.send(:perforce_files) + _(file_cache.size).must_equal 2 first_file = file_cache['/path/to/client/a_ruby_file.rb'] + _(first_file.filename).must_equal '/path/to/client/a_ruby_file.rb' _(first_file.revision).must_equal '16' _(first_file.last_commit).must_equal '1473075551' @@ -135,6 +139,7 @@ _(first_file.opened?).must_equal false second_file = file_cache['/path/to/client/second_ruby_file.rb'] + _(second_file.filename).must_equal '/path/to/client/second_ruby_file.rb' _(second_file.revision).must_equal '12' _(second_file.last_commit).must_equal '1464601668' @@ -146,6 +151,7 @@ it 'retrieves the number revisions of the ruby files' do Dir.stubs(:getwd).returns('/path/to/client') RubyCritic::SourceControlSystem::Perforce.stubs(:`).once.returns(p4_stats) + _(@system.revisions_count('a_ruby_file.rb')).must_equal 16 _(@system.revisions_count('second_ruby_file.rb')).must_equal 12 end @@ -155,6 +161,7 @@ ENV['TZ'] = 'utc' Dir.stubs(:getwd).returns('/path/to/client') RubyCritic::SourceControlSystem::Perforce.stubs(:`).once.returns(p4_stats) + _(@system.date_of_last_commit('a_ruby_file.rb')).must_equal '2016-09-05 11:39:11 +0000' _(@system.date_of_last_commit('second_ruby_file.rb')).must_equal '2016-05-30 09:47:48 +0000' ENV['TZ'] = oldtz @@ -163,12 +170,14 @@ it 'retrieves the information if the ruby file is opened (in the changelist and ready to commit)' do Dir.stubs(:getwd).returns('/path/to/client') RubyCritic::SourceControlSystem::Perforce.stubs(:`).once.returns(p4_stats) + _(@system.revision?).must_equal true end it 'retrieves the head reference of the repository' do Dir.stubs(:getwd).returns('/path/to/client') RubyCritic::SourceControlSystem::Perforce.stubs(:`).once.returns(p4_stats) + _(@system.head_reference).must_equal '2103504' end end diff --git a/test/lib/rubycritic/source_locator_test.rb b/test/lib/rubycritic/source_locator_test.rb index f58a3e34..6eaf3397 100644 --- a/test/lib/rubycritic/source_locator_test.rb +++ b/test/lib/rubycritic/source_locator_test.rb @@ -13,12 +13,14 @@ describe '#paths' do it 'finds a single file' do paths = ['file0.rb'] + _(RubyCritic::SourceLocator.new(paths).paths).must_equal paths end it 'finds all the files inside a given directory' do initial_paths = ['dir1'] final_paths = ['dir1/file1.rb'] + _(RubyCritic::SourceLocator.new(initial_paths).paths).must_equal final_paths end @@ -36,11 +38,13 @@ it 'finds files with extensions it is configured to find' do RubyCritic::Config.stubs(:ruby_extensions).returns(%w[.rb .foo]) paths = ['file0.rb', 'ruby_file_different_extension.foo'] + _(RubyCritic::SourceLocator.new(paths).paths).must_equal paths end it 'finds files which have a ruby shebang' do paths = ['file_with_ruby_shebang'] + _(RubyCritic::SourceLocator.new(paths).paths).must_equal paths end @@ -56,24 +60,28 @@ it 'cleans paths of consecutive slashes and useless dots' do initial_paths = ['.//file0.rb'] final_paths = ['file0.rb'] + _(RubyCritic::SourceLocator.new(initial_paths).paths).must_equal final_paths end it 'ignores paths to non-existent files' do initial_paths = ['non_existent_dir1/non_existent_file1.rb', 'non_existent_file0.rb'] final_paths = [] + _(RubyCritic::SourceLocator.new(initial_paths).paths).must_equal final_paths end it 'ignores paths to files that do not match the Ruby extension' do initial_paths = ['file_with_no_extension', 'file_with_different_extension.py'] final_paths = [] + _(RubyCritic::SourceLocator.new(initial_paths).paths).must_equal final_paths end it 'can deal with nil paths' do paths = nil final_paths = [] + _(RubyCritic::SourceLocator.new(paths).paths).must_equal final_paths end end @@ -82,6 +90,7 @@ it 'finds a single file' do initial_paths = ['file0.rb'] final_pathnames = [Pathname.new('file0.rb')] + _(RubyCritic::SourceLocator.new(initial_paths).pathnames).must_equal final_pathnames end end From 268d3a2cbf82d8b6ccefea97702ea516e33895fc Mon Sep 17 00:00:00 2001 From: Faisal N Jawdat Date: Wed, 9 Apr 2025 11:13:42 +0100 Subject: [PATCH 2/3] Fix feature execution on Ruby 3.5.0dev cucumber-core fails on Ruby 3.5.0dev due to a change in the expected method signature for Cucumber::Core::Test::Location#from_source_location. Work around this by aliasing out the old method and then using a new proxy method to catch the method and send the old style message to the old method. --- CHANGELOG.md | 2 ++ features/support/env.rb | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77bb45d2..04bb6e9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # main [(unreleased)](https://github.com/whitesmith/rubycritic/compare/v4.9.2...main) +* [CHANGE] Bump aruba, byebug, cucumber, fakefs, rake, reek dependencies (by [@faisal][]) +* [BUGFIX] Work around issue preventing feature execution on Ruby 3.5.0dev (by [@faisal][]) * [CHANGE] Add changes or suppress warnings for issues found by newer rubocop (by [@faisal][]) * [CHANGE] Update CI checkout action to v4 (by [@faisal][]) diff --git a/features/support/env.rb b/features/support/env.rb index c822f943..16c7602d 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,5 +1,20 @@ # frozen_string_literal: true +if RUBY_VERSION == '3.5.0' && RUBY_PATCHLEVEL == -1 + module Cucumber + module Core + module Test + module Location + singleton_class.send(:alias_method, :original_from_source_location, :from_source_location) + def self.from_source_location(file, start_line, _start_column = nil, _end_line = nil, _end_column = nil) + original_from_source_location(file, start_line) + end + end + end + end + end +end + require_relative '../../lib/rubycritic' require_relative '../../lib/rubycritic/cli/application' require_relative '../../lib/rubycritic/commands/status_reporter' From 34b55b734ba2e456098f4c6865b25da0799a5f56 Mon Sep 17 00:00:00 2001 From: Faisal N Jawdat Date: Tue, 20 May 2025 18:37:23 +0100 Subject: [PATCH 3/3] Bump aruba, byebug, cucumber, fakefs, rake, reek dependencies Also corrected multiple Minitest/EmptyLineBeforeAssertionMethods issues flagged by rubocop-minitst. --- rubycritic.gemspec | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/rubycritic.gemspec b/rubycritic.gemspec index 23e53a91..666215a9 100644 --- a/rubycritic.gemspec +++ b/rubycritic.gemspec @@ -35,30 +35,30 @@ Gem::Specification.new do |spec| spec.add_dependency 'launchy', '>= 2.5.2' spec.add_dependency 'parser', '>= 3.3.0.5' spec.add_dependency 'rainbow', '~> 3.1.1' - spec.add_dependency 'reek', '~> 6.4.0', '< 7.0' + spec.add_dependency 'reek', '~> 6.5.0', '< 7.0' spec.add_dependency 'rexml' spec.add_dependency 'ruby_parser', '~> 3.21' spec.add_dependency 'simplecov', '>= 0.22.0' spec.add_dependency 'tty-which', '~> 0.5.0' spec.add_dependency 'virtus', '~> 2.0' - spec.add_development_dependency 'aruba', '~> 2.3.0' + spec.add_development_dependency 'aruba', '~> 2.3.1', '>= 2.3.1' spec.add_development_dependency 'bundler', '>= 2.0.0' if RUBY_PLATFORM == 'java' spec.add_development_dependency 'pry-debugger-jruby' else - spec.add_development_dependency 'byebug', '~> 11.0', '>= 10.0' + spec.add_development_dependency 'byebug', '~> 12.0', '>= 10.0' end - spec.add_development_dependency 'cucumber', '~> 9.2.1', '!= 9.0.0' + spec.add_development_dependency 'cucumber', '~> 10.0.0', '!= 9.0.0' spec.add_development_dependency 'diff-lcs', '~> 1.3' - spec.add_development_dependency 'fakefs', '~> 2.6.0' + spec.add_development_dependency 'fakefs', '~> 3.0.0' spec.add_development_dependency 'irb' spec.add_development_dependency 'mdl', '~> 0.13.0', '>= 0.12.0' spec.add_development_dependency 'minitest', '~> 5.25.2', '>= 5.3.0' spec.add_development_dependency 'minitest-around', '~> 0.5.0', '>= 0.4.0' spec.add_development_dependency 'mocha', '~> 2.7.1' spec.add_development_dependency 'ostruct' - spec.add_development_dependency 'rake', '~> 13.2.0', '>= 11.0.0' + spec.add_development_dependency 'rake', '~> 13.3.0', '>= 11.0.0' spec.add_development_dependency 'rdoc' spec.add_development_dependency 'rexml', '>= 3.2.0' spec.add_development_dependency 'rubocop', '>= 1.72.0', '< 2.0'