Sha256: b56c209953d9275cc5ff8559d916acfb8503256afdb304b8aa2e8edcc7f88a03

Contents?: true

Size: 1.94 KB

Versions: 9

Compression:

Stored size: 1.94 KB

Contents

require "spec_helper"
MetricFu.metrics_require { "hotspots/generator" }

describe MetricFu::HotspotsGenerator do
  describe "analyze method" do
    it "should be empty on error" do
      hotspots = MetricFu::HotspotsGenerator.new
      hotspots.instance_variable_set(:@analyzer, nil)
      result = hotspots.analyze
      expect(result).to eq(files: [], classes: [], methods: [])
    end

    it "should put the changes into a hash" do
      hotspots = MetricFu::HotspotsGenerator.new
      hotspots.analyze
      result = hotspots.to_h[:hotspots]
      expected = HOTSPOT_DATA["generator_analysis.yml"]
      # ensure expected granularities
      expect(result.keys).to eq(expected.keys)

      # for each granularity's location details
      result.each do |granularity, location_details|
        # map 2d array for this granularity of [details, location]
        expected_result = expected.fetch(granularity).map { |ld| [ld.fetch("details"), ld.fetch("location")] }
        # verify all the location details for this granularity match elements of expected_result
        location_details.each do |location_detail|
          location = location_detail.fetch("location")
          details  = location_detail.fetch("details")
          # get the location_detail array where the  where the locations (second element) match
          expected_location_details = expected_result.rassoc(location)
          # get the details (first element) from the expected location_details array
          expected_details = expected_location_details[0]
          expect(details).to eq(expected_details)
        end
      end
    end

    # really testing the output of analyzed_problems#worst_items
    it "should return the worst item granularities: files, classes, methods" do
      hotspots = MetricFu::HotspotsGenerator.new
      yaml = HOTSPOT_DATA["generator.yml"]
      analyzer = HotspotAnalyzer.new(yaml)
      expect(hotspots.analyze.keys).to eq([:files, :classes, :methods])
    end
  end
end

Version data entries

9 entries across 9 versions & 3 rubygems

Version Path
metric_fu-4.13.0 spec/metric_fu/metrics/hotspots/generator_spec.rb
fastruby-metric_fu-5.0.0 spec/metric_fu/metrics/hotspots/generator_spec.rb
code_metric_fu-4.14.4 spec/metric_fu/metrics/hotspots/generator_spec.rb
code_metric_fu-4.14.3 spec/metric_fu/metrics/hotspots/generator_spec.rb
code_metric_fu-4.14.2 spec/metric_fu/metrics/hotspots/generator_spec.rb
code_metric_fu-4.14.1 spec/metric_fu/metrics/hotspots/generator_spec.rb
code_metric_fu-4.14.0 spec/metric_fu/metrics/hotspots/generator_spec.rb
metric_fu-4.12.0 spec/metric_fu/metrics/hotspots/generator_spec.rb
metric_fu-4.11.4 spec/metric_fu/metrics/hotspots/generator_spec.rb