Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ gemfile:
rvm:
- 2.0.0
- 1.9.3
- 1.9.2
# - 1.9.2 # code_metric 0.1.0 requires ruby 1.9.3 or greater
- jruby-19mode # JRuby in 1.9 mode
- rbx-19mode
matrix:
Expand Down
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ As such, a _Feature_ would map to either major or minor. A _bug fix_ to a patch.
* Distinguish between an activated metric library and an enabled metric.
* An enabled metric will be run.
* An activated metric has had its library required.
* Code Statistics metrics always runs now, relies on the code_metrics gem extracted from Rails. Does not shell out. ( Benjamin Fleischer, #108 )
* Fixes
* Skip reek of no files are found to run against. Otherwise, reek hangs trying to read from STDIN (Benjamin Fleischer, #119, #121)
* Reek will now find files on Windows. Remove *nix-specific '/' directory separators from Reek file glob. (Benjamin Fleischer, #119, #121)
Expand Down
7 changes: 0 additions & 7 deletions bin/mf-stats

This file was deleted.

8 changes: 6 additions & 2 deletions lib/metric_fu/metrics/stats/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ def name
end

def default_run_options
{}
{
# returns a list of directories that contains the glob of files that have the file_pattern in the file names
:additional_test_directories => [{glob_pattern: File.join('.','spec','**','*_spec.rb'), file_pattern: 'spec'}],
:additional_app_directories => [{glob_pattern: File.join('.','engines','**','*.rb'), file_pattern: ''}],
}
end

def has_graph?
true
end

def enable
super if MetricFu.configuration.rails?
super
end

end
Expand Down
24 changes: 19 additions & 5 deletions lib/metric_fu/metrics/stats/stats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ module MetricFu
class Stats < Generator

def emit
command = %Q(mf-stats > #{metric_directory + '/stats.txt'})
mf_debug "** #{command}"
@output = `#{command}`
require 'code_metrics/statistics'
@output = MfDebugger::Logger.capture_output do
CodeMetrics::Statistics.new(*dirs).to_s
end
end

def analyze
output = File.open(metric_directory + '/stats.txt').read
lines = remove_noise(output).compact
lines = remove_noise(@output).compact

@stats = {}

Expand Down Expand Up @@ -57,5 +57,19 @@ def set_granular_stats(lines)
end
end

# @return [Array<[ 'Acceptance specs', 'spec/acceptance' ]>]
def dirs
require 'code_metrics/stats_directories'
require 'code_metrics/statistics'
stats_dirs = CodeMetrics::StatsDirectories.new
options.fetch(:additional_test_directories).each do |option|
stats_dirs.add_test_directories(option.fetch(:glob_pattern), option.fetch(:file_pattern))
end
options.fetch(:additional_app_directories).each do |option|
stats_dirs.add_directories(option.fetch(:glob_pattern), option.fetch(:file_pattern))
end
stats_dirs.directories
end

end
end
4 changes: 2 additions & 2 deletions lib/metric_fu/metrics/stats/template_awesome/stats.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<h3>Rake Stats Results</h3>
<h3>Lines of Code/Tests Metric Results</h3>

<% graph_name = 'stats' %>
<% if MetricFu.configuration.graph_engine == :gchart %>
Expand All @@ -9,7 +9,7 @@
<% end %>


<p>Rails rake stats results.</p>
<p>Lines of Code/Tests Metrics Results</p>
<table>
<tr>
<th>Lines of Code</th>
Expand Down
1 change: 1 addition & 0 deletions metric_fu.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'rails_best_practices', ['>= 1.14.1', '~> 1.14']
s.add_runtime_dependency 'metric_fu-Saikuro', ['>= 1.1.1.0']
s.add_runtime_dependency 'metric_fu-roodi', ['>= 2.2.1']
s.add_runtime_dependency 'code_metrics', ['~> 0.1']

# other dependencies
# ruby version identification
Expand Down
10 changes: 6 additions & 4 deletions spec/metric_fu/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,10 @@ def load_metric(metric)
end
it 'should set @stats to {}' do
load_metric 'stats'
MetricFu::Metric.get_metric(:stats).run_options.
should == {}
expect(MetricFu::Metric.get_metric(:stats).run_options).to eq({
:additional_test_directories=>[{:glob_pattern=>"./spec/**/*_spec.rb", :file_pattern=>"spec"}],
:additional_app_directories=>[{:glob_pattern=>"./engines/**/*.rb", :file_pattern=>""}]
})
end

it 'should set @rails_best_practices to {}' do
Expand All @@ -258,10 +260,10 @@ def load_metric(metric)
end

it 'should set the available metrics' do
MetricFu::Metric.enabled_metrics.map(&:name).should =~ [:churn, :flog, :flay, :reek, :roodi, :rcov, :hotspots, :saikuro, :cane] - MetricFu.mri_only_metrics
MetricFu::Metric.enabled_metrics.map(&:name).should =~ [:churn, :flog, :flay, :reek, :roodi, :rcov, :hotspots, :saikuro, :cane, :stats] - MetricFu.mri_only_metrics
end

it 'should set the @code_dirs instance var to ["lib"]' do
it 'should set the registered code_dirs to ["lib"]' do
directory('code_dirs').should == ['lib']
end
end
Expand Down
3 changes: 1 addition & 2 deletions spec/metric_fu/metrics/stats/stats_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
MetricFu.configure.reset
File.stub(:directory?).and_return(true)
stats = MetricFu::Stats.new
stats.should_receive(:`).with("mf-stats > tmp/metric_fu/scratch/stats/stats.txt")
stats.emit
end
end
Expand Down Expand Up @@ -37,7 +36,7 @@
MetricFu.configure.reset
File.stub(:directory?).and_return(true)
stats = MetricFu::Stats.new
File.should_receive(:open).and_return(double("file", :read => @lines))
stats.instance_variable_set('@output', @lines)
@results = stats.analyze
end

Expand Down