diff --git a/rubycritic.gemspec b/rubycritic.gemspec index ca118b9b..61dd0080 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_dependency 'churn' spec.add_dependency 'flay', '~> 2.13' spec.add_dependency 'flog', '~> 4.7' spec.add_dependency 'launchy', '>= 2.5.2' 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..3b4c441f --- /dev/null +++ b/test/lib/rubycritic/learning/churn_gem_learning_test.rb @@ -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