diff --git a/lib/metric_fu/metric.rb b/lib/metric_fu/metric.rb index 267e11156..e3c349800 100644 --- a/lib/metric_fu/metric.rb +++ b/lib/metric_fu/metric.rb @@ -43,10 +43,11 @@ def default_run_args run_options.map { |k, v| "--#{k} #{v}" }.join(" ") end - def run + def run(options = run_options) not_implemented end + # TODO: move into generator def run_external(args = default_run_args) runner = GemRun.new( gem_name: gem_name.to_s, diff --git a/lib/metric_fu/metrics/flay/generator.rb b/lib/metric_fu/metrics/flay/generator.rb index aaba47782..c02a35e3b 100644 --- a/lib/metric_fu/metrics/flay/generator.rb +++ b/lib/metric_fu/metrics/flay/generator.rb @@ -5,8 +5,7 @@ def self.metric end def emit - args = "#{minimum_duplication_mass} #{dirs_to_flay}" - @output = run!(args) + @output = run(options) end def analyze @@ -35,17 +34,27 @@ def calculate_result(matches) } end + def run(options) + flay_options = Flay.default_options.merge(minimum_duplication_mass) + flay = Flay.new flay_options + files = Flay.expand_dirs_to_files(dirs_to_flay) + flay.process(*files) + MetricFu::Utility.capture_output do + flay.report + end + end + private def minimum_duplication_mass flay_mass = options[:minimum_score] - return "" unless flay_mass + return {} unless flay_mass - "--mass #{flay_mass} " + { :mass => flay_mass } end def dirs_to_flay - options[:dirs_to_flay].join(" ") + options[:dirs_to_flay] end end end diff --git a/lib/metric_fu/metrics/flay/metric.rb b/lib/metric_fu/metrics/flay/metric.rb index 67258e1bc..8eba709ff 100644 --- a/lib/metric_fu/metrics/flay/metric.rb +++ b/lib/metric_fu/metrics/flay/metric.rb @@ -22,6 +22,7 @@ def enable end def activate + activate_library 'flay' super end end diff --git a/spec/metric_fu/metrics/flay/generator_spec.rb b/spec/metric_fu/metrics/flay/generator_spec.rb index 2336bb750..4b6c2e13f 100644 --- a/spec/metric_fu/metrics/flay/generator_spec.rb +++ b/spec/metric_fu/metrics/flay/generator_spec.rb @@ -8,7 +8,10 @@ allow(File).to receive(:directory?).and_return(true) @flay = MetricFu::FlayGenerator.new(options) - expect(@flay).to receive(:run!).with(" app lib") + expected_options = Flay.default_options + expect(Flay).to receive(:expand_dirs_to_files).with(options[:dirs_to_flay]) + flay = double('flay', :process => nil) + allow(Flay).to receive(:new).and_return(flay) output = @flay.emit end @@ -17,7 +20,9 @@ allow(File).to receive(:directory?).and_return(true) @flay = MetricFu::FlayGenerator.new(options) - expect(@flay).to receive(:run!).with("--mass 99 ") + expected_options = Flay.default_options.merge(:mass => 99) + flay = double('flay', :process => nil) + expect(Flay).to receive(:new).with(expected_options).and_return(flay) output = @flay.emit end end