From 210bc4f4da3d1da76a0d0736b8891e6c532a1175 Mon Sep 17 00:00:00 2001 From: Ernesto Tagwerker Date: Thu, 12 Sep 2019 17:00:27 -0400 Subject: [PATCH] Change `instance_doubles` to work with new implementation of reek generator Remove unused variable (`@lines`) --- spec/metric_fu/metrics/reek/generator_spec.rb | 45 ++++++++++++++----- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/spec/metric_fu/metrics/reek/generator_spec.rb b/spec/metric_fu/metrics/reek/generator_spec.rb index c95b8fb0b..5df7d8b19 100644 --- a/spec/metric_fu/metrics/reek/generator_spec.rb +++ b/spec/metric_fu/metrics/reek/generator_spec.rb @@ -1,4 +1,5 @@ require "spec_helper" + MetricFu.metrics_require { "reek/generator" } describe MetricFu::ReekGenerator do @@ -42,8 +43,8 @@ before :each do MetricFu::Configuration.run {} allow(File).to receive(:directory?).and_return(true) - @reek = MetricFu::ReekGenerator.new - @examiner = @reek.send(:examiner) + @generator = MetricFu::ReekGenerator.new + @examiner = @generator.send(:examiner) @smell_warning = Reek.const_defined?(:SmellWarning) ? Reek.const_get(:SmellWarning) : Reek.const_get(:Smells).const_get(:SmellWarning) if @smell_warning.instance_methods.include?(:subclass) @smell_warning.send(:alias_method, :smell_type, :subclass) @@ -99,9 +100,11 @@ smell_type: "Duplication", lines: [6, 9]) ] - @lines = instance_double(@examiner, smells: @smells) - @reek.instance_variable_set(:@output, @lines) - @matches = @reek.analyze + @examiners = [ + instance_double(Reek::Examiner, smells: @smells) + ] + @generator.instance_variable_set(:@output, @examiners) + @matches = @generator.analyze end it "should find the code smell's line numbers" do @@ -143,9 +146,11 @@ subclass: "Duplication", lines: [2, 4]), ] - @lines = instance_double(@examiner, smells: @smells) - @reek.instance_variable_set(:@output, @lines) - @matches = @reek.analyze + @examiners = [ + instance_double(Reek::Examiner, smells: @smells) + ] + @generator.instance_variable_set(:@output, @examiners) + @matches = @generator.analyze end it "uses the subclass field to find the smell type" do @@ -154,11 +159,29 @@ end end + context "with real output, not mocked nor doubled" do + let(:result) do + {:file_path=>"spec/support/samples/alfa.rb", :code_smells=>[{:method=>"Alfa", :message=>"takes parameters ['echo', 'foxtrot', 'golf'] to 3 methods", :type=>"DataClump", :lines=>[2, 3, 4]}, {:method=>"Alfa", :message=>"has no descriptive comment", :type=>"IrresponsibleModule", :lines=>[1]}, {:method=>"Alfa#bravo", :message=>"has unused parameter 'echo'", :type=>"UnusedParameters", :lines=>[2]}, {:method=>"Alfa#bravo", :message=>"has unused parameter 'foxtrot'", :type=>"UnusedParameters", :lines=>[2]}, {:method=>"Alfa#bravo", :message=>"has unused parameter 'golf'", :type=>"UnusedParameters", :lines=>[2]}, {:method=>"Alfa#charlie", :message=>"has unused parameter 'echo'", :type=>"UnusedParameters", :lines=>[3]}, {:method=>"Alfa#charlie", :message=>"has unused parameter 'foxtrot'", :type=>"UnusedParameters", :lines=>[3]}, {:method=>"Alfa#charlie", :message=>"has unused parameter 'golf'", :type=>"UnusedParameters", :lines=>[3]}, {:method=>"Alfa#delta", :message=>"has unused parameter 'echo'", :type=>"UnusedParameters", :lines=>[4]}, {:method=>"Alfa#delta", :message=>"has unused parameter 'foxtrot'", :type=>"UnusedParameters", :lines=>[4]}, {:method=>"Alfa#delta", :message=>"has unused parameter 'golf'", :type=>"UnusedParameters", :lines=>[4]}]} + end + before do + @generator = MetricFu::ReekGenerator.new(dirs_to_reek: ["spec/support/samples"]) + @generator.emit + end + + it "returns real data" do + @matches = @generator.analyze + + expect(@matches.first).to eq(result) + end + end + context "without reek warnings" do before :each do - @lines = instance_double(@examiner, smells: []) - @reek.instance_variable_set(:@output, @lines) - @matches = @reek.analyze + @examiners = [ + instance_double(Reek::Examiner, smells: []) + ] + @generator.instance_variable_set(:@output, @examiners) + @matches = @generator.analyze end it "returns empty analysis" do