metric_fu 4.6.0 → 4.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data.tar.gz.sig +0 -0
  2. data/.metrics +6 -0
  3. data/.travis.yml +6 -5
  4. data/CONTRIBUTING.md +15 -3
  5. data/Gemfile +3 -8
  6. data/Gemfile.devtools +3 -3
  7. data/HISTORY.md +23 -2
  8. data/README.md +42 -38
  9. data/checksum/metric_fu-4.6.0.gem.sha512 +1 -0
  10. data/gemfiles/Gemfile.travis +7 -0
  11. data/lib/metric_fu/cli/helper.rb +2 -1
  12. data/lib/metric_fu/configuration.rb +0 -2
  13. data/lib/metric_fu/formatter/html.rb +2 -0
  14. data/lib/metric_fu/formatter/syntax.rb +47 -0
  15. data/lib/metric_fu/gem_version.rb +44 -11
  16. data/lib/metric_fu/io.rb +5 -5
  17. data/lib/metric_fu/loader.rb +12 -5
  18. data/lib/metric_fu/metric.rb +10 -0
  19. data/lib/metric_fu/metrics/base_template.rb +2 -2
  20. data/lib/metric_fu/metrics/cane/cane.rb +1 -0
  21. data/lib/metric_fu/metrics/churn/churn.rb +16 -42
  22. data/lib/metric_fu/metrics/churn/init.rb +7 -1
  23. data/lib/metric_fu/metrics/hotspots/analysis/groupings.rb +1 -0
  24. data/lib/metric_fu/metrics/hotspots/analysis/problems.rb +1 -0
  25. data/lib/metric_fu/metrics/hotspots/analysis/ranked_problem_location.rb +2 -0
  26. data/lib/metric_fu/metrics/hotspots/analysis/rankings.rb +5 -0
  27. data/lib/metric_fu/metrics/hotspots/hotspot.rb +3 -0
  28. data/lib/metric_fu/metrics/hotspots/hotspot_analyzer.rb +8 -4
  29. data/lib/metric_fu/metrics/hotspots/hotspots.rb +11 -0
  30. data/lib/metric_fu/metrics/reek/reek.rb +1 -1
  31. data/lib/metric_fu/metrics/reek/reek_hotspot.rb +0 -1
  32. data/lib/metric_fu/metrics/saikuro/saikuro.rb +1 -0
  33. data/lib/metric_fu/reporting/graphs/grapher.rb +0 -1
  34. data/lib/metric_fu/reporting/templates/awesome/awesome_template.rb +8 -59
  35. data/lib/metric_fu/run.rb +1 -1
  36. data/lib/metric_fu/{reporting/templates/awesome → templates}/css/bluff.css +0 -0
  37. data/lib/metric_fu/{reporting/templates/awesome → templates}/css/buttons.css +0 -0
  38. data/lib/metric_fu/{reporting/templates/awesome → templates}/css/default.css +0 -0
  39. data/lib/metric_fu/{reporting/templates/awesome → templates}/css/integrity.css +0 -0
  40. data/lib/metric_fu/{reporting/templates/awesome → templates}/css/rcov.css +0 -0
  41. data/lib/metric_fu/{reporting/templates/awesome → templates}/css/reset.css +0 -0
  42. data/lib/metric_fu/{reporting/templates/awesome → templates}/css/syntax.css +0 -0
  43. data/lib/metric_fu/templates/report.html.erb +32 -0
  44. data/lib/metric_fu/templates/report.rb +36 -0
  45. data/lib/metric_fu/utility.rb +4 -0
  46. data/lib/metric_fu/version.rb +1 -1
  47. data/metric_fu.gemspec +11 -2
  48. data/spec/cli/helper_spec.rb +33 -33
  49. data/spec/metric_fu/configuration_spec.rb +20 -20
  50. data/spec/metric_fu/data_structures/line_numbers_spec.rb +12 -11
  51. data/spec/metric_fu/data_structures/location_spec.rb +27 -26
  52. data/spec/metric_fu/formatter/html_spec.rb +18 -8
  53. data/spec/metric_fu/formatter/yaml_spec.rb +14 -3
  54. data/spec/metric_fu/formatter_spec.rb +5 -5
  55. data/spec/metric_fu/loader_spec.rb +1 -1
  56. data/spec/metric_fu/metric_spec.rb +2 -2
  57. data/spec/metric_fu/metrics/base_template_spec.rb +50 -50
  58. data/spec/metric_fu/metrics/cane/cane_spec.rb +29 -28
  59. data/spec/metric_fu/metrics/churn/churn_spec.rb +10 -33
  60. data/spec/metric_fu/metrics/flay/flay_grapher_spec.rb +9 -8
  61. data/spec/metric_fu/metrics/flay/flay_spec.rb +14 -13
  62. data/spec/metric_fu/metrics/flog/flog_grapher_spec.rb +16 -15
  63. data/spec/metric_fu/metrics/flog/flog_spec.rb +10 -9
  64. data/spec/metric_fu/metrics/generator_spec.rb +19 -19
  65. data/spec/metric_fu/metrics/graph_spec.rb +11 -9
  66. data/spec/metric_fu/metrics/hotspots/analysis/analyzed_problems_spec.rb +5 -0
  67. data/spec/metric_fu/metrics/hotspots/analysis/analyzer_tables_spec.rb +11 -6
  68. data/spec/metric_fu/metrics/hotspots/analysis/ranking_spec.rb +4 -3
  69. data/spec/metric_fu/metrics/hotspots/analysis/rankings_spec.rb +16 -10
  70. data/spec/metric_fu/metrics/hotspots/analysis/table_spec.rb +2 -1
  71. data/spec/metric_fu/metrics/hotspots/hotspot_analyzer_spec.rb +2 -1
  72. data/spec/metric_fu/metrics/hotspots/hotspot_spec.rb +8 -2
  73. data/spec/metric_fu/metrics/hotspots/hotspots_spec.rb +4 -8
  74. data/spec/metric_fu/metrics/rails_best_practices/rails_best_practices_grapher_spec.rb +10 -9
  75. data/spec/metric_fu/metrics/rails_best_practices/rails_best_practices_spec.rb +8 -7
  76. data/spec/metric_fu/metrics/rcov/rcov_grapher_spec.rb +8 -8
  77. data/spec/metric_fu/metrics/rcov/rcov_hotspot_spec.rb +7 -4
  78. data/spec/metric_fu/metrics/rcov/rcov_spec.rb +15 -14
  79. data/spec/metric_fu/metrics/reek/reek_grapher_spec.rb +10 -9
  80. data/spec/metric_fu/metrics/reek/reek_spec.rb +17 -15
  81. data/spec/metric_fu/metrics/roodi/roodi_grapher_spec.rb +9 -8
  82. data/spec/metric_fu/metrics/roodi/roodi_spec.rb +4 -3
  83. data/spec/metric_fu/metrics/saikuro/saikuro_spec.rb +13 -10
  84. data/spec/metric_fu/metrics/stats/stats_grapher_spec.rb +13 -12
  85. data/spec/metric_fu/metrics/stats/stats_spec.rb +16 -14
  86. data/spec/metric_fu/reporter_spec.rb +8 -7
  87. data/spec/metric_fu/reporting/graphs/grapher_spec.rb +1 -1
  88. data/spec/metric_fu/reporting/result_spec.rb +12 -11
  89. data/spec/metric_fu/run_spec.rb +24 -8
  90. data/spec/spec_helper.rb +1 -2
  91. data/spec/support/helper_methods.rb +14 -1
  92. metadata +124 -57
  93. metadata.gz.sig +0 -0
  94. checksums.yaml +0 -7
  95. checksums.yaml.gz.sig +0 -0
  96. data/lib/metric_fu/initial_requires.rb +0 -13
  97. data/lib/metric_fu/load_files.rb +0 -34
