code_metric_fu 4.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +28 -0
- data/.metrics +3 -0
- data/.rspec +2 -0
- data/.rubocop.yml +15 -0
- data/.rubocop_todo.yml +69 -0
- data/.simplecov +74 -0
- data/.travis.yml +22 -0
- data/.yardopts +4 -0
- data/AUTHORS +12 -0
- data/CONTRIBUTING.md +47 -0
- data/CONTRIBUTORS +76 -0
- data/DEV.md +76 -0
- data/Gemfile +74 -0
- data/Guardfile +30 -0
- data/HISTORY.md +705 -0
- data/MIT-LICENSE +22 -0
- data/README.md +299 -0
- data/Rakefile +27 -0
- data/TODO.md +118 -0
- data/appveyor.yml +31 -0
- data/bin/metric_fu +9 -0
- data/bin/mf-cane +10 -0
- data/bin/mf-churn +10 -0
- data/bin/mf-flay +10 -0
- data/bin/mf-reek +10 -0
- data/bin/mf-roodi +10 -0
- data/bin/mf-saikuro +10 -0
- data/certs/bf4.pem +22 -0
- data/checksum/.gitkeep +0 -0
- data/checksum/metric_fu-4.10.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.11.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.11.1.gem.sha512 +1 -0
- data/checksum/metric_fu-4.11.2.gem.sha512 +1 -0
- data/checksum/metric_fu-4.11.3.gem.sha512 +1 -0
- data/checksum/metric_fu-4.11.4.gem.sha512 +1 -0
- data/checksum/metric_fu-4.12.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.2.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.2.1.gem.sha512 +1 -0
- data/checksum/metric_fu-4.3.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.3.1.gem.sha512 +1 -0
- data/checksum/metric_fu-4.4.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.4.1.gem.sha512 +1 -0
- data/checksum/metric_fu-4.4.2.gem.sha512 +1 -0
- data/checksum/metric_fu-4.4.3.gem.sha512 +1 -0
- data/checksum/metric_fu-4.4.4.gem.sha512 +1 -0
- data/checksum/metric_fu-4.5.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.5.1.gem.sha512 +1 -0
- data/checksum/metric_fu-4.5.2.gem.sha512 +1 -0
- data/checksum/metric_fu-4.6.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.7.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.7.1.gem.sha512 +1 -0
- data/checksum/metric_fu-4.7.2.gem.sha512 +1 -0
- data/checksum/metric_fu-4.7.3.gem.sha512 +1 -0
- data/checksum/metric_fu-4.7.4.gem.sha512 +1 -0
- data/checksum/metric_fu-4.8.0.gem.sha512 +1 -0
- data/checksum/metric_fu-4.9.0.gem.sha512 +1 -0
- data/config/roodi_config.yml +22 -0
- data/config/rubocop.yml +269 -0
- data/gem_tasks/build.rake +197 -0
- data/gem_tasks/rubocop.rake +10 -0
- data/gem_tasks/usage_test.rake +19 -0
- data/gem_tasks/yard.rake +24 -0
- data/lib/metric_fu/calculate.rb +10 -0
- data/lib/metric_fu/cli/client.rb +26 -0
- data/lib/metric_fu/cli/helper.rb +80 -0
- data/lib/metric_fu/cli/parser.rb +138 -0
- data/lib/metric_fu/configuration.rb +150 -0
- data/lib/metric_fu/constantize.rb +57 -0
- data/lib/metric_fu/data_structures/line_numbers.rb +112 -0
- data/lib/metric_fu/data_structures/location.rb +110 -0
- data/lib/metric_fu/data_structures/sexp_node.rb +107 -0
- data/lib/metric_fu/environment.rb +129 -0
- data/lib/metric_fu/errors/analysis_error.rb +4 -0
- data/lib/metric_fu/formatter/html.rb +96 -0
- data/lib/metric_fu/formatter/syntax.rb +45 -0
- data/lib/metric_fu/formatter/yaml.rb +18 -0
- data/lib/metric_fu/formatter.rb +40 -0
- data/lib/metric_fu/gem_run.rb +70 -0
- data/lib/metric_fu/gem_version.rb +92 -0
- data/lib/metric_fu/generator.rb +135 -0
- data/lib/metric_fu/io.rb +132 -0
- data/lib/metric_fu/loader.rb +105 -0
- data/lib/metric_fu/logger.rb +62 -0
- data/lib/metric_fu/logging/mf_debugger.rb +23 -0
- data/lib/metric_fu/metric.rb +143 -0
- data/lib/metric_fu/metrics/cane/generator.rb +95 -0
- data/lib/metric_fu/metrics/cane/grapher.rb +37 -0
- data/lib/metric_fu/metrics/cane/metric.rb +34 -0
- data/lib/metric_fu/metrics/cane/report.html.erb +87 -0
- data/lib/metric_fu/metrics/cane/violations.rb +46 -0
- data/lib/metric_fu/metrics/churn/generator.rb +37 -0
- data/lib/metric_fu/metrics/churn/hotspot.rb +43 -0
- data/lib/metric_fu/metrics/churn/metric.rb +29 -0
- data/lib/metric_fu/metrics/churn/report.html.erb +58 -0
- data/lib/metric_fu/metrics/flay/generator.rb +51 -0
- data/lib/metric_fu/metrics/flay/grapher.rb +37 -0
- data/lib/metric_fu/metrics/flay/hotspot.rb +52 -0
- data/lib/metric_fu/metrics/flay/metric.rb +28 -0
- data/lib/metric_fu/metrics/flay/report.html.erb +29 -0
- data/lib/metric_fu/metrics/flog/generator.rb +113 -0
- data/lib/metric_fu/metrics/flog/grapher.rb +77 -0
- data/lib/metric_fu/metrics/flog/hotspot.rb +46 -0
- data/lib/metric_fu/metrics/flog/metric.rb +29 -0
- data/lib/metric_fu/metrics/flog/report.html.erb +50 -0
- data/lib/metric_fu/metrics/hotspots/analysis/analyzed_problems.rb +34 -0
- data/lib/metric_fu/metrics/hotspots/analysis/analyzer_tables.rb +114 -0
- data/lib/metric_fu/metrics/hotspots/analysis/grouping.rb +23 -0
- data/lib/metric_fu/metrics/hotspots/analysis/groupings.rb +12 -0
- data/lib/metric_fu/metrics/hotspots/analysis/problems.rb +20 -0
- data/lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb +70 -0
- data/lib/metric_fu/metrics/hotspots/analysis/ranking.rb +29 -0
- data/lib/metric_fu/metrics/hotspots/analysis/rankings.rb +91 -0
- data/lib/metric_fu/metrics/hotspots/analysis/record.rb +32 -0
- data/lib/metric_fu/metrics/hotspots/analysis/scoring_strategies.rb +24 -0
- data/lib/metric_fu/metrics/hotspots/analysis/table.rb +67 -0
- data/lib/metric_fu/metrics/hotspots/generator.rb +40 -0
- data/lib/metric_fu/metrics/hotspots/hotspot.rb +87 -0
- data/lib/metric_fu/metrics/hotspots/hotspot_analyzer.rb +61 -0
- data/lib/metric_fu/metrics/hotspots/metric.rb +20 -0
- data/lib/metric_fu/metrics/hotspots/report.html.erb +60 -0
- data/lib/metric_fu/metrics/rails_best_practices/generator.rb +47 -0
- data/lib/metric_fu/metrics/rails_best_practices/grapher.rb +38 -0
- data/lib/metric_fu/metrics/rails_best_practices/metric.rb +31 -0
- data/lib/metric_fu/metrics/rails_best_practices/report.html.erb +22 -0
- data/lib/metric_fu/metrics/rcov/external_client.rb +22 -0
- data/lib/metric_fu/metrics/rcov/generator.rb +75 -0
- data/lib/metric_fu/metrics/rcov/grapher.rb +37 -0
- data/lib/metric_fu/metrics/rcov/hotspot.rb +46 -0
- data/lib/metric_fu/metrics/rcov/metric.rb +61 -0
- data/lib/metric_fu/metrics/rcov/rcov_format_coverage.rb +149 -0
- data/lib/metric_fu/metrics/rcov/rcov_line.rb +48 -0
- data/lib/metric_fu/metrics/rcov/report.html.erb +40 -0
- data/lib/metric_fu/metrics/rcov/simplecov_formatter.rb +74 -0
- data/lib/metric_fu/metrics/reek/generator.rb +97 -0
- data/lib/metric_fu/metrics/reek/grapher.rb +55 -0
- data/lib/metric_fu/metrics/reek/hotspot.rb +95 -0
- data/lib/metric_fu/metrics/reek/metric.rb +26 -0
- data/lib/metric_fu/metrics/reek/report.html.erb +35 -0
- data/lib/metric_fu/metrics/roodi/generator.rb +41 -0
- data/lib/metric_fu/metrics/roodi/grapher.rb +37 -0
- data/lib/metric_fu/metrics/roodi/hotspot.rb +39 -0
- data/lib/metric_fu/metrics/roodi/metric.rb +24 -0
- data/lib/metric_fu/metrics/roodi/report.html.erb +22 -0
- data/lib/metric_fu/metrics/saikuro/generator.rb +145 -0
- data/lib/metric_fu/metrics/saikuro/hotspot.rb +51 -0
- data/lib/metric_fu/metrics/saikuro/metric.rb +31 -0
- data/lib/metric_fu/metrics/saikuro/parsing_element.rb +37 -0
- data/lib/metric_fu/metrics/saikuro/report.html.erb +71 -0
- data/lib/metric_fu/metrics/saikuro/scratch_file.rb +108 -0
- data/lib/metric_fu/metrics/stats/generator.rb +82 -0
- data/lib/metric_fu/metrics/stats/grapher.rb +40 -0
- data/lib/metric_fu/metrics/stats/hotspot.rb +35 -0
- data/lib/metric_fu/metrics/stats/metric.rb +28 -0
- data/lib/metric_fu/metrics/stats/report.html.erb +44 -0
- data/lib/metric_fu/reporter.rb +37 -0
- data/lib/metric_fu/reporting/graphs/graph.rb +69 -0
- data/lib/metric_fu/reporting/graphs/grapher.rb +66 -0
- data/lib/metric_fu/reporting/result.rb +59 -0
- data/lib/metric_fu/run.rb +82 -0
- data/lib/metric_fu/tasks/metric_fu.rake +54 -0
- data/lib/metric_fu/templates/_gem_info.html.erb +8 -0
- data/lib/metric_fu/templates/_graph.html.erb +2 -0
- data/lib/metric_fu/templates/_report_footer.html.erb +1 -0
- data/lib/metric_fu/templates/configuration.rb +25 -0
- data/lib/metric_fu/templates/css/bluff.css +15 -0
- data/lib/metric_fu/templates/css/buttons.css +82 -0
- data/lib/metric_fu/templates/css/default.css +43 -0
- data/lib/metric_fu/templates/css/integrity.css +337 -0
- data/lib/metric_fu/templates/css/rcov.css +32 -0
- data/lib/metric_fu/templates/css/reset.css +7 -0
- data/lib/metric_fu/templates/css/syntax.css +19 -0
- data/lib/metric_fu/templates/index.html.erb +13 -0
- data/lib/metric_fu/templates/javascripts/bluff-min.js +1 -0
- data/lib/metric_fu/templates/javascripts/bluff_graph.js +15 -0
- data/lib/metric_fu/templates/javascripts/excanvas.js +35 -0
- data/lib/metric_fu/templates/javascripts/highcharts.js +294 -0
- data/lib/metric_fu/templates/javascripts/highcharts_graph.js +38 -0
- data/lib/metric_fu/templates/javascripts/js-class.js +1 -0
- data/lib/metric_fu/templates/javascripts/standalone-framework.js +17 -0
- data/lib/metric_fu/templates/javascripts/utils.js +9 -0
- data/lib/metric_fu/templates/layout.html.erb +41 -0
- data/lib/metric_fu/templates/metrics_template.rb +86 -0
- data/lib/metric_fu/templates/report.html.erb +31 -0
- data/lib/metric_fu/templates/report.rb +41 -0
- data/lib/metric_fu/templates/template.rb +247 -0
- data/lib/metric_fu/utility.rb +79 -0
- data/lib/metric_fu/version.rb +9 -0
- data/lib/metric_fu.rb +143 -0
- data/metric_fu.gemspec +72 -0
- data/spec/capture_warnings.rb +55 -0
- data/spec/cli/helper_spec.rb +165 -0
- data/spec/dummy/.gitignore +1 -0
- data/spec/dummy/.gitkeep +0 -0
- data/spec/dummy/.metrics +4 -0
- data/spec/dummy/lib/.gitkeep +0 -0
- data/spec/dummy/lib/bad_encoding.rb +6 -0
- data/spec/dummy/spec/.gitkeep +0 -0
- data/spec/fixtures/20090630.yml +7922 -0
- data/spec/fixtures/coverage-153.rb +11 -0
- data/spec/fixtures/coverage.rb +13 -0
- data/spec/fixtures/exit0.sh +3 -0
- data/spec/fixtures/exit1.sh +3 -0
- data/spec/fixtures/hotspots/flog.yml +86 -0
- data/spec/fixtures/hotspots/generator.yml +47 -0
- data/spec/fixtures/hotspots/generator_analysis.yml +53 -0
- data/spec/fixtures/hotspots/reek.yml +14 -0
- data/spec/fixtures/hotspots/roodi.yml +13 -0
- data/spec/fixtures/hotspots/saikuro.yml +27 -0
- data/spec/fixtures/hotspots/several_metrics.yml +47 -0
- data/spec/fixtures/hotspots/stats.yml +4 -0
- data/spec/fixtures/hotspots/three_metrics_on_same_file.yml +36 -0
- data/spec/fixtures/line_numbers/foo.rb +33 -0
- data/spec/fixtures/line_numbers/module.rb +11 -0
- data/spec/fixtures/line_numbers/module_surrounds_class.rb +15 -0
- data/spec/fixtures/line_numbers/two_classes.rb +11 -0
- data/spec/fixtures/metric_missing.yml +1 -0
- data/spec/fixtures/rcov_output.txt +135 -0
- data/spec/fixtures/saikuro/app/controllers/sessions_controller.rb_cyclo.html +10 -0
- data/spec/fixtures/saikuro/app/controllers/users_controller.rb_cyclo.html +16 -0
- data/spec/fixtures/saikuro/index_cyclo.html +155 -0
- data/spec/fixtures/saikuro_sfiles/thing.rb_cyclo.html +11 -0
- data/spec/metric_fu/calculate_spec.rb +21 -0
- data/spec/metric_fu/configuration_spec.rb +90 -0
- data/spec/metric_fu/data_structures/line_numbers_spec.rb +63 -0
- data/spec/metric_fu/data_structures/location_spec.rb +110 -0
- data/spec/metric_fu/formatter/configuration_spec.rb +44 -0
- data/spec/metric_fu/formatter/html_spec.rb +138 -0
- data/spec/metric_fu/formatter/yaml_spec.rb +61 -0
- data/spec/metric_fu/formatter_spec.rb +49 -0
- data/spec/metric_fu/gem_version_spec.rb +12 -0
- data/spec/metric_fu/generator_spec.rb +130 -0
- data/spec/metric_fu/loader_spec.rb +10 -0
- data/spec/metric_fu/metric_spec.rb +46 -0
- data/spec/metric_fu/metrics/cane/configuration_spec.rb +22 -0
- data/spec/metric_fu/metrics/cane/generator_spec.rb +184 -0
- data/spec/metric_fu/metrics/churn/configuration_spec.rb +13 -0
- data/spec/metric_fu/metrics/churn/generator_spec.rb +64 -0
- data/spec/metric_fu/metrics/flay/configuration_spec.rb +13 -0
- data/spec/metric_fu/metrics/flay/generator_spec.rb +105 -0
- data/spec/metric_fu/metrics/flay/grapher_spec.rb +57 -0
- data/spec/metric_fu/metrics/flog/configuration_spec.rb +18 -0
- data/spec/metric_fu/metrics/flog/generator_spec.rb +77 -0
- data/spec/metric_fu/metrics/flog/grapher_spec.rb +107 -0
- data/spec/metric_fu/metrics/hotspots/analysis/analyzed_problems_spec.rb +104 -0
- data/spec/metric_fu/metrics/hotspots/analysis/analyzer_tables_spec.rb +71 -0
- data/spec/metric_fu/metrics/hotspots/analysis/ranking_spec.rb +30 -0
- data/spec/metric_fu/metrics/hotspots/analysis/rankings_spec.rb +97 -0
- data/spec/metric_fu/metrics/hotspots/analysis/table_spec.rb +6 -0
- data/spec/metric_fu/metrics/hotspots/generator_spec.rb +46 -0
- data/spec/metric_fu/metrics/hotspots/hotspot_analyzer_spec.rb +10 -0
- data/spec/metric_fu/metrics/hotspots/hotspot_spec.rb +16 -0
- data/spec/metric_fu/metrics/rails_best_practices/configuration_spec.rb +55 -0
- data/spec/metric_fu/metrics/rails_best_practices/generator_spec.rb +33 -0
- data/spec/metric_fu/metrics/rails_best_practices/grapher_spec.rb +62 -0
- data/spec/metric_fu/metrics/rcov/configuration_spec.rb +28 -0
- data/spec/metric_fu/metrics/rcov/generator_spec.rb +22 -0
- data/spec/metric_fu/metrics/rcov/grapher_spec.rb +57 -0
- data/spec/metric_fu/metrics/rcov/hotspot_spec.rb +20 -0
- data/spec/metric_fu/metrics/rcov/rcov_line_spec.rb +89 -0
- data/spec/metric_fu/metrics/rcov/simplecov_formatter_spec.rb +67 -0
- data/spec/metric_fu/metrics/reek/configuration_spec.rb +13 -0
- data/spec/metric_fu/metrics/reek/generator_spec.rb +169 -0
- data/spec/metric_fu/metrics/reek/grapher_spec.rb +66 -0
- data/spec/metric_fu/metrics/roodi/configuration_spec.rb +14 -0
- data/spec/metric_fu/metrics/roodi/generator_spec.rb +82 -0
- data/spec/metric_fu/metrics/roodi/grapher_spec.rb +57 -0
- data/spec/metric_fu/metrics/saikuro/configuration_spec.rb +25 -0
- data/spec/metric_fu/metrics/saikuro/generator_spec.rb +71 -0
- data/spec/metric_fu/metrics/stats/generator_spec.rb +96 -0
- data/spec/metric_fu/metrics/stats/grapher_spec.rb +69 -0
- data/spec/metric_fu/reporter_spec.rb +41 -0
- data/spec/metric_fu/reporting/graphs/graph_spec.rb +44 -0
- data/spec/metric_fu/reporting/graphs/grapher_spec.rb +24 -0
- data/spec/metric_fu/reporting/result_spec.rb +50 -0
- data/spec/metric_fu/run_spec.rb +197 -0
- data/spec/metric_fu/templates/configuration_spec.rb +51 -0
- data/spec/metric_fu/templates/metrics_template_spec.rb +11 -0
- data/spec/metric_fu/templates/report_spec.rb +15 -0
- data/spec/metric_fu/templates/template_spec.rb +233 -0
- data/spec/metric_fu/utility_spec.rb +12 -0
- data/spec/metric_fu_spec.rb +33 -0
- data/spec/quality_spec.rb +114 -0
- data/spec/shared/configured.rb +45 -0
- data/spec/shared/test_coverage.rb +95 -0
- data/spec/spec_helper.rb +54 -0
- data/spec/support/deferred_garbaged_collection.rb +33 -0
- data/spec/support/helper_methods.rb +32 -0
- data/spec/support/matcher_create_file.rb +37 -0
- data/spec/support/matcher_create_files.rb +43 -0
- data/spec/support/suite.rb +26 -0
- data/spec/support/test_fixtures.rb +37 -0
- data/spec/support/timeout.rb +7 -0
- data/spec/support/usage_test.rb +150 -0
- data/spec/usage_test_spec.rb +93 -0
- metadata +757 -0
@@ -0,0 +1,169 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
MetricFu.metrics_require { "reek/generator" }
|
3
|
+
|
4
|
+
describe MetricFu::ReekGenerator do
|
5
|
+
describe "emit" do
|
6
|
+
let(:options) { { dirs_to_reek: [] } }
|
7
|
+
let(:files_to_analyze) { ["lib/foo.rb", "lib/bar.rb"] }
|
8
|
+
let(:reek) { MetricFu::ReekGenerator.new(options) }
|
9
|
+
|
10
|
+
before :each do
|
11
|
+
allow(reek).to receive(:files_to_analyze).and_return(files_to_analyze)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "includes config file pattern into reek parameters when specified" do
|
15
|
+
options.merge!(config_file_pattern: "lib/config/*.reek")
|
16
|
+
|
17
|
+
expect(reek).to receive(:run!) do |_files, config_files|
|
18
|
+
expect(config_files).to eq(["lib/config/*.reek"])
|
19
|
+
end.and_return("")
|
20
|
+
|
21
|
+
reek.emit
|
22
|
+
end
|
23
|
+
|
24
|
+
it "passes an empty array when no config file pattern is specified" do
|
25
|
+
expect(reek).to receive(:run!) do |_files, config_files|
|
26
|
+
expect(config_files).to eq([])
|
27
|
+
end.and_return("")
|
28
|
+
|
29
|
+
reek.emit
|
30
|
+
end
|
31
|
+
|
32
|
+
it "includes files to analyze into reek parameters" do
|
33
|
+
expect(reek).to receive(:run!) do |files, _config_files|
|
34
|
+
expect(files).to eq(["lib/foo.rb", "lib/bar.rb"])
|
35
|
+
end.and_return("")
|
36
|
+
|
37
|
+
reek.emit
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "analyze method" do
|
42
|
+
before :each do
|
43
|
+
MetricFu::Configuration.run {}
|
44
|
+
allow(File).to receive(:directory?).and_return(true)
|
45
|
+
@reek = MetricFu::ReekGenerator.new
|
46
|
+
@examiner = @reek.send(:examiner)
|
47
|
+
@smell_warning = Reek.const_defined?(:SmellWarning) ? Reek.const_get(:SmellWarning) : Reek.const_get(:Smells).const_get(:SmellWarning)
|
48
|
+
if @smell_warning.instance_methods.include?(:subclass)
|
49
|
+
@smell_warning.send(:alias_method, :smell_type, :subclass)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "with reek warnings" do
|
54
|
+
before :each do
|
55
|
+
@smells = [
|
56
|
+
instance_double(@smell_warning,
|
57
|
+
source: "app/controllers/activity_reports_controller.rb",
|
58
|
+
context: "ActivityReportsController#authorize_user",
|
59
|
+
message: "calls current_user.primary_site_ids multiple times",
|
60
|
+
smell_type: "Duplication",
|
61
|
+
lines: [2, 4]),
|
62
|
+
instance_double(@smell_warning,
|
63
|
+
source: "app/controllers/activity_reports_controller.rb",
|
64
|
+
context: "ActivityReportsController#authorize_user",
|
65
|
+
message: "calls params[id] multiple times",
|
66
|
+
smell_type: "Duplication",
|
67
|
+
lines: [5, 7]),
|
68
|
+
instance_double(@smell_warning,
|
69
|
+
source: "app/controllers/activity_reports_controller.rb",
|
70
|
+
context: "ActivityReportsController#authorize_user",
|
71
|
+
message: "calls params[primary_site_id] multiple times",
|
72
|
+
smell_type: "Duplication",
|
73
|
+
lines: [11, 15]),
|
74
|
+
instance_double(@smell_warning,
|
75
|
+
source: "app/controllers/activity_reports_controller.rb",
|
76
|
+
context: "ActivityReportsController#authorize_user",
|
77
|
+
message: "has approx 6 statements",
|
78
|
+
smell_type: "Long Method",
|
79
|
+
lines: [8]),
|
80
|
+
|
81
|
+
instance_double(@smell_warning,
|
82
|
+
source: "app/controllers/application.rb",
|
83
|
+
context: "ApplicationController#start_background_task/block/block",
|
84
|
+
message: "is nested",
|
85
|
+
smell_type: "Nested Iterators",
|
86
|
+
lines: [23]),
|
87
|
+
|
88
|
+
instance_double(@smell_warning,
|
89
|
+
source: "app/controllers/link_targets_controller.rb",
|
90
|
+
context: "LinkTargetsController#authorize_user",
|
91
|
+
message: "calls current_user.role multiple times",
|
92
|
+
smell_type: "Duplication",
|
93
|
+
lines: [8]),
|
94
|
+
|
95
|
+
instance_double(@smell_warning,
|
96
|
+
source: "app/controllers/newline_controller.rb",
|
97
|
+
context: "NewlineController#some_method",
|
98
|
+
message: "calls current_user.<< \"new line\n\" multiple times",
|
99
|
+
smell_type: "Duplication",
|
100
|
+
lines: [6, 9])
|
101
|
+
]
|
102
|
+
@lines = instance_double(@examiner, smells: @smells)
|
103
|
+
@reek.instance_variable_set(:@output, @lines)
|
104
|
+
@matches = @reek.analyze
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should find the code smell's line numbers" do
|
108
|
+
smell = @matches.first[:code_smells].first
|
109
|
+
expect(smell[:lines]).to eq([2, 4])
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should find the code smell's method name" do
|
113
|
+
smell = @matches.first[:code_smells].first
|
114
|
+
expect(smell[:method]).to eq("ActivityReportsController#authorize_user")
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should find the code smell's type" do
|
118
|
+
smell = @matches[1][:code_smells].first
|
119
|
+
expect(smell[:type]).to eq("Nested Iterators")
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should find the code smell's message" do
|
123
|
+
smell = @matches[1][:code_smells].first
|
124
|
+
expect(smell[:message]).to eq("is nested")
|
125
|
+
end
|
126
|
+
|
127
|
+
it "should find the code smell's type" do
|
128
|
+
smell = @matches.first
|
129
|
+
expect(smell[:file_path]).to eq("app/controllers/activity_reports_controller.rb")
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should NOT insert nil smells into the array when there's a newline in the method call" do
|
133
|
+
expect(@matches.last[:code_smells]).to eq(@matches.last[:code_smells].compact)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
context "with reek 1.3 output" do
|
138
|
+
before :each do
|
139
|
+
@smells = [
|
140
|
+
double(source: "app/controllers/activity_reports_controller.rb",
|
141
|
+
context: "ActivityReportsController#authorize_user",
|
142
|
+
message: "calls current_user.primary_site_ids multiple times",
|
143
|
+
subclass: "Duplication",
|
144
|
+
lines: [2, 4]),
|
145
|
+
]
|
146
|
+
@lines = instance_double(@examiner, smells: @smells)
|
147
|
+
@reek.instance_variable_set(:@output, @lines)
|
148
|
+
@matches = @reek.analyze
|
149
|
+
end
|
150
|
+
|
151
|
+
it "uses the subclass field to find the smell type" do
|
152
|
+
smell = @matches.first[:code_smells].first
|
153
|
+
expect(smell[:type]).to eq('Duplication')
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
context "without reek warnings" do
|
158
|
+
before :each do
|
159
|
+
@lines = instance_double(@examiner, smells: [])
|
160
|
+
@reek.instance_variable_set(:@output, @lines)
|
161
|
+
@matches = @reek.analyze
|
162
|
+
end
|
163
|
+
|
164
|
+
it "returns empty analysis" do
|
165
|
+
expect(@matches).to eq([])
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
MetricFu.metrics_require { "reek/grapher" }
|
3
|
+
|
4
|
+
describe ReekGrapher do
|
5
|
+
before :each do
|
6
|
+
@reek_grapher = MetricFu::ReekGrapher.new
|
7
|
+
MetricFu.configuration
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should respond to reek_count and labels" do
|
11
|
+
expect(@reek_grapher).to respond_to(:reek_count)
|
12
|
+
expect(@reek_grapher).to respond_to(:labels)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "responding to #initialize" do
|
16
|
+
it "should initialise reek_count and labels" do
|
17
|
+
expect(@reek_grapher.reek_count).to eq({})
|
18
|
+
expect(@reek_grapher.labels).to eq({})
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "responding to #get_metrics" do
|
23
|
+
context "when metrics were not generated" do
|
24
|
+
before(:each) do
|
25
|
+
@metrics = FIXTURE.load_metric("metric_missing.yml")
|
26
|
+
@date = "1/2"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should not set a hash of code smells to reek_count" do
|
30
|
+
@reek_grapher.get_metrics(@metrics, @date)
|
31
|
+
expect(@reek_grapher.reek_count).to eq({})
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should not update labels with the date" do
|
35
|
+
expect(@reek_grapher.labels).not_to receive(:update)
|
36
|
+
@reek_grapher.get_metrics(@metrics, @date)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when metrics have been generated" do
|
41
|
+
before(:each) do
|
42
|
+
@metrics = FIXTURE.load_metric("20090630.yml")
|
43
|
+
@date = "1/2"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should set a hash of code smells to reek_count" do
|
47
|
+
@reek_grapher.get_metrics(@metrics, @date)
|
48
|
+
expect(@reek_grapher.reek_count).to eq(
|
49
|
+
"Uncommunicative Name" => [27],
|
50
|
+
"Feature Envy" => [20],
|
51
|
+
"Utility Function" => [15],
|
52
|
+
"Long Method" => [26],
|
53
|
+
"Nested Iterators" => [12],
|
54
|
+
"Control Couple" => [4],
|
55
|
+
"Duplication" => [48],
|
56
|
+
"Large Class" => [1]
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
it "should update labels with the date" do
|
61
|
+
expect(@reek_grapher.labels).to receive(:update).with(0 => "1/2")
|
62
|
+
@reek_grapher.get_metrics(@metrics, @date)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "shared/configured"
|
3
|
+
|
4
|
+
describe MetricFu::Configuration, "for roodi" do
|
5
|
+
it_behaves_like "configured" do
|
6
|
+
it "should set @roodi to {:dirs_to_roodi => @code_dirs}" do
|
7
|
+
load_metric "roodi"
|
8
|
+
expect(MetricFu::Metric.get_metric(:roodi).run_options).to eq(
|
9
|
+
dirs_to_roodi: directory("code_dirs"),
|
10
|
+
roodi_config: "#{directory('root_directory')}/config/roodi_config.yml"
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
MetricFu.metrics_require { "roodi/generator" }
|
3
|
+
|
4
|
+
describe MetricFu::RoodiGenerator do
|
5
|
+
describe "emit" do
|
6
|
+
it "should add config options when present" do
|
7
|
+
options = { roodi_config: "lib/config/roodi_config.yml", dirs_to_roodi: [] }
|
8
|
+
roodi = MetricFu::RoodiGenerator.new(options)
|
9
|
+
expect(roodi).to receive(:run!).with(/-config=lib\/config\/roodi_config\.yml/).and_return("")
|
10
|
+
roodi.emit
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should NOT add config options when NOT present" do
|
14
|
+
options = { dirs_to_roodi: [] }
|
15
|
+
roodi = MetricFu::RoodiGenerator.new(options)
|
16
|
+
allow(roodi).to receive(:run!)
|
17
|
+
expect(roodi).to receive(:run!).with(/-config/).never
|
18
|
+
roodi.emit
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "analyze" do
|
23
|
+
context "when it has multiple failures" do
|
24
|
+
before :each do
|
25
|
+
lines = <<-HERE
|
26
|
+
|
27
|
+
Running Roodi checks
|
28
|
+
./app/models/some_model.rb:14 - Found = in conditional. It should probably be an ==
|
29
|
+
lib/some_file.rb:53 - Rescue block should not be empty.
|
30
|
+
|
31
|
+
Checked 65 files
|
32
|
+
HERE
|
33
|
+
|
34
|
+
roodi = MetricFu::RoodiGenerator.new
|
35
|
+
roodi.instance_variable_set(:@output, lines)
|
36
|
+
@matches = roodi.analyze
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should find all problems" do
|
40
|
+
problem_count = @matches[:problems].size
|
41
|
+
expect(problem_count).to eq(2)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should find the file of the problem" do
|
45
|
+
problem = @matches[:problems].first
|
46
|
+
expect(problem[:file]).to eq("./app/models/some_model.rb")
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should find the line of the problem" do
|
50
|
+
problem = @matches[:problems].first
|
51
|
+
expect(problem[:line]).to eq("14")
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should find the description of the problem" do
|
55
|
+
problem = @matches[:problems].first
|
56
|
+
expect(problem[:problem]).to eq("Found = in conditional. It should probably be an ==")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "when it has no failures" do
|
62
|
+
before :each do
|
63
|
+
lines = <<-HERE
|
64
|
+
|
65
|
+
Running Roodi checks
|
66
|
+
|
67
|
+
Checked 42 files
|
68
|
+
Found 0 errors.
|
69
|
+
|
70
|
+
HERE
|
71
|
+
|
72
|
+
roodi = MetricFu::RoodiGenerator.new
|
73
|
+
roodi.instance_variable_set(:@output, lines)
|
74
|
+
@matches = roodi.analyze
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should have no problems" do
|
78
|
+
problem_count = @matches[:problems].size
|
79
|
+
expect(problem_count).to eq(0)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
MetricFu.metrics_require { "roodi/grapher" }
|
3
|
+
|
4
|
+
describe RoodiGrapher do
|
5
|
+
before :each do
|
6
|
+
@roodi_grapher = MetricFu::RoodiGrapher.new
|
7
|
+
MetricFu.configuration
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should respond to roodi_count and labels" do
|
11
|
+
expect(@roodi_grapher).to respond_to(:roodi_count)
|
12
|
+
expect(@roodi_grapher).to respond_to(:labels)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "responding to #initialize" do
|
16
|
+
it "should initialise roodi_count and labels" do
|
17
|
+
expect(@roodi_grapher.roodi_count).to eq([])
|
18
|
+
expect(@roodi_grapher.labels).to eq({})
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "responding to #get_metrics" do
|
23
|
+
context "when metrics were not generated" do
|
24
|
+
before(:each) do
|
25
|
+
@metrics = FIXTURE.load_metric("metric_missing.yml")
|
26
|
+
@date = "1/2"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should not push to roodi_count" do
|
30
|
+
expect(@roodi_grapher.roodi_count).not_to receive(:push)
|
31
|
+
@roodi_grapher.get_metrics(@metrics, @date)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should not update labels with the date" do
|
35
|
+
expect(@roodi_grapher.labels).not_to receive(:update)
|
36
|
+
@roodi_grapher.get_metrics(@metrics, @date)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when metrics have been generated" do
|
41
|
+
before(:each) do
|
42
|
+
@metrics = FIXTURE.load_metric("20090630.yml")
|
43
|
+
@date = "1/2"
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should push to roodi_count" do
|
47
|
+
expect(@roodi_grapher.roodi_count).to receive(:push).with(13)
|
48
|
+
@roodi_grapher.get_metrics(@metrics, @date)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should update labels with the date" do
|
52
|
+
expect(@roodi_grapher.labels).to receive(:update).with(0 => "1/2")
|
53
|
+
@roodi_grapher.get_metrics(@metrics, @date)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "shared/configured"
|
3
|
+
|
4
|
+
describe MetricFu::Configuration, "for saikuro" do
|
5
|
+
it_behaves_like "configured" do
|
6
|
+
it "should set @saikuro to { :output_directory => @scratch_directory + '/saikuro',
|
7
|
+
:input_directory => @code_dirs,
|
8
|
+
:cyclo => '',
|
9
|
+
:filter_cyclo => '0',
|
10
|
+
:warn_cyclo => '5',
|
11
|
+
:error_cyclo => '7',
|
12
|
+
:formater => 'text' }" do
|
13
|
+
load_metric "saikuro"
|
14
|
+
expect(MetricFu::Metric.get_metric(:saikuro).run_options).to eq(
|
15
|
+
output_directory: "#{scratch_directory}/saikuro",
|
16
|
+
input_directory: ["lib"],
|
17
|
+
cyclo: "",
|
18
|
+
filter_cyclo: "0",
|
19
|
+
warn_cyclo: "5",
|
20
|
+
error_cyclo: "7",
|
21
|
+
formater: "text"
|
22
|
+
)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
MetricFu.metrics_require { "saikuro/generator" }
|
3
|
+
|
4
|
+
describe MetricFu::SaikuroGenerator do
|
5
|
+
STUB_TEST_DATA = lambda do |generator|
|
6
|
+
# set test data dir; ensure it doesn't get cleared
|
7
|
+
def generator.metric_directory
|
8
|
+
FIXTURE.fixtures_path.join("saikuro").to_s
|
9
|
+
end
|
10
|
+
def generator.clear_scratch_files!
|
11
|
+
# no-op
|
12
|
+
end
|
13
|
+
end
|
14
|
+
describe "to_h method" do
|
15
|
+
before do
|
16
|
+
options = {}
|
17
|
+
saikuro = MetricFu::SaikuroGenerator.new(options)
|
18
|
+
STUB_TEST_DATA[saikuro]
|
19
|
+
|
20
|
+
saikuro.analyze
|
21
|
+
@output = saikuro.to_h
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should find the filename of a file" do
|
25
|
+
expect(@output[:saikuro][:files].first[:filename]).to eq("app/controllers/users_controller.rb")
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should find the name of the classes" do
|
29
|
+
expect(@output[:saikuro][:classes].first[:name]).to eq("UsersController")
|
30
|
+
expect(@output[:saikuro][:classes][1][:name]).to eq("SessionsController")
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should put the most complex method first" do
|
34
|
+
expect(@output[:saikuro][:methods].first[:name]).to eq("UsersController#create")
|
35
|
+
expect(@output[:saikuro][:methods].first[:complexity]).to eq(4)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should find the complexity of a method" do
|
39
|
+
expect(@output[:saikuro][:methods].first[:complexity]).to eq(4)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should find the lines of a method" do
|
43
|
+
expect(@output[:saikuro][:methods].first[:lines]).to eq(15)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "per_file_info method" do
|
48
|
+
before :all do
|
49
|
+
options = {}
|
50
|
+
@saikuro = MetricFu::SaikuroGenerator.new(options)
|
51
|
+
STUB_TEST_DATA[@saikuro]
|
52
|
+
@saikuro.analyze
|
53
|
+
@output = @saikuro.to_h
|
54
|
+
end
|
55
|
+
|
56
|
+
it "doesn't try to get information if the file does not exist" do
|
57
|
+
expect(@saikuro).to receive(:file_not_exists?).at_least(:once).and_return(true)
|
58
|
+
@saikuro.per_file_info("ignore_me")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe MetricFu::SaikuroScratchFile do
|
63
|
+
describe "getting elements from a Saikuro result file" do
|
64
|
+
it "should parse nested START/END sections" do
|
65
|
+
path = FIXTURE.fixtures_path.join("saikuro_sfiles", "thing.rb_cyclo.html").to_s
|
66
|
+
sfile = MetricFu::SaikuroScratchFile.new path
|
67
|
+
expect(sfile.elements.map(&:complexity).sort).to eql(["0", "0", "2"])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
MetricFu.metrics_require { "stats/generator" }
|
3
|
+
|
4
|
+
describe StatsGenerator do
|
5
|
+
describe "emit method" do
|
6
|
+
it "should gather the raw data" do
|
7
|
+
ENV["CC_BUILD_ARTIFACTS"] = nil
|
8
|
+
MetricFu.configure.reset
|
9
|
+
allow(File).to receive(:directory?).and_return(true)
|
10
|
+
stats = MetricFu::StatsGenerator.new
|
11
|
+
stats.emit
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# TODO review tested output
|
16
|
+
describe "analyze method" do
|
17
|
+
before :each do
|
18
|
+
@lines = <<-HERE.gsub(/^\s*/, "")
|
19
|
+
+----------------------+-------+-------+---------+---------+-----+-------+
|
20
|
+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
|
21
|
+
+----------------------+-------+-------+---------+---------+-----+-------+
|
22
|
+
| Controllers | 470 | 382 | 7 | 53 | 7 | 5 |
|
23
|
+
| Helpers | 128 | 65 | 0 | 6 | 0 | 8 |
|
24
|
+
| Models | 351 | 285 | 9 | 31 | 3 | 7 |
|
25
|
+
| Libraries | 305 | 183 | 2 | 30 | 15 | 4 |
|
26
|
+
| Model specs | 860 | 719 | 0 | 2 | 0 | 357 |
|
27
|
+
| View specs | 0 | 0 | 0 | 0 | 0 | 0 |
|
28
|
+
| Controller specs | 1570 | 1308 | 1 | 10 | 10 | 128 |
|
29
|
+
| Helper specs | 191 | 172 | 0 | 0 | 0 | 0 |
|
30
|
+
| Library specs | 31 | 27 | 0 | 0 | 0 | 0 |
|
31
|
+
+----------------------+-------+-------+---------+---------+-----+-------+
|
32
|
+
| Total | 3906 | 3141 | 19 | 132 | 6 | 21 |
|
33
|
+
+----------------------+-------+-------+---------+---------+-----+-------+
|
34
|
+
Code LOC: 915 Test LOC: 2226 Code to Test Ratio: 1:2.4
|
35
|
+
|
36
|
+
HERE
|
37
|
+
ENV["CC_BUILD_ARTIFACTS"] = nil
|
38
|
+
MetricFu.configure.reset
|
39
|
+
allow(File).to receive(:directory?).and_return(true)
|
40
|
+
stats = MetricFu::StatsGenerator.new
|
41
|
+
stats.instance_variable_set("@output", @lines)
|
42
|
+
@results = stats.analyze
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should get code Lines Of Code" do
|
46
|
+
expect(@results[:codeLOC]).to eq(915)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should get test Lines Of Code" do
|
50
|
+
expect(@results[:testLOC]).to eq(2226)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should get code to test ratio" do
|
54
|
+
expect(@results[:code_to_test_ratio]).to eq(2.4)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should get data on models" do
|
58
|
+
model_data = @results[:lines].find { |line| line[:name] == "Models" }
|
59
|
+
expect(model_data[:classes]).to eq(9)
|
60
|
+
expect(model_data[:methods]).to eq(31)
|
61
|
+
expect(model_data[:loc]).to eq(285)
|
62
|
+
expect(model_data[:lines]).to eq(351)
|
63
|
+
expect(model_data[:methods_per_class]).to eq(3)
|
64
|
+
expect(model_data[:loc_per_method]).to eq(7)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "handles code to test ratio is ratio is 1:NaN" do
|
68
|
+
lines = <<-HERE.gsub(/^\s*/, "")
|
69
|
+
+----------------------+-------+-------+---------+---------+-----+-------+
|
70
|
+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
|
71
|
+
+----------------------+-------+-------+---------+---------+-----+-------+
|
72
|
+
+----------------------+-------+-------+---------+---------+-----+-------+
|
73
|
+
Code LOC: 0 Test LOC: 0 Code to Test Ratio: 1:NaN
|
74
|
+
|
75
|
+
HERE
|
76
|
+
ENV["CC_BUILD_ARTIFACTS"] = nil
|
77
|
+
MetricFu.configure.reset
|
78
|
+
allow(File).to receive(:directory?).and_return(true)
|
79
|
+
stats = MetricFu::StatsGenerator.new(MetricFu::Metric.get_metric(:stats).run_options)
|
80
|
+
stats.instance_variable_set("@output", lines)
|
81
|
+
@results = stats.analyze
|
82
|
+
expect(@results[:code_to_test_ratio]).to eq(0.0)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe "to_h method" do
|
87
|
+
it "should put things into a hash" do
|
88
|
+
ENV["CC_BUILD_ARTIFACTS"] = nil
|
89
|
+
MetricFu.configure.reset
|
90
|
+
allow(File).to receive(:directory?).and_return(true)
|
91
|
+
stats = MetricFu::StatsGenerator.new
|
92
|
+
stats.instance_variable_set(:@stats, "the_stats")
|
93
|
+
expect(stats.to_h[:stats]).to eq("the_stats")
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
MetricFu.metrics_require { "stats/grapher" }
|
3
|
+
|
4
|
+
describe StatsGrapher do
|
5
|
+
before :each do
|
6
|
+
@stats_grapher = MetricFu::StatsGrapher.new
|
7
|
+
MetricFu.configuration
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should respond to loc_counts and lot_counts and labels" do
|
11
|
+
expect(@stats_grapher).to respond_to(:loc_counts)
|
12
|
+
expect(@stats_grapher).to respond_to(:lot_counts)
|
13
|
+
expect(@stats_grapher).to respond_to(:labels)
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "responding to #initialize" do
|
17
|
+
it "should initialise loc_counts and lot_counts and labels" do
|
18
|
+
expect(@stats_grapher.loc_counts).to eq([])
|
19
|
+
expect(@stats_grapher.lot_counts).to eq([])
|
20
|
+
expect(@stats_grapher.labels).to eq({})
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "responding to #get_metrics" do
|
25
|
+
context "when metrics were not generated" do
|
26
|
+
before(:each) do
|
27
|
+
@metrics = FIXTURE.load_metric("metric_missing.yml")
|
28
|
+
@date = "01022003"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should not push to loc_counts" do
|
32
|
+
expect(@stats_grapher.loc_counts).not_to receive(:push)
|
33
|
+
@stats_grapher.get_metrics(@metrics, @date)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should not push to lot_counts" do
|
37
|
+
expect(@stats_grapher.lot_counts).not_to receive(:push)
|
38
|
+
@stats_grapher.get_metrics(@metrics, @date)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should not update labels with the date" do
|
42
|
+
expect(@stats_grapher.labels).not_to receive(:update)
|
43
|
+
@stats_grapher.get_metrics(@metrics, @date)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when metrics have been generated" do
|
48
|
+
before(:each) do
|
49
|
+
@metrics = FIXTURE.load_metric("20090630.yml")
|
50
|
+
@date = "01022003"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should push to loc_counts" do
|
54
|
+
expect(@stats_grapher.loc_counts).to receive(:push).with(15935)
|
55
|
+
@stats_grapher.get_metrics(@metrics, @date)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should push to lot_counts" do
|
59
|
+
expect(@stats_grapher.lot_counts).to receive(:push).with(7438)
|
60
|
+
@stats_grapher.get_metrics(@metrics, @date)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should update labels with the date" do
|
64
|
+
expect(@stats_grapher.labels).to receive(:update).with(0 => "01022003")
|
65
|
+
@stats_grapher.get_metrics(@metrics, @date)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|