From f2f55c005171bc337907eb47b80ef176a008e0d6 Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Wed, 4 Dec 2024 20:56:07 +0000 Subject: [PATCH 01/12] chore: add churn gem --- rubycritic.gemspec | 1 + 1 file changed, 1 insertion(+) diff --git a/rubycritic.gemspec b/rubycritic.gemspec index fe9ca4ba..73a6cd63 100644 --- a/rubycritic.gemspec +++ b/rubycritic.gemspec @@ -30,6 +30,7 @@ Gem::Specification.new do |spec| spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } spec.require_path = 'lib' + spec.add_runtime_dependency 'churn' spec.add_runtime_dependency 'flay', '~> 2.13' spec.add_runtime_dependency 'flog', '~> 4.7' spec.add_runtime_dependency 'launchy', '>= 2.5.2' From 7cac1ebb6dde9cc78ac9c66ade7fbb4962496549 Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Wed, 4 Dec 2024 22:42:03 +0000 Subject: [PATCH 02/12] test: added a learning test for the churn gem's calculator so we can explore its interface. --- .../learning/churn_gem_learning_test.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 test/lib/rubycritic/learning/churn_gem_learning_test.rb diff --git a/test/lib/rubycritic/learning/churn_gem_learning_test.rb b/test/lib/rubycritic/learning/churn_gem_learning_test.rb new file mode 100644 index 00000000..773fdbd0 --- /dev/null +++ b/test/lib/rubycritic/learning/churn_gem_learning_test.rb @@ -0,0 +1,16 @@ +require 'test_helper' +require 'churn' +require 'churn/calculator' +describe "churn gem's Churn" do + it 'computes how many times a file was changes' do + config = { + report: false, # Disable default report output + start_date: '6 years ago', # Optional: Limit analysis to a specific time range + minimum_churn_count: 1 # Minimum number of changes to consider a file + } + + churn_calculator = ::Churn::ChurnCalculator.new(config) + report = churn_calculator.report(false) + assert_equal 146, report[:churn][:changes].length + end +end From 077a05c84862d53fe2ecd0193fda2e1fe94c5946 Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Wed, 4 Dec 2024 22:47:13 +0000 Subject: [PATCH 03/12] chore: does not need to be a runtime dependency. --- rubycritic.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rubycritic.gemspec b/rubycritic.gemspec index 14fb6695..61dd0080 100644 --- a/rubycritic.gemspec +++ b/rubycritic.gemspec @@ -30,7 +30,7 @@ Gem::Specification.new do |spec| spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) } spec.require_path = 'lib' - spec.add_runtime_dependency 'churn' + spec.add_dependency 'churn' spec.add_dependency 'flay', '~> 2.13' spec.add_dependency 'flog', '~> 4.7' spec.add_dependency 'launchy', '>= 2.5.2' From c1e667b53436940545c8739670207f78ce6f66d4 Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Wed, 4 Dec 2024 22:55:19 +0000 Subject: [PATCH 04/12] test: corrected the description and explained which file was changed. --- test/lib/rubycritic/learning/churn_gem_learning_test.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/lib/rubycritic/learning/churn_gem_learning_test.rb b/test/lib/rubycritic/learning/churn_gem_learning_test.rb index 773fdbd0..381bd947 100644 --- a/test/lib/rubycritic/learning/churn_gem_learning_test.rb +++ b/test/lib/rubycritic/learning/churn_gem_learning_test.rb @@ -2,7 +2,7 @@ require 'churn' require 'churn/calculator' describe "churn gem's Churn" do - it 'computes how many times a file was changes' do + it 'computes how many times a file was changed' do config = { report: false, # Disable default report output start_date: '6 years ago', # Optional: Limit analysis to a specific time range @@ -11,6 +11,7 @@ churn_calculator = ::Churn::ChurnCalculator.new(config) report = churn_calculator.report(false) - assert_equal 146, report[:churn][:changes].length + # rubycritic gemspec was changed 148 times. + assert_equal 148, report[:churn][:changes].length end end From 876b55d24f5b41815736626a80453752fa26e95d Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Sun, 8 Dec 2024 16:57:04 +0000 Subject: [PATCH 05/12] fix: forgot some set up. --- test/lib/rubycritic/learning/churn_gem_learning_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/rubycritic/learning/churn_gem_learning_test.rb b/test/lib/rubycritic/learning/churn_gem_learning_test.rb index 381bd947..ff52cc02 100644 --- a/test/lib/rubycritic/learning/churn_gem_learning_test.rb +++ b/test/lib/rubycritic/learning/churn_gem_learning_test.rb @@ -8,7 +8,7 @@ start_date: '6 years ago', # Optional: Limit analysis to a specific time range minimum_churn_count: 1 # Minimum number of changes to consider a file } - + Churn::GitAnalyzer.stubs(:supported?).returns(true) churn_calculator = ::Churn::ChurnCalculator.new(config) report = churn_calculator.report(false) # rubycritic gemspec was changed 148 times. From 3c3735dfebe22bcdffab91572f66d8fcc7c1a2e1 Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Sun, 8 Dec 2024 17:12:08 +0000 Subject: [PATCH 06/12] test: corrected the test as changes contains a list of files and the number of times they were changed. --- test/lib/rubycritic/learning/churn_gem_learning_test.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/lib/rubycritic/learning/churn_gem_learning_test.rb b/test/lib/rubycritic/learning/churn_gem_learning_test.rb index ff52cc02..72250098 100644 --- a/test/lib/rubycritic/learning/churn_gem_learning_test.rb +++ b/test/lib/rubycritic/learning/churn_gem_learning_test.rb @@ -1,6 +1,7 @@ require 'test_helper' require 'churn' require 'churn/calculator' +require 'byebug' describe "churn gem's Churn" do it 'computes how many times a file was changed' do config = { @@ -11,7 +12,9 @@ Churn::GitAnalyzer.stubs(:supported?).returns(true) churn_calculator = ::Churn::ChurnCalculator.new(config) report = churn_calculator.report(false) - # rubycritic gemspec was changed 148 times. - assert_equal 148, report[:churn][:changes].length + + changes = report[:churn][:changes].first + assert_equal 'CHANGELOG.md', changes[:file_path] + assert_equal 99, changes[:times_changed] end end From e719791e6d1d7be48c3a46ee0af2ec7e3c8b8e81 Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Sun, 8 Dec 2024 19:11:24 +0000 Subject: [PATCH 07/12] test: made the assertion more stable. --- test/lib/rubycritic/learning/churn_gem_learning_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/lib/rubycritic/learning/churn_gem_learning_test.rb b/test/lib/rubycritic/learning/churn_gem_learning_test.rb index 72250098..f8e1b980 100644 --- a/test/lib/rubycritic/learning/churn_gem_learning_test.rb +++ b/test/lib/rubycritic/learning/churn_gem_learning_test.rb @@ -14,7 +14,7 @@ report = churn_calculator.report(false) changes = report[:churn][:changes].first - assert_equal 'CHANGELOG.md', changes[:file_path] - assert_equal 99, changes[:times_changed] + assert changes.has_key?(:file_path) + assert changes.has_key?(:times_changed) end end From 11397c211d80466e8c2656b7c69933d90373cd91 Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Sun, 8 Dec 2024 21:20:02 +0000 Subject: [PATCH 08/12] test: made assertion stronger. --- test/lib/rubycritic/learning/churn_gem_learning_test.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/lib/rubycritic/learning/churn_gem_learning_test.rb b/test/lib/rubycritic/learning/churn_gem_learning_test.rb index f8e1b980..937f9935 100644 --- a/test/lib/rubycritic/learning/churn_gem_learning_test.rb +++ b/test/lib/rubycritic/learning/churn_gem_learning_test.rb @@ -14,7 +14,8 @@ report = churn_calculator.report(false) changes = report[:churn][:changes].first - assert changes.has_key?(:file_path) - assert changes.has_key?(:times_changed) + + assert_equal 'CHANGELOG.md', changes[:file_path] + assert changes[:times_changed].positive? end end From ff89dd2d28d3a99487b8575a991c62b2246cdb00 Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Sun, 8 Dec 2024 21:23:57 +0000 Subject: [PATCH 09/12] style: corrected some style errors identified by rubocop --- test/lib/rubycritic/learning/churn_gem_learning_test.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/lib/rubycritic/learning/churn_gem_learning_test.rb b/test/lib/rubycritic/learning/churn_gem_learning_test.rb index 937f9935..3c8ed574 100644 --- a/test/lib/rubycritic/learning/churn_gem_learning_test.rb +++ b/test/lib/rubycritic/learning/churn_gem_learning_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' require 'churn' require 'churn/calculator' @@ -10,12 +12,12 @@ minimum_churn_count: 1 # Minimum number of changes to consider a file } Churn::GitAnalyzer.stubs(:supported?).returns(true) - churn_calculator = ::Churn::ChurnCalculator.new(config) + churn_calculator = Churn::ChurnCalculator.new(config) report = churn_calculator.report(false) changes = report[:churn][:changes].first assert_equal 'CHANGELOG.md', changes[:file_path] - assert changes[:times_changed].positive? + assert_predicate changes[:times_changed], :positive? end end From 1ab8581bad8dbe4e5e7b7dda180a8f57fc2d0069 Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Sun, 8 Dec 2024 21:51:49 +0000 Subject: [PATCH 10/12] fix: added some more set up that I missed :facepalm:. --- test/lib/rubycritic/learning/churn_gem_learning_test.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/lib/rubycritic/learning/churn_gem_learning_test.rb b/test/lib/rubycritic/learning/churn_gem_learning_test.rb index 3c8ed574..3cce9d6e 100644 --- a/test/lib/rubycritic/learning/churn_gem_learning_test.rb +++ b/test/lib/rubycritic/learning/churn_gem_learning_test.rb @@ -13,11 +13,14 @@ } Churn::GitAnalyzer.stubs(:supported?).returns(true) churn_calculator = Churn::ChurnCalculator.new(config) + churn_calculator.stubs(:parse_log_for_changes).returns([['file.rb', 4], ['less.rb', 1]]) + churn_calculator.stubs(:parse_log_for_revision_changes).returns(['revision']) + report = churn_calculator.report(false) changes = report[:churn][:changes].first - assert_equal 'CHANGELOG.md', changes[:file_path] + assert_equal 'file.rb', changes[:file_path] assert_predicate changes[:times_changed], :positive? end end From f714894627b4ddef6e4bd2b6546f9f0895316625 Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Sun, 8 Dec 2024 22:28:28 +0000 Subject: [PATCH 11/12] refactor: removed some obsolete code comments. --- test/lib/rubycritic/learning/churn_gem_learning_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/lib/rubycritic/learning/churn_gem_learning_test.rb b/test/lib/rubycritic/learning/churn_gem_learning_test.rb index 3cce9d6e..0dda50ed 100644 --- a/test/lib/rubycritic/learning/churn_gem_learning_test.rb +++ b/test/lib/rubycritic/learning/churn_gem_learning_test.rb @@ -7,9 +7,9 @@ describe "churn gem's Churn" do it 'computes how many times a file was changed' do config = { - report: false, # Disable default report output - start_date: '6 years ago', # Optional: Limit analysis to a specific time range - minimum_churn_count: 1 # Minimum number of changes to consider a file + report: false, + start_date: '6 years ago', + minimum_churn_count: 1 } Churn::GitAnalyzer.stubs(:supported?).returns(true) churn_calculator = Churn::ChurnCalculator.new(config) From d877a8fcf69a548bd0c30889b7d2bb356f81d847 Mon Sep 17 00:00:00 2001 From: Hemal Varambhia Date: Sun, 8 Dec 2024 22:48:44 +0000 Subject: [PATCH 12/12] test: clarified the content of a variable. --- test/lib/rubycritic/learning/churn_gem_learning_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/lib/rubycritic/learning/churn_gem_learning_test.rb b/test/lib/rubycritic/learning/churn_gem_learning_test.rb index 0dda50ed..3b4c441f 100644 --- a/test/lib/rubycritic/learning/churn_gem_learning_test.rb +++ b/test/lib/rubycritic/learning/churn_gem_learning_test.rb @@ -14,7 +14,7 @@ Churn::GitAnalyzer.stubs(:supported?).returns(true) churn_calculator = Churn::ChurnCalculator.new(config) churn_calculator.stubs(:parse_log_for_changes).returns([['file.rb', 4], ['less.rb', 1]]) - churn_calculator.stubs(:parse_log_for_revision_changes).returns(['revision']) + churn_calculator.stubs(:parse_log_for_revision_changes).returns(['revision-git-sha']) report = churn_calculator.report(false)