@@ -1,4 +1,5 @@
1
1
  require 'spec_helper'
2
+ MetricFu.metrics_require { 'cane/cane' }
2
3
 
3
4
  describe CaneGenerator do
4
5
  describe "emit method" do
@@ -6,49 +7,49 @@ describe CaneGenerator do
6
7
  it "should execute cane command" do
7
8
  options = {}
8
9
  @cane = MetricFu::CaneGenerator.new(options)
9
- @cane.should_receive(:run!).with("")
10
+ expect(@cane).to receive(:run!).with("")
10
11
  output = @cane.emit
11
12
  end
12
13
 
13
14
  it "should use abc max option" do
14
15
  options = {abc_max: 20}
15
16
  @cane = MetricFu::CaneGenerator.new(options)
16
- @cane.should_receive(:run!).with(" --abc-max 20")
17
+ expect(@cane).to receive(:run!).with(" --abc-max 20")
17
18
  output = @cane.emit
18
19
  end
19
20
 
20
21
  it "should use style max line length option" do
21
22
  options = {line_length: 100}
22
23
  @cane = MetricFu::CaneGenerator.new(options)
23
- @cane.should_receive(:run!).with(" --style-measure 100")
24
+ expect(@cane).to receive(:run!).with(" --style-measure 100")
24
25
  output = @cane.emit
