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

Issue 498: Integrate the Churn Gem and Write a Learning Test to Understand Parts of the Interface RubyCritic Cares About #499

Open
wants to merge 13 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
1 change: 1 addition & 0 deletions rubycritic.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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_dependency 'churn'
spec.add_dependency 'flay', '~> 2.13'
spec.add_dependency 'flog', '~> 4.7'
spec.add_dependency 'launchy', '>= 2.5.2'
Expand Down
26 changes: 26 additions & 0 deletions test/lib/rubycritic/learning/churn_gem_learning_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

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 = {
report: false,
start_date: '6 years ago',
minimum_churn_count: 1
}
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-git-sha'])

report = churn_calculator.report(false)

changes = report[:churn][:changes].first

assert_equal 'file.rb', changes[:file_path]
assert_predicate changes[:times_changed], :positive?
end
end