diff --git a/.pryrc b/.pryrc new file mode 100644 index 000000000..e549c1e0e --- /dev/null +++ b/.pryrc @@ -0,0 +1,11 @@ +require "bond" +if defined?(PryByebug) + Pry.commands.alias_command 'c', 'continue' + Pry.commands.alias_command 's', 'step' + Pry.commands.alias_command 'n', 'next' + Pry.commands.alias_command 'f', 'finish' +end +# Hit Enter to repeat last command +Pry::Commands.command /^$/, "repeat last command" do + _pry_.run_command Pry.history.to_a.last +end diff --git a/.simplecov b/.simplecov index 6cfe7adac..5651f9843 100644 --- a/.simplecov +++ b/.simplecov @@ -1,17 +1,8 @@ # https://github.com/colszowka/simplecov#using-simplecov-for-centralized-config # see https://github.com/colszowka/simplecov/blob/master/lib/simplecov/defaults.rb # vim: set ft=ruby -@minimum_coverage = ENV.fetch("COVERAGE_MINIMUM") { 87.8 }.to_f.round(2) -if SimpleCov.respond_to?(:profiles) - SimpleCov.profiles -else - SimpleCov.adapters -end.define 'metric_fu' do - if defined?(load_profile) - load_profile 'test_frameworks' - else - load_adapter 'test_frameworks' - end +SimpleCov.profiles.define "metric_fu" do + load_profile "test_frameworks" add_group "Cli", "lib/metric_fu/cli" add_group "Data Structures", "lib/metric_fu/data_structures" @@ -32,9 +23,9 @@ end.define 'metric_fu' do add_group "Short files", MaxLinesFilter.new(5) # Exclude these paths from analysis - add_filter 'bundle' + add_filter "bundle" + add_filter "bin" add_filter 'vendor/bundle' - add_filter 'bin' add_filter 'lib/metric_fu/tasks' # https://github.com/colszowka/simplecov/blob/v0.9.1/lib/simplecov/defaults.rb#L60 @@ -45,18 +36,23 @@ end if defined?(@running_tests) @running_tests = false else - @running_tests = caller.any? {|line| line =~ /exe\/rspec/ } + @running_tests = caller.any? { |line| line =~ /exe\/rspec/ } end + +if @running_tests + SimpleCov.start "metric_fu" +end + if ENV["COVERAGE"] =~ /\Atrue\z/i puts "[COVERAGE] Running with SimpleCov HTML Formatter" formatters = [SimpleCov::Formatter::HTMLFormatter] begin - puts '[COVERAGE] Running with SimpleCov HTML Formatter' require 'metric_fu/metrics/rcov/simplecov_formatter' - formatters << SimpleCov::Formatter::MetricFu - puts '[COVERAGE] Running with SimpleCov MetricFu Formatter' rescue LoadError puts '[COVERAGE] SimpleCov MetricFu formatter could not be loaded' + else + formatters << SimpleCov::Formatter::MetricFu + puts '[COVERAGE] Running with SimpleCov MetricFu Formatter' end SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ *formatters ] SimpleCov.start "metric_fu" if @running_tests @@ -64,11 +60,13 @@ else SimpleCov.formatters = [] end SimpleCov.at_exit do + @minimum_coverage = ENV.fetch("COVERAGE_MINIMUM") { 87.8 }.to_f.round(2) SimpleCov.result.format! percent = Float(SimpleCov.result.covered_percent) if percent < @minimum_coverage - abort "Spec coverage was not high enough: #{percent.round(2)} is < #{@minimum_coverage}%" + puts "Spec coverage was not high enough: #{percent.round(2)} is < #{@minimum_coverage}%" + exit 1 if ENV["COVERAGE"] || ENV["FULL_BUILD"] =~ /true/i # we only want to fail the test when running in CI else - puts "Nice job! Spec coverage is still above #{@minimum_coverage}%" + puts "Nice job! Spec coverage (#{percent.round(2)}) is still above #{@minimum_coverage}%" end end diff --git a/.travis.yml b/.travis.yml index 8105768d3..b05161d7d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: ruby bundler_args: --path vendor/bundle --jobs=3 --retry=3 -script: bundle exec rspec +script: bundle exec rake cache: bundler before_install: diff --git a/Gemfile b/Gemfile index f5cf9d30b..b82cfc2b8 100644 --- a/Gemfile +++ b/Gemfile @@ -47,8 +47,28 @@ platform :jruby do end group :test, :local_development do - gem "pry" + gem "code_notes" + + # Debugging + # Guard includes 'pry', so let's make that explicit + # https://github.com/guard/guard#interactions + # Add: edit -c, play -l number, whereami, wtf + gem "pry", require: true + # see https://github.com/pry/pry/wiki/Editor-integration + # https://github.com/pry/pry/wiki/Documentation-browsing + # https://github.com/pry/pry/wiki/Exceptions + # http://www.confreaks.com/videos/2864-rubyconf2013-repl-driven-development-with-pry + # On OSX, edit ~/.editrc and add + # bind "^R" em-inc-search-prev + # to get 'readline' support + # + # Adds: 'step', 'next', 'finish', 'continue', and 'break' commands to control execution. + # gem "pry-byebug", require: false + # see https://github.com/deivid-rodriguez/pry-byebug#execution-commands gem "pry-nav" + # command completion + gem "bond", require: false + # see .pryrc for more configurations end # Added by devtools diff --git a/Rakefile b/Rakefile index 136b36b3f..6bf4d7e2b 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,7 @@ #!/usr/bin/env rake -using_git = File.exist?(File.expand_path('../.git/', __FILE__)) -if using_git +pwd = File.expand_path("..", __FILE__) +USING_GIT = File.directory?(File.join(pwd, ".git")) +if USING_GIT require 'bundler/setup' end require 'rake' @@ -10,18 +11,6 @@ Dir['./gem_tasks/*.rake'].each do |task| import(task) end -require 'rspec/core/rake_task' -desc "Run all specs in spec directory" -RSpec::Core::RakeTask.new(:spec) do |t| - t.verbose = false - - t.pattern = "spec/**/_spec.rb" - # we require spec_helper so we don't get an RSpec warning about - # examples being defined before configuration. - t.ruby_opts = "-I./spec -r./spec/capture_warnings -rspec_helper" - t.rspec_opts = %w[--format progress] if (ENV['FULL_BUILD'] || !using_git) -end - -require File.expand_path File.join(File.dirname(__FILE__),'lib/metric_fu') +require File.join(pwd, "lib/metric_fu") task :default => :spec diff --git a/gem_tasks/notes.rake b/gem_tasks/notes.rake new file mode 100644 index 000000000..73c93190f --- /dev/null +++ b/gem_tasks/notes.rake @@ -0,0 +1,31 @@ +begin + require "code_notes" + @annotator = CodeNotes::SourceAnnotationExtractor +rescue LoadError + require 'rails/source_annotation_extractor' + @annotator = SourceAnnotationExtractor +rescue LoadError + # no notes +end +if @annotator + Rake::Task[:notes].clear if Rake::Task.task_defined?(:notes) + desc "Enumerate all annotations (use notes:optimize, :fixme, :todo for focus)" + task :notes do + @annotator.enumerate "OPTIMIZE|FIXME|TODO|TECHDEBT|HACK", tag: true + end + + namespace :notes do + ["OPTIMIZE", "FIXME", "TODO", "TECHDEBT", "HACK"].each do |annotation| + desc "Enumerate all #{annotation} annotations" + task annotation.downcase.intern do + @annotator.enumerate annotation + end + end + + desc "Enumerate a custom annotation, specify with ANNOTATION=CUSTOM|ANOTHER" + task :custom do + @annotator.enumerate ENV["ANNOTATION"] + end + end +end + diff --git a/gem_tasks/rspec.rake b/gem_tasks/rspec.rake new file mode 100644 index 000000000..f14dbe9a5 --- /dev/null +++ b/gem_tasks/rspec.rake @@ -0,0 +1,16 @@ +begin + Rake::Task[:spec].clear if Rake::Task.task_defined?(:spec) + require "rspec/core/rake_task" +rescue LoadError +else + desc "Run all specs in spec directory" + RSpec::Core::RakeTask.new(:spec) do |t| + t.verbose = false + + t.pattern = "spec/**/*_spec.rb" + # we require spec_helper so we don't get an RSpec warning about + # examples being defined before configuration. + t.ruby_opts = "-I./lib -rbundler/setup -I./spec -rcapture_warnings -rspec_helper" + t.rspec_opts = %w[--format progress] if (ENV['FULL_BUILD'] || USING_GIT) + end +end diff --git a/gem_tasks/rubocop.rake b/gem_tasks/rubocop.rake index 66ef9eb3d..a08ab6672 100644 --- a/gem_tasks/rubocop.rake +++ b/gem_tasks/rubocop.rake @@ -1,10 +1,22 @@ -if ENV["FULL_BUILD"] != "true" # skip on Travis +begin + require "rubocop" require "rubocop/rake_task" +rescue LoadError +else + Rake::Task[:rubocop].clear if Rake::Task.task_defined?(:rubocop) + desc "Run RuboCop" RuboCop::RakeTask.new(:rubocop) do |task| - task.patterns = ["lib", "spec"] - task.formatters = ["progress"] + task.patterns = [ + "lib/**/*.rb", + "config/**/*.rb", + "spec/**/*.rb", + "app/**/*.rb", + "exe/*" + ] task.options = ["--display-cop-names"] + # only show the files with failures + task.formatters = ["progress"] + # don"t abort rake on failure task.fail_on_error = false - task.verbose = false end -end +end if ENV["FULL_BUILD"] != "true" # skip on Travis diff --git a/gem_tasks/yard.rake b/gem_tasks/yard.rake index 033742156..8fe5d2ea2 100644 --- a/gem_tasks/yard.rake +++ b/gem_tasks/yard.rake @@ -4,21 +4,22 @@ begin require "yard" rescue LoadError else -namespace :yard do - YARD::Rake::YardocTask.new(:doc) do |t| - t.stats_options = ["--list-undoc"] - end + task :yard => ["yard:doc"] + namespace :yard do + YARD::Rake::YardocTask.new(:doc) do |t| + t.stats_options = ["--list-undoc"] + end - desc "start a gem server" - task :server do - sh "bundle exec yard server --gems" - end + desc "start a gem server" + task :server do + sh "bundle exec yard server --gems" + end - desc "use Graphviz to generate dot graph" - task :graph do - output_file = "doc/erd.dot" - sh "bundle exec yard graph --protected --full --dependencies > #{output_file}" - puts "open doc/erd.dot if you have graphviz installed" + desc "use Graphviz to generate dot graph" + task :graph do + output_file = "doc/erd.dot" + sh "bundle exec yard graph --protected --full --dependencies > #{output_file}" + puts "open doc/erd.dot if you have graphviz installed" + end end end -end diff --git a/lib/metric_fu/metrics/saikuro/generator.rb b/lib/metric_fu/metrics/saikuro/generator.rb index 364984eae..f413c6969 100644 --- a/lib/metric_fu/metrics/saikuro/generator.rb +++ b/lib/metric_fu/metrics/saikuro/generator.rb @@ -84,7 +84,7 @@ def erb_file?(filename) end def file_not_exists?(filename) - !File.exists?(filename) + !File.exist?(filename) end def sort_methods(methods) diff --git a/spec/capture_warnings.rb b/spec/capture_warnings.rb index 0ab842052..a4935a656 100644 --- a/spec/capture_warnings.rb +++ b/spec/capture_warnings.rb @@ -29,16 +29,6 @@ line.include?(app_root) && !line.include?(bundle_dir) } - if app_warnings.any? - puts <<-WARNINGS -#{'-' * 30} app warnings: #{'-' * 30} - -#{app_warnings.join("\n")} - -#{'-' * 75} - WARNINGS - end - if other_warnings.any? output_file = File.join(output_dir, "warnings.txt") File.write(output_file, other_warnings.join("\n") << "\n") @@ -47,8 +37,17 @@ puts end - # fail the build... if app_warnings.any? + puts <<-WARNINGS + +#{'-' * 30} app warnings: #{'-' * 30} + +#{app_warnings.join("\n")} + +#{'-' * 75} + + WARNINGS + abort "Failing build due to app warnings: #{app_warnings.inspect}" end end diff --git a/spec/metric_fu/metrics/rcov/simplecov_formatter_spec.rb b/spec/metric_fu/metrics/rcov/simplecov_formatter_spec.rb index c71a8d96e..cc17c297b 100644 --- a/spec/metric_fu/metrics/rcov/simplecov_formatter_spec.rb +++ b/spec/metric_fu/metrics/rcov/simplecov_formatter_spec.rb @@ -6,7 +6,7 @@ describe SimpleCov::Formatter::MetricFu do before do @rcov_file = subject.coverage_file_path - File.delete(@rcov_file) if File.exists?(@rcov_file) + File.delete(@rcov_file) if File.exist?(@rcov_file) @result = SimpleCov::Result.new( @@ -19,7 +19,7 @@ it "test_format" do SimpleCov::Formatter::MetricFu.new.format(@result) - expect(File.exists?(@rcov_file)).to be_truthy + expect(File.exist?(@rcov_file)).to be_truthy end if SimpleCov.running