25
26
  end
26
27
 
27
28
  it "should use no-doc if specified" do
28
29
  options = {no_doc: 'y'}
29
30
  @cane = MetricFu::CaneGenerator.new(options)
30
- @cane.should_receive(:run!).with(" --no-doc")
31
+ expect(@cane).to receive(:run!).with(" --no-doc")
31
32
  output = @cane.emit
32
33
  end
33
34
 
34
35
  it "should include doc violations if no_doc != 'y'" do
35
36
  options = {no_doc: 'n'}
36
37
  @cane = MetricFu::CaneGenerator.new(options)
37
- @cane.should_receive(:run!).with("")
38
+ expect(@cane).to receive(:run!).with("")
38
39
  output = @cane.emit
39
40
  end
40
41
 
41
42
  it "should use no-readme if specified" do
42
43
  options = {no_readme: 'y'}
43
44
  @cane = MetricFu::CaneGenerator.new(options)
44
- @cane.should_receive(:run!).with(" --no-readme")
45
+ expect(@cane).to receive(:run!).with(" --no-readme")
45
46
  output = @cane.emit
46
47
  end
47
48
 
48
49
  it "should include README violations if no_readme != 'y'" do
49
50
  options = {no_readme: 'n'}
50
51
  @cane = MetricFu::CaneGenerator.new(options)
51
- @cane.should_receive(:run!).with("")
52
+ expect(@cane).to receive(:run!).with("")
52
53
  output = @cane.emit
53
54
  end
54
55
  end
@@ -56,7 +57,7 @@ describe CaneGenerator do
56
57
  describe "parse cane empty output" do
57
58
  before :each do
58
59
  # MetricFu::Configuration.run {}
59
- File.stub(:directory?).and_return(true)
60
+ allow(File).to receive(:directory?).and_return(true)
60
61
  options = {}
61
62
  @cane = MetricFu::CaneGenerator.new(options)
62
63
  @cane.instance_variable_set(:@output, '')
@@ -66,7 +67,7 @@ describe CaneGenerator do
66
67
 
67
68
  it "should find total violations" do
68
69
  @cane.analyze
69
- @cane.total_violations.should == 0
70
+ expect(@cane.total_violations).to eq(0)
70
71
  end
71
72
  end
72
73
  end
@@ -75,7 +76,7 @@ describe CaneGenerator do
75
76
  before :each do
76
77
  lines = sample_cane_output
77
78
  MetricFu::Configuration.run {}
78
- File.stub(:directory?).and_return(true)
79
+ allow(File).to receive(:directory?).and_return(true)
79
80
  @cane = MetricFu::CaneGenerator.new('base_dir')
80
81
  @cane.instance_variable_set(:@output, lines)
81
82
  end
@@ -84,69 +85,69 @@ describe CaneGenerator do
84
85
 
85
86
  it "should find total violations" do
86
87
  @cane.analyze
87
- @cane.total_violations.should == 6
88
+ expect(@cane.total_violations).to eq(6)
88
89
  end
89
90
 
90
91
  it "should extract abc complexity violations" do
91
92
  @cane.analyze
92
- @cane.violations[:abc_complexity].should == [
93
+ expect(@cane.violations[:abc_complexity]).to eq([
93
94
  {file: 'lib/abc/foo.rb', method: 'Abc::Foo#method', complexity: '11'},
94
95
  {file: 'lib/abc/bar.rb', method: 'Abc::Bar#method', complexity: '22'}
95
- ]
96
+ ])
96
97
  end
97
98
 
98
99
  it "should extract line style violations" do
99
100
  @cane.analyze
100
- @cane.violations[:line_style].should == [
101
+ expect(@cane.violations[:line_style]).to eq([
101
102
  {line: 'lib/line/foo.rb:1', description: 'Line is >80 characters (135)'},
102
103
  {line: 'lib/line/bar.rb:2', description: 'Line contains trailing whitespace'}
103
- ]
104
+ ])
104
105
  end
