From 66eb9a20252fda68f97a771a3994f296cf5f903b Mon Sep 17 00:00:00 2001 From: Solomon White Date: Sun, 22 Oct 2017 15:55:26 -0600 Subject: [PATCH] test cleanup and enhancements --- Gemfile | 5 ----- Rakefile | 5 ++++- dentaku.gemspec | 8 ++++++-- lib/dentaku/flat_hash.rb | 6 +++--- spec/calculator_spec.rb | 4 ++-- spec/spec_helper.rb | 14 +++++++++++++- 6 files changed, 28 insertions(+), 14 deletions(-) diff --git a/Gemfile b/Gemfile index 5a20cac3..be6b7a5e 100644 --- a/Gemfile +++ b/Gemfile @@ -2,8 +2,3 @@ source "http://rubygems.org" # Specify your gem's dependencies in dentaku.gemspec gemspec - -if RUBY_VERSION.to_f >= 2.0 && RUBY_ENGINE == 'ruby' - gem 'pry-byebug' - gem 'pry-stack_explorer' -end diff --git a/Rakefile b/Rakefile index dba88e61..1e3ef626 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,8 @@ require 'bundler/gem_tasks' require 'rspec/core/rake_task' +require 'rubocop/rake_task' + +RuboCop::RakeTask.new desc "Run specs" task :spec do @@ -10,7 +13,7 @@ task :spec do end desc "Default: run specs." -task default: :spec +task(:default).clear.enhance [:spec, :rubocop] task :console do begin diff --git a/dentaku.gemspec b/dentaku.gemspec index 0957f8bf..03268764 100644 --- a/dentaku.gemspec +++ b/dentaku.gemspec @@ -16,10 +16,14 @@ Gem::Specification.new do |s| s.rubyforge_project = "dentaku" + s.add_development_dependency('coveralls') + s.add_development_dependency('pry') + s.add_development_dependency('pry-byebug') + s.add_development_dependency('pry-stack_explorer') s.add_development_dependency('rake') s.add_development_dependency('rspec') - s.add_development_dependency('pry') - s.add_development_dependency('coveralls') + s.add_development_dependency('rubocop') + s.add_development_dependency('simplecov') s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") diff --git a/lib/dentaku/flat_hash.rb b/lib/dentaku/flat_hash.rb index 1d827057..18200d84 100644 --- a/lib/dentaku/flat_hash.rb +++ b/lib/dentaku/flat_hash.rb @@ -1,8 +1,8 @@ module Dentaku class FlatHash - def self.from_hash(h, key=[], acc={}) - return acc.update({ key => h }) unless h.is_a? Hash - h.each { |k, v| from_hash(v, key+[k], acc) } + def self.from_hash(h, key = [], acc = {}) + return acc.update(key => h) unless h.is_a? Hash + h.each { |k, v| from_hash(v, key + [k], acc) } flatten_keys(acc) end diff --git a/spec/calculator_spec.rb b/spec/calculator_spec.rb index 5aee4bb5..ca1f3b4a 100644 --- a/spec/calculator_spec.rb +++ b/spec/calculator_spec.rb @@ -79,7 +79,7 @@ end it 'evalutates arrays' do - expect(calculator.evaluate([1,2,3])).to eq([1,2,3]) + expect(calculator.evaluate([1, 2, 3])).to eq([1, 2, 3]) end end @@ -99,7 +99,7 @@ end it "finds no dependencies in array literals" do - expect(calculator.dependencies([1,2,3])).to eq([]) + expect(calculator.dependencies([1, 2, 3])).to eq([]) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3bc1301f..5fe68bc9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,9 +1,21 @@ require 'pry' +require 'simplecov' require 'coveralls' -# Check the amount of testcoverage +SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([ + SimpleCov::Formatter::HTMLFormatter, + Coveralls::SimpleCov::Formatter +]) + Coveralls.wear! +SimpleCov.minimum_coverage 90 +SimpleCov.minimum_coverage_by_file 80 + +SimpleCov.start do + add_filter "spec/" +end + # automatically create a token stream from bare values def token_stream(*args) args.map do |value|