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,41 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
MetricFu.lib_require { "reporter" }
|
3
|
+
|
4
|
+
describe MetricFu::Reporter do
|
5
|
+
context "given a single formatter" do
|
6
|
+
before do
|
7
|
+
@formatter = double("formatter")
|
8
|
+
allow(@formatter).to receive(:to_a).and_return([@formatter])
|
9
|
+
@reporter = Reporter.new(@formatter)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "notifies the formatter" do
|
13
|
+
expect(@formatter).to receive(:start)
|
14
|
+
expect(@formatter).to receive(:finish)
|
15
|
+
@reporter.start
|
16
|
+
@reporter.finish
|
17
|
+
end
|
18
|
+
|
19
|
+
it "only sends notifications when supported by formatter" do
|
20
|
+
allow(@formatter).to receive(:respond_to?).with(:display_results).and_return(false)
|
21
|
+
expect(@formatter).not_to receive(:display_results)
|
22
|
+
@reporter.display_results
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "given multiple formatters" do
|
27
|
+
before do
|
28
|
+
@formatters = [double("formatter"), double("formatter")]
|
29
|
+
@reporter = Reporter.new(@formatters)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "notifies all formatters" do
|
33
|
+
@formatters.each do |formatter|
|
34
|
+
expect(formatter).to receive(:start)
|
35
|
+
expect(formatter).to receive(:finish)
|
36
|
+
end
|
37
|
+
@reporter.start
|
38
|
+
@reporter.finish
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
MetricFu.reporting_require { "graphs/graph" }
|
3
|
+
|
4
|
+
describe MetricFu do
|
5
|
+
describe "responding to #graph" do
|
6
|
+
it "should return an instance of Graph" do
|
7
|
+
expect(MetricFu.graph).to be_a(Graph)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe MetricFu::Graph do
|
13
|
+
before(:each) do
|
14
|
+
@graph = MetricFu::Graph.new
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "setting the date on the graph" do
|
18
|
+
# TODO better test
|
19
|
+
it "should set the date once for one data point" do
|
20
|
+
metric_file = "metric_fu/tmp/_data/20101105.yml"
|
21
|
+
expect(MetricFu::Utility).to receive(:glob).and_return([metric_file].sort)
|
22
|
+
expect(MetricFu::Utility).to receive(:load_yaml).with(metric_file).and_return("Metrics")
|
23
|
+
double_grapher = double
|
24
|
+
expect(double_grapher).to receive(:get_metrics).with("Metrics", "11/5")
|
25
|
+
expect(double_grapher).to receive(:graph!)
|
26
|
+
|
27
|
+
@graph.graphers = [double_grapher]
|
28
|
+
@graph.generate
|
29
|
+
end
|
30
|
+
|
31
|
+
# TODO better test
|
32
|
+
it "should set the date when the data directory isn't in the default place" do
|
33
|
+
metric_file = "/some/kind/of/weird/directory/somebody/configured/_data/20101105.yml"
|
34
|
+
expect(MetricFu::Utility).to receive(:glob).and_return([metric_file].sort)
|
35
|
+
expect(MetricFu::Utility).to receive(:load_yaml).with(metric_file).and_return("Metrics")
|
36
|
+
double_grapher = double
|
37
|
+
expect(double_grapher).to receive(:get_metrics).with("Metrics", "11/5")
|
38
|
+
expect(double_grapher).to receive(:graph!)
|
39
|
+
|
40
|
+
@graph.graphers = [double_grapher]
|
41
|
+
@graph.generate
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "Bluff graphers responding to #graph!" do
|
4
|
+
before do
|
5
|
+
setup_fs
|
6
|
+
end
|
7
|
+
after do
|
8
|
+
cleanup_fs
|
9
|
+
end
|
10
|
+
it "should write chart file" do
|
11
|
+
graphs = {}
|
12
|
+
available_graphs = MetricFu::Metric.enabled_metrics.select(&:has_graph?).map(&:name)
|
13
|
+
available_graphs.each do |graph|
|
14
|
+
grapher_name = graph.to_s.gsub("MetricFu::", "").gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
|
15
|
+
grapher_name = grapher_name + "Grapher"
|
16
|
+
graphs[graph] = MetricFu.const_get(grapher_name).new
|
17
|
+
end
|
18
|
+
graphs.each do |key, val|
|
19
|
+
val.graph!
|
20
|
+
output_dir = File.expand_path(File.join(MetricFu::Io::FileSystem.directory("output_directory")))
|
21
|
+
expect { File.read(File.join(output_dir, "#{key.to_s.downcase}.js")) }.not_to raise_error
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
MetricFu.reporting_require { "result" }
|
3
|
+
|
4
|
+
describe MetricFu do
|
5
|
+
describe "#result" do
|
6
|
+
it "should return an instance of Result" do
|
7
|
+
expect(MetricFu.result.instance_of?(Result)).to be(true)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe MetricFu::Result do
|
13
|
+
before(:each) do
|
14
|
+
@result = MetricFu::Result.new
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#as_yaml" do
|
18
|
+
it "should call #result_hash" do
|
19
|
+
result_hash = double("result_hash")
|
20
|
+
expect(result_hash).to receive(:to_yaml)
|
21
|
+
|
22
|
+
expect(@result).to receive(:result_hash).and_return(result_hash)
|
23
|
+
@result.as_yaml
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#result_hash" do
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#add" do
|
31
|
+
it "should add a passed hash to the result_hash instance variable" do
|
32
|
+
result_type = double("result_type")
|
33
|
+
allow(result_type).to receive(:to_s).and_return("type")
|
34
|
+
|
35
|
+
result_inst = double("result_inst")
|
36
|
+
expect(result_type).to receive(:new).and_return(result_inst)
|
37
|
+
|
38
|
+
expect(result_inst).to receive(:generate_result).and_return(a: "b")
|
39
|
+
expect(result_inst).to receive(:respond_to?).and_return(false)
|
40
|
+
|
41
|
+
expect(MetricFu::Generator).to receive(:get_generator).
|
42
|
+
with(result_type).and_return(result_type)
|
43
|
+
result_hash = double("result_hash")
|
44
|
+
expect(result_hash).to receive(:merge!).with(a: "b")
|
45
|
+
expect(@result).to receive(:result_hash).and_return(result_hash)
|
46
|
+
expect(@result).to receive(:metric_options_for_result_type).with(result_type)
|
47
|
+
@result.add(result_type)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,197 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "metric_fu/cli/client"
|
3
|
+
|
4
|
+
describe MetricFu do
|
5
|
+
let(:helper) { MetricFu::Cli::Helper.new }
|
6
|
+
|
7
|
+
before do
|
8
|
+
setup_fs
|
9
|
+
end
|
10
|
+
|
11
|
+
def base_directory
|
12
|
+
directory("base_directory")
|
13
|
+
end
|
14
|
+
|
15
|
+
def output_directory
|
16
|
+
directory("output_directory")
|
17
|
+
end
|
18
|
+
|
19
|
+
def data_directory
|
20
|
+
directory("data_directory")
|
21
|
+
end
|
22
|
+
|
23
|
+
context "given configured metrics, when run" do
|
24
|
+
before do
|
25
|
+
# TODO: Should probably use some sort of fake metric
|
26
|
+
# to speed up tests. For now, just configuring with a
|
27
|
+
# limited set, so we can test the basic functionality
|
28
|
+
# without significantly slowing down the specs.
|
29
|
+
MetricFu.configuration.configure_metrics do |metric|
|
30
|
+
if metric.name == :cane
|
31
|
+
metric.enable
|
32
|
+
metric.activated = true
|
33
|
+
# so this doesn't seem to always be true
|
34
|
+
# @bf4 adding that line you thought I didn't need made tests pass for me
|
35
|
+
# but they failed on one of the travis builds.
|
36
|
+
# swapping this line all seem to pass every run
|
37
|
+
# I don't understand what is happening in run_external well enough
|
38
|
+
# need some help debugging
|
39
|
+
# but tests seem more stable without it.
|
40
|
+
# metric.should_receive(:run_external).and_return('')
|
41
|
+
allow(metric).to receive(:run_external).and_return("")
|
42
|
+
else
|
43
|
+
metric.enabled = false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
it "creates a report yaml file" do
|
49
|
+
expect { metric_fu }.to create_file("#{base_directory}/report.yml")
|
50
|
+
end
|
51
|
+
|
52
|
+
it "creates a data yaml file" do
|
53
|
+
expect { metric_fu }.to create_file("#{data_directory}/#{MetricFu.report_id}.yml")
|
54
|
+
end
|
55
|
+
|
56
|
+
it "creates a report html file" do
|
57
|
+
expect { metric_fu }.to create_file("#{output_directory}/index.html")
|
58
|
+
end
|
59
|
+
|
60
|
+
context "with configured formatter" do
|
61
|
+
it "outputs using configured formatter" do
|
62
|
+
expect {
|
63
|
+
MetricFu::Configuration.run do |config|
|
64
|
+
config.configure_formatter(:yaml)
|
65
|
+
end
|
66
|
+
metric_fu
|
67
|
+
}.to create_file("#{base_directory}/report.yml")
|
68
|
+
end
|
69
|
+
|
70
|
+
it "doesn't output using formatters not configured" do
|
71
|
+
expect {
|
72
|
+
MetricFu::Configuration.run do |config|
|
73
|
+
config.configure_formatter(:yaml)
|
74
|
+
end
|
75
|
+
metric_fu
|
76
|
+
}.to_not create_file("#{output_directory}/index.html")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "with command line formatter" do
|
81
|
+
it "outputs using command line formatter" do
|
82
|
+
expect { metric_fu "--format yaml" }.to create_file("#{base_directory}/report.yml")
|
83
|
+
end
|
84
|
+
|
85
|
+
it "doesn't output using formatters not configured" do
|
86
|
+
expect { metric_fu "--format yaml" }.to_not create_file("#{output_directory}/index.html")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "with configured and command line formatter" do
|
91
|
+
before do
|
92
|
+
MetricFu::Configuration.run do |config|
|
93
|
+
config.configure_formatter(:html)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
it "outputs using command line formatter" do
|
98
|
+
expect { metric_fu "--format yaml" }.to create_file("#{base_directory}/report.yml")
|
99
|
+
end
|
100
|
+
|
101
|
+
it "doesn't output using configured formatter (cli takes precedence)" do
|
102
|
+
expect { metric_fu "--format yaml" }.to_not create_file("#{output_directory}/index.html")
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "with configured specified out" do
|
107
|
+
it "outputs using configured out" do
|
108
|
+
expect {
|
109
|
+
MetricFu::Configuration.run do |config|
|
110
|
+
config.configure_formatter(:yaml, "customreport.yml")
|
111
|
+
end
|
112
|
+
metric_fu
|
113
|
+
}.to create_file("#{base_directory}/customreport.yml")
|
114
|
+
end
|
115
|
+
|
116
|
+
it "doesn't output using formatters not configured" do
|
117
|
+
expect {
|
118
|
+
MetricFu::Configuration.run do |config|
|
119
|
+
config.configure_formatter(:yaml, "customreport.yml")
|
120
|
+
end
|
121
|
+
metric_fu
|
122
|
+
}.to_not create_file("#{base_directory}/report.yml")
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context "with command line specified formatter + out" do
|
127
|
+
it "outputs to the specified path" do
|
128
|
+
expect { metric_fu "--format yaml --out customreport.yml" }.to create_file("#{base_directory}/customreport.yml")
|
129
|
+
end
|
130
|
+
|
131
|
+
it "doesn't output to default path" do
|
132
|
+
expect { metric_fu "--format yaml --out customreport.yml" }.to_not create_file("#{base_directory}/report.yml")
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context "with command line specified out only" do
|
137
|
+
it "outputs to the specified path" do
|
138
|
+
expect { metric_fu "--out customdir --no-open" }.to create_file("#{base_directory}/customdir/index.html")
|
139
|
+
end
|
140
|
+
|
141
|
+
it "doesn't output to default path" do
|
142
|
+
expect { metric_fu "--out customdir --no-open" }.to_not create_file("#{output_directory}/index.html")
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
after do
|
147
|
+
MetricFu::Configuration.run do |config|
|
148
|
+
config.formatters.clear
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context "given other options" do
|
154
|
+
it "displays help" do
|
155
|
+
out = metric_fu "--help"
|
156
|
+
expect(out).to include helper.banner
|
157
|
+
end
|
158
|
+
|
159
|
+
it "displays version" do
|
160
|
+
out = metric_fu "--version"
|
161
|
+
expect(out).to include "#{MetricFu::VERSION}"
|
162
|
+
end
|
163
|
+
|
164
|
+
it "errors on unknown flags" do
|
165
|
+
failure = false
|
166
|
+
out = metric_fu "--asdasdasda" do |_message|
|
167
|
+
# swallow the error message
|
168
|
+
failure = true
|
169
|
+
end
|
170
|
+
expect(out).to include "invalid option"
|
171
|
+
expect(failure).to be_truthy
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
after do
|
176
|
+
cleanup_fs
|
177
|
+
end
|
178
|
+
|
179
|
+
def metric_fu(options = "--no-open")
|
180
|
+
message = ""
|
181
|
+
out = MetricFu::Utility.capture_output {
|
182
|
+
begin
|
183
|
+
argv = Shellwords.shellwords(options)
|
184
|
+
MetricFu::Cli::Client.new.run(argv)
|
185
|
+
# Catch system exit so that it doesn't halt spec.
|
186
|
+
rescue SystemExit => system_exit
|
187
|
+
status = system_exit.success? ? "SUCCESS" : "FAILURE"
|
188
|
+
message << "#{status} with code #{system_exit.status}: "
|
189
|
+
message << "#{system_exit.message} #{system_exit.backtrace}"
|
190
|
+
end
|
191
|
+
}
|
192
|
+
if message.start_with?("FAILURE")
|
193
|
+
block_given? ? yield(message) : STDERR.puts(message)
|
194
|
+
end
|
195
|
+
out
|
196
|
+
end
|
197
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "shared/configured"
|
3
|
+
|
4
|
+
describe MetricFu::Configuration, "for templates" do
|
5
|
+
it_behaves_like "configured" do
|
6
|
+
describe "when there is no CC_BUILD_ARTIFACTS environment variable" do
|
7
|
+
before(:each) do
|
8
|
+
ENV["CC_BUILD_ARTIFACTS"] = nil
|
9
|
+
get_new_config
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should set @template_directory to the lib/templates relative " + "to @metric_fu_root_directory" do
|
13
|
+
expected_template_dir = MetricFu.root.join("lib", "templates").to_s
|
14
|
+
expect(template_directory).to eq(expected_template_dir)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should set @template_class to MetricFu::Templates::MetricsTemplate by default" do
|
18
|
+
expect(template_class).to eq(MetricFu::Templates::MetricsTemplate)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "when a templates configuration is given" do
|
22
|
+
before do
|
23
|
+
class DummyTemplate; end
|
24
|
+
|
25
|
+
@config.templates_configuration do |config|
|
26
|
+
config.template_class = DummyTemplate
|
27
|
+
config.link_prefix = "http:/"
|
28
|
+
config.syntax_highlighting = false
|
29
|
+
config.darwin_txmt_protocol_no_thanks = false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should set given template_class" do
|
34
|
+
expect(template_class).to eq(DummyTemplate)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should set given link_prefix" do
|
38
|
+
expect(MetricFu::Formatter::Templates.option("link_prefix")).to eq("http:/")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should set given darwin_txmt_protocol_no_thanks" do
|
42
|
+
expect(MetricFu::Formatter::Templates.option("darwin_txmt_protocol_no_thanks")).to be_falsey
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should set given syntax_highlighting" do
|
46
|
+
expect(MetricFu::Formatter::Templates.option("syntax_highlighting")).to be_falsey
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe MetricFu::Templates::MetricsTemplate do
|
4
|
+
let(:template) { Templates::MetricsTemplate.new }
|
5
|
+
|
6
|
+
describe "#html_filename" do
|
7
|
+
it "returns the hashed filename ending with .html" do
|
8
|
+
expect(template.html_filename("some_file.rb")).to eq("10580a1fcbe74a931db8210462a584.html")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
MetricFu.lib_require { "templates/report" }
|
3
|
+
|
4
|
+
describe MetricFu::Templates::Report do
|
5
|
+
# TODO: This test only shows how the code works and that it doesn't blow up.
|
6
|
+
# Perhaps it should test something more specific?
|
7
|
+
it "Reads in a source file, and produces an annotated HTML report" do
|
8
|
+
lines = { "2" => [{ type: :reek, description: "Bad Param Names" }] }
|
9
|
+
source_file = File.join(MetricFu.root_dir, "spec", "dummy", "lib", "bad_encoding.rb")
|
10
|
+
report = MetricFu::Templates::Report.new(source_file, lines)
|
11
|
+
expect {
|
12
|
+
rendered_report = report.render
|
13
|
+
}.not_to raise_error
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,233 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "tempfile"
|
3
|
+
require "erb"
|
4
|
+
|
5
|
+
describe MetricFu::Template do
|
6
|
+
before(:each) do
|
7
|
+
@template = Template.new
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#erbify" do
|
11
|
+
it "should evaluate a erb doc" do
|
12
|
+
section = "section"
|
13
|
+
erb = double("erb")
|
14
|
+
expect(erb).to receive(:result)
|
15
|
+
expect(@template).to receive(:template).and_return("foo")
|
16
|
+
expect(@template).to receive(:erb_template_source).with("foo").and_return(erb)
|
17
|
+
@template.send(:erbify, section)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "#template_exists? " do
|
22
|
+
before(:each) do
|
23
|
+
@section = double("section")
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "if the template exists" do
|
27
|
+
it "should return true" do
|
28
|
+
Tempfile.open("file") do |file|
|
29
|
+
expect(@template).to receive(:template).with(@section).and_return(file.path)
|
30
|
+
result = @template.send(:template_exists?, @section)
|
31
|
+
expect(result).to be_truthy
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "if the template does not exist" do
|
37
|
+
it "should return false" do
|
38
|
+
path = "path"
|
39
|
+
expect(@template).to receive(:template).with(@section).and_return(path)
|
40
|
+
result = @template.send(:template_exists?, @section)
|
41
|
+
expect(result).to be_falsey
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#create_instance_var" do
|
47
|
+
it "should set an instance variable with the passed contents" do
|
48
|
+
section = "section"
|
49
|
+
contents = "contents"
|
50
|
+
@template.send(:create_instance_var, section, contents)
|
51
|
+
expect(@template.instance_variable_get(:@section)).to eq(contents)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#template" do
|
56
|
+
it "should generate the filename of the template file" do
|
57
|
+
section = double("section")
|
58
|
+
allow(section).to receive(:to_s).and_return("section")
|
59
|
+
expect(@template).to receive(:template_directory).and_return("dir")
|
60
|
+
result = @template.send(:template, section)
|
61
|
+
expect(result).to eq("dir/section.html.erb")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "#output_filename" do
|
66
|
+
it "should generate the filename of the output file" do
|
67
|
+
section = double("section")
|
68
|
+
expect(section).to receive(:to_s).and_return("section")
|
69
|
+
result = @template.send(:output_filename, section)
|
70
|
+
expect(result).to eq("section.html")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "#inline_css" do
|
75
|
+
it "should return the contents of a css file" do
|
76
|
+
css = "mycss.css"
|
77
|
+
dir = File.join(MetricFu.lib_dir, "templates", css)
|
78
|
+
contents = "css contents"
|
79
|
+
expect(MetricFu::Utility).to receive(:binread).with(dir).and_return(contents)
|
80
|
+
result = @template.send(:inline_css, css)
|
81
|
+
expect(result).to eq(contents)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe "#link_to_filename " do
|
86
|
+
describe "when on OS X" do
|
87
|
+
before(:each) do
|
88
|
+
config = double("configuration")
|
89
|
+
allow(config).to receive(:osx?).and_return(true)
|
90
|
+
allow(config).to receive(:platform).and_return("universal-darwin-9.0")
|
91
|
+
allow(config).to receive(:templates_option).with("darwin_txmt_protocol_no_thanks").and_return(false)
|
92
|
+
allow(config).to receive(:templates_option).with("link_prefix").and_return(nil)
|
93
|
+
allow(MetricFu).to receive(:configuration).and_return(config)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should return a textmate protocol link" do
|
97
|
+
expect(@template).to receive(:complete_file_path).with("filename").and_return("/expanded/filename")
|
98
|
+
result = @template.send(:link_to_filename, "filename")
|
99
|
+
expect(result).to eql("<a href='txmt://open/?url=file://" \
|
100
|
+
+ "/expanded/filename'>filename</a>")
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should do the right thing with a filename that starts with a slash" do
|
104
|
+
expect(@template).to receive(:complete_file_path).with("/filename").and_return("/expanded/filename")
|
105
|
+
result = @template.send(:link_to_filename, "/filename")
|
106
|
+
expect(result).to eql("<a href='txmt://open/?url=file://" \
|
107
|
+
+ "/expanded/filename'>/filename</a>")
|
108
|
+
end
|
109
|
+
|
110
|
+
it "should include a line number" do
|
111
|
+
expect(@template).to receive(:complete_file_path).with("filename").and_return("/expanded/filename")
|
112
|
+
result = @template.send(:link_to_filename, "filename", 6)
|
113
|
+
expect(result).to eql("<a href='txmt://open/?url=file://" \
|
114
|
+
+ "/expanded/filename&line=6'>filename:6</a>")
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "but no thanks for txtmt" do
|
118
|
+
before(:each) do
|
119
|
+
config = double("configuration")
|
120
|
+
allow(config).to receive(:osx?).and_return(true)
|
121
|
+
allow(config).to receive(:platform).and_return("universal-darwin-9.0")
|
122
|
+
allow(config).to receive(:templates_option).with("darwin_txmt_protocol_no_thanks").and_return(true)
|
123
|
+
allow(config).to receive(:templates_option).with("link_prefix").and_return("file:/")
|
124
|
+
allow(MetricFu).to receive(:configuration).and_return(config)
|
125
|
+
expect(@template).to receive(:complete_file_path).and_return("filename")
|
126
|
+
end
|
127
|
+
|
128
|
+
it "should return a file protocol link" do
|
129
|
+
name = "filename"
|
130
|
+
result = @template.send(:link_to_filename, name)
|
131
|
+
expect(result).to eq("<a href='file://filename'>filename</a>")
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
describe "and given link text" do
|
136
|
+
it "should use the submitted link text" do
|
137
|
+
expect(@template).to receive(:complete_file_path).with("filename").and_return("/expanded/filename")
|
138
|
+
result = @template.send(:link_to_filename, "filename", 6, "link content")
|
139
|
+
expect(result).to eql("<a href='txmt://open/?url=file://" \
|
140
|
+
+ "/expanded/filename&line=6'>link content</a>")
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "when on other platforms" do
|
146
|
+
before(:each) do
|
147
|
+
config = double("configuration")
|
148
|
+
expect(config).to receive(:osx?).and_return(false)
|
149
|
+
allow(config).to receive(:templates_option).with("link_prefix").and_return("file:/")
|
150
|
+
allow(MetricFu).to receive(:configuration).and_return(config)
|
151
|
+
expect(@template).to receive(:complete_file_path).and_return("filename")
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should return a file protocol link" do
|
155
|
+
name = "filename"
|
156
|
+
result = @template.send(:link_to_filename, name)
|
157
|
+
expect(result).to eq("<a href='file://filename'>filename</a>")
|
158
|
+
end
|
159
|
+
end
|
160
|
+
describe "when configured with a link_prefix" do
|
161
|
+
before(:each) do
|
162
|
+
config = double("configuration")
|
163
|
+
allow(config).to receive(:templates_option).with("darwin_txmt_protocol_no_thanks").and_return(true)
|
164
|
+
allow(config).to receive(:templates_option).with("link_prefix").and_return("http://example.org/files")
|
165
|
+
allow(config).to receive(:osx?).and_return(true)
|
166
|
+
allow(MetricFu).to receive(:configuration).and_return(config)
|
167
|
+
expect(@template).to receive(:complete_file_path).and_return("filename")
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should return a http protocol link" do
|
171
|
+
name = "filename"
|
172
|
+
result = @template.send(:link_to_filename, name)
|
173
|
+
expect(result).to eq("<a href='http://example.org/files/filename'>filename</a>")
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
context "given an absolute path" do
|
178
|
+
it "returns a link with that absolute path" do
|
179
|
+
name = "/some/file.rb"
|
180
|
+
result = @template.send(:link_to_filename, name)
|
181
|
+
expect(result).to match("<a href='file://(.:)?/some/file.rb'>/some/file.rb</a>")
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
context "given a relative path" do
|
186
|
+
it "returns a link with the absolute path" do
|
187
|
+
name = "./some/file.rb"
|
188
|
+
expected = File.expand_path(name)
|
189
|
+
result = @template.send(:link_to_filename, name)
|
190
|
+
expect(result).to eq("<a href='file://#{expected}'>./some/file.rb</a>")
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe "#cycle" do
|
196
|
+
it "should return the first_value passed if iteration passed is even" do
|
197
|
+
first_val = "first"
|
198
|
+
second_val = "second"
|
199
|
+
iter = 2
|
200
|
+
result = @template.send(:cycle, first_val, second_val, iter)
|
201
|
+
expect(result).to eq(first_val)
|
202
|
+
end
|
203
|
+
|
204
|
+
it "should return the second_value passed if iteration passed is odd" do
|
205
|
+
first_val = "first"
|
206
|
+
second_val = "second"
|
207
|
+
iter = 1
|
208
|
+
result = @template.send(:cycle, first_val, second_val, iter)
|
209
|
+
expect(result).to eq(second_val)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
describe "#render_partial" do
|
214
|
+
it "should erbify a partial with the name prefixed with an underscore" do
|
215
|
+
expect(@template).to receive(:erbify).with("_some_partial")
|
216
|
+
@template.send(:render_partial, "some_partial")
|
217
|
+
end
|
218
|
+
|
219
|
+
it "should set the given instance variables" do
|
220
|
+
variables = { answer: 42 }
|
221
|
+
allow(@template).to receive(:erbify)
|
222
|
+
expect(@template).to receive(:create_instance_vars).with(variables)
|
223
|
+
@template.send(:render_partial, "some_partial", variables)
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
describe "#create_instance_vars" do
|
228
|
+
it "should set the given instance variables" do
|
229
|
+
@template.send(:create_instance_vars, answer: 42)
|
230
|
+
expect(@template.instance_variable_get(:@answer)).to eq(42)
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "metric_fu/utility"
|
3
|
+
|
4
|
+
describe MetricFu::Utility do
|
5
|
+
it "strips ANSI escape codes from text" do
|
6
|
+
text = "\e[31m./app/models/account.rb:64 - Found = in conditional. It should probably be an ==\e[0m"
|
7
|
+
output = "./app/models/account.rb:64 - Found = in conditional. It should probably be an =="
|
8
|
+
|
9
|
+
result = MetricFu::Utility.strip_escape_codes(text)
|
10
|
+
expect(result).to eq(output)
|
11
|
+
end
|
12
|
+
end
|