105
106
 
106
107
  it "should extract comment violations" do
107
108
  @cane.analyze
108
- @cane.violations[:comment].should == [
109
+ expect(@cane.violations[:comment]).to eq([
109
110
  {line: 'lib/comments/foo.rb:1', class_name: 'Foo'},
110
111
  {line: 'lib/comments/bar.rb:2', class_name: 'Bar'}
111
- ]
112
+ ])
112
113
  end
113
114
 
114
115
  it "should extract no readme violations if present" do
115
116
  @cane.analyze
116
- @cane.violations[:documentation].should == [
117
+ expect(@cane.violations[:documentation]).to eq([
117
118
  {description: 'No README found'},
118
- ]
119
+ ])
119
120
  end
120
121
 
121
122
  it "should extract unknown violations in others category" do
122
123
  @cane.analyze
123
- @cane.violations[:others].should == [
124
+ expect(@cane.violations[:others]).to eq([
124
125
  {description: 'Misc issue 1'},
125
126
  {description: 'Misc issue 2'}
126
- ]
127
+ ])
127
128
  end
128
129
  end
129
130
 
130
131
  describe "to_h method" do
131
132
  it "should have total violations" do
132
133
  @cane.analyze
133
- @cane.to_h[:cane][:total_violations].should == 6
134
+ expect(@cane.to_h[:cane][:total_violations]).to eq(6)
134
135
  end
135
136
 
136
137
  it "should have violations by category" do
137
138
  @cane.analyze
138
- @cane.to_h[:cane][:violations][:abc_complexity].should == [
139
+ expect(@cane.to_h[:cane][:violations][:abc_complexity]).to eq([
139
140
  {file: 'lib/abc/foo.rb', method: 'Abc::Foo#method', complexity: '11'},
140
141
  {file: 'lib/abc/bar.rb', method: 'Abc::Bar#method', complexity: '22'}
141
- ]
142
- @cane.to_h[:cane][:violations][:line_style].should == [
142
+ ])
143
+ expect(@cane.to_h[:cane][:violations][:line_style]).to eq([
143
144
  {line: 'lib/line/foo.rb:1', description: 'Line is >80 characters (135)'},
144
145
  {line: 'lib/line/bar.rb:2', description: 'Line contains trailing whitespace'}
145
- ]
146
- @cane.to_h[:cane][:violations][:comment].should == [
146
+ ])
147
+ expect(@cane.to_h[:cane][:violations][:comment]).to eq([
147
148
  {line: 'lib/comments/foo.rb:1', class_name: 'Foo'},
148
149
  {line: 'lib/comments/bar.rb:2', class_name: 'Bar'}
149
- ]
150
+ ])
150
151
  end
151
152
  end
152
153
  end
@@ -1,57 +1,34 @@
1
1
  require "spec_helper"
2
+ MetricFu.metrics_require { 'churn/churn' }
2
3
 
3
4
  describe MetricFu::ChurnGenerator do
4
5
 
5
6
  # TODO extract yaml
6
- let(:churn_yaml) { "--- \n:churn: \n :changed_files: \n - spec/graphs/flog_grapher_spec.rb\n - spec/base/graph_spec.rb\n - lib/templates/awesome/layout.html.erb\n - lib/graphs/rcov_grapher.rb\n - lib/base/base_template.rb\n - spec/graphs/grapher_spec.rb\n - lib/templates/awesome/flog.html.erb\n - lib/templates/awesome/flay.html.erb\n - lib/graphs/roodi_grapher.rb\n - lib/graphs/reek_grapher.rb\n - HISTORY\n - spec/graphs/roodi_grapher_spec.rb\n - lib/generators/rcov.rb\n - spec/graphs/engines/gchart_spec.rb\n - spec/graphs/rcov_grapher_spec.rb\n - lib/templates/javascripts/excanvas.js\n - lib/templates/javascripts/bluff-min.js\n - spec/graphs/reek_grapher_spec.rb\n" }
7
+ let(:churn_hash) { YAML::load("--- \n:churn: \n :changed_files: \n - spec/graphs/flog_grapher_spec.rb\n - spec/base/graph_spec.rb\n - lib/templates/awesome/layout.html.erb\n - lib/graphs/rcov_grapher.rb\n - lib/base/base_template.rb\n - spec/graphs/grapher_spec.rb\n - lib/templates/awesome/flog.html.erb\n - lib/templates/awesome/flay.html.erb\n - lib/graphs/roodi_grapher.rb\n - lib/graphs/reek_grapher.rb\n - HISTORY\n - spec/graphs/roodi_grapher_spec.rb\n - lib/generators/rcov.rb\n - spec/graphs/engines/gchart_spec.rb\n - spec/graphs/rcov_grapher_spec.rb\n - lib/templates/javascripts/excanvas.js\n - lib/templates/javascripts/bluff-min.js\n - spec/graphs/reek_grapher_spec.rb\n") }
7
8
 
