Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: fixing ruby warnings #261

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
11 changes: 11 additions & 0 deletions .pryrc
Original file line number Diff line number Diff line change
@@ -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
36 changes: 17 additions & 19 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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
Expand All @@ -45,30 +36,37 @@ 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
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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
22 changes: 21 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 4 additions & 15 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
31 changes: 31 additions & 0 deletions gem_tasks/notes.rake
Original file line number Diff line number Diff line change
@@ -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

16 changes: 16 additions & 0 deletions gem_tasks/rspec.rake
Original file line number Diff line number Diff line change
@@ -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
22 changes: 17 additions & 5 deletions gem_tasks/rubocop.rake
Original file line number Diff line number Diff line change
@@ -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
29 changes: 15 additions & 14 deletions gem_tasks/yard.rake
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/metric_fu/metrics/saikuro/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 10 additions & 11 deletions spec/capture_warnings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/metric_fu/metrics/rcov/simplecov_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(

Expand All @@ -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
Expand Down