From 47ea554fe2485c6faac0041bb6d109e8bfec434d Mon Sep 17 00:00:00 2001 From: Matijs van Zuijlen Date: Fri, 21 Mar 2014 07:20:15 +0100 Subject: [PATCH] Filter non-ruby files from list passed to reek --- lib/pronto/reek.rb | 1 + spec/pronto/reek_spec.rb | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/pronto/reek.rb b/lib/pronto/reek.rb index 5fff6b4..33ac87c 100644 --- a/lib/pronto/reek.rb +++ b/lib/pronto/reek.rb @@ -8,6 +8,7 @@ def run(patches, _) patches_with_additions = patches.select { |patch| patch.additions > 0 } files = patches_with_additions.map { |patch| patch.new_file_full_path.to_s } + files = files.grep /\.rb$/ if files.any? examiner = ::Reek::Examiner.new(files) diff --git a/spec/pronto/reek_spec.rb b/spec/pronto/reek_spec.rb index 77f1c5c..372b12e 100644 --- a/spec/pronto/reek_spec.rb +++ b/spec/pronto/reek_spec.rb @@ -17,6 +17,40 @@ module Pronto let(:patches) { [] } it { should == [] } end + + context 'patches with additions' do + let(:patches) { [ + double("patch with additions", additions: 4, new_file_full_path: 'ruby_code.rb'), + double("patch without additions", additions: 0) ] } + + let(:examiner) { double("examiner", smells: []) } + + before do + ::Reek::Examiner.stub(:new).and_return examiner + end + + it "calls reek with the files that have additions" do + subject + ::Reek::Examiner.should have_received(:new).with ['ruby_code.rb'] + end + end + + context 'patches with additions to non-ruby files' do + let(:patches) { [ + double("patch for ruby file", additions: 4, new_file_full_path: 'ruby_code.rb'), + double("patch for non-ruby file", additions: 4, new_file_full_path: 'other.stuff') ] } + + let(:examiner) { double("examiner", smells: []) } + + before do + ::Reek::Examiner.stub(:new).and_return examiner + end + + it "calls reek with only the ruby files" do + subject + ::Reek::Examiner.should have_received(:new).with ['ruby_code.rb'] + end + end end end end