8
9
  let(:config_setup) {
9
10
  ENV['CC_BUILD_ARTIFACTS'] = nil
10
11
  MetricFu.configure.reset
11
12
  }
12
13
 
13
- describe "new method" do
14
- before :each do
15
- config_setup
16
- end
17
-
18
- it "initializes with yaml option" do
19
- churn = MetricFu::ChurnGenerator.new
20
- churn.send(:build_churn_options).should == "--yaml"
21
- end
22
-
23
- it "initializes with given minimum_churn_count option" do
24
- churn = MetricFu::ChurnGenerator.new( { :minimum_churn_count => 5 })
25
- churn.send(:build_churn_options).should == "--yaml --minimum_churn_count=5"
26
- end
27
- end
28
-
29
-
30
14
  describe "analyze method" do
31
15
  before :each do
32
16
  config_setup
33
17
  @changes = {"lib/generators/flog.rb" => 2, "lib/metric_fu.rb" => 3}
34
18
  end
35
19
 
36
- it "should be empty on error text" do
37
- churn = MetricFu::ChurnGenerator.new
38
- churn.instance_variable_set(:@output, "Churning requires a subversion or git repo")
39
- result = churn.analyze
40
- result.should == {:churn => {}}
41
- end
42
-
43
20
  it "should be empty on error no output captured" do
44
21
  churn = MetricFu::ChurnGenerator.new
45
22
  churn.instance_variable_set(:@output, nil)
46
23
  result = churn.analyze
47
- result.should == {:churn => {}}
24
+ expect(result).to eq({:churn => {}})
48
25
  end
49
26
 
50
27
  it "should return yaml results" do
51
28
  churn = MetricFu::ChurnGenerator.new
52
- churn.instance_variable_set(:@output, churn_yaml)
29
+ churn.instance_variable_set(:@output, churn_hash)
53
30
  result = churn.analyze
54
- result.should == {:churn => {:changed_files => ["spec/graphs/flog_grapher_spec.rb", "spec/base/graph_spec.rb", "lib/templates/awesome/layout.html.erb", "lib/graphs/rcov_grapher.rb", "lib/base/base_template.rb", "spec/graphs/grapher_spec.rb", "lib/templates/awesome/flog.html.erb", "lib/templates/awesome/flay.html.erb", "lib/graphs/roodi_grapher.rb", "lib/graphs/reek_grapher.rb", "HISTORY", "spec/graphs/roodi_grapher_spec.rb", "lib/generators/rcov.rb", "spec/graphs/engines/gchart_spec.rb", "spec/graphs/rcov_grapher_spec.rb", "lib/templates/javascripts/excanvas.js", "lib/templates/javascripts/bluff-min.js", "spec/graphs/reek_grapher_spec.rb"]}}
31
+ expect(result).to eq({:churn => {:changed_files => ["spec/graphs/flog_grapher_spec.rb", "spec/base/graph_spec.rb", "lib/templates/awesome/layout.html.erb", "lib/graphs/rcov_grapher.rb", "lib/base/base_template.rb", "spec/graphs/grapher_spec.rb", "lib/templates/awesome/flog.html.erb", "lib/templates/awesome/flay.html.erb", "lib/graphs/roodi_grapher.rb", "lib/graphs/reek_grapher.rb", "HISTORY", "spec/graphs/roodi_grapher_spec.rb", "lib/generators/rcov.rb", "spec/graphs/engines/gchart_spec.rb", "spec/graphs/rcov_grapher_spec.rb", "lib/templates/javascripts/excanvas.js", "lib/templates/javascripts/bluff-min.js", "spec/graphs/reek_grapher_spec.rb"]}})
55
32
  end
56
33
 
57
34
  end
@@ -65,7 +42,7 @@ describe MetricFu::ChurnGenerator do
65
42
  it "should put the changes into a hash" do
66
43
  churn = MetricFu::ChurnGenerator.new
67
44
  churn.instance_variable_set(:@churn, {:churn => 'results'})
68
- churn.to_h[:churn].should == "results"
45
+ expect(churn.to_h[:churn]).to eq("results")
69
46
  end
70
47
  end
71
48
 
@@ -77,15 +54,15 @@ describe MetricFu::ChurnGenerator do
77
54
  end
78
55
 
79
56
  it "returns churn output" do
80
- @churn.stub(:churn_code).and_return(" master\n#{churn_yaml}")
57
+ allow(@churn).to receive(:run).and_return(churn_hash)
81
58
  result = @churn.emit
82
- result.should == churn_yaml
59
+ expect(result).to eq(churn_hash)
83
60
  end
84
61
 
85
62
  it "returns nil, when churn result is not yaml" do
86
- @churn.stub(:churn_code).and_return(" master\n")
63
+ allow(@churn).to receive(:run).and_return(nil)
87
64
  result = @churn.emit
88
- result.should be nil
65
+ expect(result).to be nil
89
66
  end
90
67
  end
91
68
  end
@@ -1,4 +1,5 @@
1
1
  require "spec_helper"
2
+ MetricFu.metrics_require { 'flay/flay_grapher' }
2
3
 
3
4
  describe FlayGrapher do
4
5
  before :each do
@@ -7,14 +8,14 @@ describe FlayGrapher do
7
8
  end
8
9
 
9
10
  it "should respond to flay_score and labels" do
10
- @flay_grapher.should respond_to(:flay_score)
11
- @flay_grapher.should respond_to(:labels)
11
+ expect(@flay_grapher).to respond_to(:flay_score)
12
+ expect(@flay_grapher).to respond_to(:labels)
12
13
  end
13
14
 
14
15
  describe "responding to #initialize" do
15
16
  it "should initialise flay_score and labels" do
16
- @flay_grapher.flay_score.should == []
17
- @flay_grapher.labels.should == {}
17
+ expect(@flay_grapher.flay_score).to eq([])
18
+ expect(@flay_grapher.labels).to eq({})
18
19
  end
19
20
  end
20
21
 
@@ -26,12 +27,12 @@ describe FlayGrapher do
26
27
  end
27
28
 
28
29
  it "should not push to flay_score" do
29
- @flay_grapher.flay_score.should_not_receive(:push)
30
+ expect(@flay_grapher.flay_score).not_to receive(:push)
30
31
  @flay_grapher.get_metrics(@metrics, @date)
31
32
  end
32
33
 
33
34
  it "should not update labels with the date" do
34
- @flay_grapher.labels.should_not_receive(:update)
35
+ expect(@flay_grapher.labels).not_to receive(:update)
35
36
  @flay_grapher.get_metrics(@metrics, @date)
36
37
  end
37
38
  end
@@ -43,12 +44,12 @@ describe FlayGrapher do
43
44
  end
44
45
 
45
46
  it "should push to flay_score" do
46
- @flay_grapher.flay_score.should_receive(:push).with(476)
47
+ expect(@flay_grapher.flay_score).to receive(:push).with(476)
47
48
  @flay_grapher.get_metrics(@metrics, @date)
48
49
  end
49
50
 
50
51
  it "should update labels with the date" do
51
- @flay_grapher.labels.should_receive(:update).with({ 0 => "1/2" })
52
+ expect(@flay_grapher.labels).to receive(:update).with({ 0 => "1/2" })
52
53
  @flay_grapher.get_metrics(@metrics, @date)
53
54
  end
54
55
  end
@@ -1,22 +1,23 @@
1
1
  require "spec_helper"
2
+ MetricFu.metrics_require { 'flay/flay' }
2
3
 
3
4
  describe MetricFu::FlayGenerator do
4
5
  describe "emit method" do
5
6
  it "should look at the dirs" do
6
7
  options = { :dirs_to_flay => ['app', 'lib'], :filetypes => ['rb'] }
7
- File.stub(:directory?).and_return(true)
8
+ allow(File).to receive(:directory?).and_return(true)
8
9
  @flay = MetricFu::FlayGenerator.new(options)
9
10
 
10
- @flay.should_receive(:run!).with(" app lib")
11
+ expect(@flay).to receive(:run!).with(" app lib")
11
12
  output = @flay.emit
12
13
  end
13
14
 
14
15
  it "should limit flay scores by the minimum_score" do
15
16
  options = { :dirs_to_flay => [], :minimum_score => 99 }
16
- File.stub(:directory?).and_return(true)
17
+ allow(File).to receive(:directory?).and_return(true)
17
18
  @flay = MetricFu::FlayGenerator.new(options)
18
19
 
19
- @flay.should_receive(:run!).with("--mass 99 ")
20
+ expect(@flay).to receive(:run!).with("--mass 99 ")
20
21
  output = @flay.emit
21
22
  end
22
23
  end
@@ -38,13 +39,13 @@ Total score (lower is better) = 246
38
39
  app/controllers/primary_sites_controller.rb:89
39
40
  HERE
40
41
  MetricFu::Configuration.run {}
41
- File.stub(:directory?).and_return(true)
42
+ allow(File).to receive(:directory?).and_return(true)
42
43
  @flay = MetricFu::FlayGenerator.new('base_dir')
43
44
  @flay.instance_variable_set(:@output, lines)
44
45
  end
45
46
 
46
47
  it "should analyze and return matches" do
47
- @flay.analyze.should == [ ["Total score (lower is better) = 246"],
48
+ expect(@flay.analyze).to eq([ ["Total score (lower is better) = 246"],
48
49
  ["\n1) IDENTICAL code found in :or (mass*2 = 68)",
49
50
  "app/controllers/link_targets_controller.rb:57",
50
51
  "app/controllers/primary_sites_controller.rb:138"],
@@ -52,7 +53,7 @@ Total score (lower is better) = 246
52
53
  "app/controllers/primary_sites_controller.rb:75",
53
54
  "app/controllers/primary_sites_controller.rb:76",
54
55
  "app/controllers/primary_sites_controller.rb:88",
55
- "app/controllers/primary_sites_controller.rb:89"] ]
56
+ "app/controllers/primary_sites_controller.rb:89"] ])
56
57
  end
57
58
  end
58
59
 
@@ -82,24 +83,24 @@ Total score (lower is better) = 246
82
83
  "app/controllers/bookmarklet_integration_controller.rb:17"]]
83
84
 
84
85
  MetricFu::Configuration.run {}
85
- File.stub(:directory?).and_return(true)
86
+ allow(File).to receive(:directory?).and_return(true)
86
87
  flay = MetricFu::FlayGenerator.new('base_dir')
87
88
  flay.instance_variable_set(:@matches, lines)
88
89
  @results = flay.to_h
89
90
  end
90
91
 
91
92
  it "should find the total_score" do
92
- @results[:flay][:total_score].should == '284'
93
+ expect(@results[:flay][:total_score]).to eq('284')
93
94
  end
94
95
 
95
96
  it "should have 6 matches" do
96
- @results[:flay][:matches].size.should == 6
97
+ expect(@results[:flay][:matches].size).to eq(6)
97
98
  end
98
99
 
99
100
  it "should capture info for match" do
100
- @results[:flay][:matches].first[:reason].should =~ /IDENTICAL/
101
- @results[:flay][:matches].first[:matches].first[:name].should =~ /link_targets_controller/
102
- @results[:flay][:matches].first[:matches].first[:line].should == "57"
101
+ expect(@results[:flay][:matches].first[:reason]).to match(/IDENTICAL/)
102
+ expect(@results[:flay][:matches].first[:matches].first[:name]).to match(/link_targets_controller/)
103
+ expect(@results[:flay][:matches].first[:matches].first[:line]).to eq("57")
103
104
  end
104
105
  end
105
106
  end
@@ -1,4 +1,5 @@
1
1
  require "spec_helper"
2
+ MetricFu.metrics_require { 'flog/flog_grapher' }
2
3
 
3
4
  describe MetricFu::FlogGrapher do
4
5
  before :each do
@@ -8,16 +9,16 @@ describe MetricFu::FlogGrapher do
8
9
  end
9
10
 
10
11
  it "should respond to flog_total, flog_average and labels" do
11
- @flog_grapher.should respond_to(:flog_average)
12
- @flog_grapher.should respond_to(:labels)
13
- @flog_grapher.should respond_to(:top_five_percent_average)
12
+ expect(@flog_grapher).to respond_to(:flog_average)
13
+ expect(@flog_grapher).to respond_to(:labels)
14
+ expect(@flog_grapher).to respond_to(:top_five_percent_average)
14
15
  end
15
16
 
16
17
  describe "responding to #initialize" do
17
18
  it "should initialize top_five_percent_average, flog_average and labels" do
18
- @flog_grapher.flog_average.should == []
19
- @flog_grapher.labels.should == {}
20
- @flog_grapher.top_five_percent_average.should == []
19
+ expect(@flog_grapher.flog_average).to eq([])
20
+ expect(@flog_grapher.labels).to eq({})
21
+ expect(@flog_grapher.top_five_percent_average).to eq([])
21
22
  end
22
23
  end
23
24
 
@@ -36,12 +37,12 @@ describe MetricFu::FlogGrapher do
36
37
 
37
38
  it "should push to top_five_percent_average" do
38
39
  average = (99.0 + 98.0 + 97.0 + 96.0 + 95.0) / 5.0
39
- @flog_grapher.top_five_percent_average.should_receive(:push).with(average)
40
+ expect(@flog_grapher.top_five_percent_average).to receive(:push).with(average)
40
41
  @flog_grapher.get_metrics(@metrics, @date)
41
42
  end
42
43
 
43
44
  it "should push 9.9 to flog_average" do
44
- @flog_grapher.flog_average.should_receive(:push).with(7.7)
45
+ expect(@flog_grapher.flog_average).to receive(:push).with(7.7)
45
46
  @flog_grapher.get_metrics(@metrics, @date)
46
47
  end
47
48
 
@@ -52,17 +53,17 @@ describe MetricFu::FlogGrapher do
52
53
  end
53
54
 
54
55
  it "should not push to top_five_percent_average" do
55
- @flog_grapher.top_five_percent_average.should_not_receive(:push)
56
+ expect(@flog_grapher.top_five_percent_average).not_to receive(:push)
56
57
  @flog_grapher.get_metrics(@metrics, @date)
57
58
  end
58
59
 
59
60
  it "should not push to flog_average" do
60
- @flog_grapher.flog_average.should_not_receive(:push)
61
+ expect(@flog_grapher.flog_average).not_to receive(:push)
61
62
  @flog_grapher.get_metrics(@metrics, @date)
62
63
  end
63
64
 
64
65
  it "should not update labels with the date" do
65
- @flog_grapher.labels.should_not_receive(:update)
66
+ expect(@flog_grapher.labels).not_to receive(:update)
66
67
  @flog_grapher.get_metrics(@metrics, @date)
67
68
  end
68
69
  end
@@ -75,17 +76,17 @@ describe MetricFu::FlogGrapher do
75
76
 
76
77
  it "should push to top_five_percent_average" do
77
78
  average = (73.6 + 68.5 + 66.1 + 46.6 + 44.8 + 44.1 + 41.2 + 36.0) / 8.0
78
- @flog_grapher.top_five_percent_average.should_receive(:push).with(average)
79
+ expect(@flog_grapher.top_five_percent_average).to receive(:push).with(average)
79
80
  @flog_grapher.get_metrics(@metrics, @date)
80
81
  end
81
82
 
82
83
  it "should push to flog_average" do
83
- @flog_grapher.flog_average.should_receive(:push).with(9.9)
84
+ expect(@flog_grapher.flog_average).to receive(:push).with(9.9)
84
85
  @flog_grapher.get_metrics(@metrics, @date)
85
86
  end
86
87
 
87
88
  it "should update labels with the date" do
88
- @flog_grapher.labels.should_receive(:update).with({ 0 => "1/2" })
89
+ expect(@flog_grapher.labels).to receive(:update).with({ 0 => "1/2" })
89
90
  @flog_grapher.get_metrics(@metrics, @date)
90
91
  end
91
92
  end
@@ -100,7 +101,7 @@ describe MetricFu::FlogGrapher do
100
101
 
101
102
  it "should push to top_five_percent_average" do
102
103
  average = (73.6 + 68.5 + 66.1 + 46.6 + 44.8 + 44.1 + 41.2 + 36.0) / 8.0
103
- @flog_grapher.top_five_percent_average.should_receive(:push).with(average)
104
+ expect(@flog_grapher.top_five_percent_average).to receive(:push).with(average)
104
105
  @flog_grapher.get_metrics(@metrics, @date)
105
106
  end
106
107
  end