From a8226a522d88417f95942bf2613e12fbbc56b1db Mon Sep 17 00:00:00 2001 From: Luca Guidi Date: Tue, 24 Jul 2018 12:03:38 +0200 Subject: [PATCH] Code quality tools (#74) --- .circleci/config.yml | 141 ++++++++++++++++++++++++++++ .jrubyrc | 1 + .travis.yml | 10 +- Gemfile | 3 +- README.md | 10 +- Rakefile | 22 ++--- script/ci | 51 ++++------ spec/spec_helper.rb | 63 +------------ spec/support/framework.rb | 23 +++++ spec/support/rspec.rb | 25 +++++ spec/unit/hanami/mailer/dsl_spec.rb | 2 +- 11 files changed, 232 insertions(+), 119 deletions(-) create mode 100644 .circleci/config.yml create mode 100644 .jrubyrc create mode 100644 spec/support/framework.rb create mode 100644 spec/support/rspec.rb diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..22835e8 --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,141 @@ +# Ruby CircleCI 2.0 configuration file +# +# Check https://circleci.com/docs/2.0/language-ruby/ for more details +# +version: 2 +jobs: + "ruby-2.3": + docker: + - image: hanami/ruby-2.3 + working_directory: ~/hanami-utils + steps: + - checkout + # Download and cache dependencies + - restore_cache: + keys: + - v1-dependencies-{{ checksum "Gemfile.lock" }} + # fallback to using the latest cache if no exact match is found + - v1-dependencies- + - run: + name: install dependencies + command: | + bundle install --jobs=4 --retry=3 --path vendor/bundle + - save_cache: + paths: + - ./vendor/bundle + key: v1-dependencies-{{ checksum "Gemfile.lock" }} + # run tests! + - run: + name: run tests + command: | + ./script/ci + "ruby-2.4": + docker: + - image: hanami/ruby-2.4 + working_directory: ~/hanami-utils + steps: + - checkout + # Download and cache dependencies + - restore_cache: + keys: + - v1-dependencies-{{ checksum "Gemfile.lock" }} + # fallback to using the latest cache if no exact match is found + - v1-dependencies- + - run: + name: install dependencies + command: | + bundle install --jobs=4 --retry=3 --path vendor/bundle + - save_cache: + paths: + - ./vendor/bundle + key: v1-dependencies-{{ checksum "Gemfile.lock" }} + # run tests! + - run: + name: run tests + command: | + ./script/ci + "ruby-2.5": + docker: + - image: hanami/ruby-2.5 + working_directory: ~/hanami-utils + steps: + - checkout + # Download and cache dependencies + - restore_cache: + keys: + - v1-dependencies-{{ checksum "Gemfile.lock" }} + # fallback to using the latest cache if no exact match is found + - v1-dependencies- + - run: + name: install dependencies + command: | + bundle install --jobs=4 --retry=3 --path vendor/bundle + - save_cache: + paths: + - ./vendor/bundle + key: v1-dependencies-{{ checksum "Gemfile.lock" }} + # run tests! + - run: + name: run tests + command: | + ./script/ci + "jruby-9.1": + docker: + - image: hanami/jruby-9.1 + working_directory: ~/hanami-utils + steps: + - checkout + # Download and cache dependencies + - restore_cache: + keys: + - v1-dependencies-{{ checksum "Gemfile.lock" }} + # fallback to using the latest cache if no exact match is found + - v1-dependencies- + - run: + name: install dependencies + command: | + bundle install --jobs=4 --retry=3 --path vendor/bundle + - save_cache: + paths: + - ./vendor/bundle + key: v1-dependencies-{{ checksum "Gemfile.lock" }} + # run tests! + - run: + name: run tests + command: | + ./script/ci + "jruby-9.2": + docker: + - image: hanami/jruby-9.2 + working_directory: ~/hanami-utils + steps: + - checkout + # Download and cache dependencies + - restore_cache: + keys: + - v1-dependencies-{{ checksum "Gemfile.lock" }} + # fallback to using the latest cache if no exact match is found + - v1-dependencies- + - run: + name: install dependencies + command: | + bundle install --jobs=4 --retry=3 --path vendor/bundle + - save_cache: + paths: + - ./vendor/bundle + key: v1-dependencies-{{ checksum "Gemfile.lock" }} + # run tests! + - run: + name: run tests + command: | + ./script/ci + +workflows: + version: 2 + build: + jobs: + - "ruby-2.3" + - "ruby-2.4" + - "ruby-2.5" + - "jruby-9.1" + - "jruby-9.2" diff --git a/.jrubyrc b/.jrubyrc new file mode 100644 index 0000000..ec033ee --- /dev/null +++ b/.jrubyrc @@ -0,0 +1 @@ +debug.fullTrace=true diff --git a/.travis.yml b/.travis.yml index 259fab4..39e73fe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,15 @@ language: ruby sudo: false cache: bundler +before_script: + - gem update --system script: ./script/ci rvm: - - 2.3.6 - - 2.4.2 - - 2.5.0 + - 2.4.4 + - 2.3.7 + - 2.5.1 + - jruby-9.1.9.0 - ruby-head - - jruby-9.1.13.0 - jruby-head matrix: diff --git a/Gemfile b/Gemfile index 77526e7..c479e14 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' gemspec -unless ENV['TRAVIS'] +unless ENV['CI'] gem 'byebug', require: false, platforms: :mri gem 'yard', require: false end @@ -10,4 +10,3 @@ gem 'hanami-utils', '~> 1.2', require: false, git: 'https://github.com/hanami/ut gem 'haml' gem 'hanami-devtools', require: false, git: 'https://github.com/hanami/devtools.git' -gem 'coveralls', require: false diff --git a/README.md b/README.md index 127b0b6..cb0b7e4 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ Mail for Ruby applications. ## Status -[![Gem Version](http://img.shields.io/gem/v/hanami-mailer.svg)](https://badge.fury.io/rb/hanami-mailer) -[![Build Status](http://img.shields.io/travis/hanami/mailer/master.svg)](https://travis-ci.org/hanami/mailer?branch=master) -[![Coverage](http://img.shields.io/coveralls/hanami/mailer/master.svg)](https://coveralls.io/r/hanami/mailer) -[![Code Climate](http://img.shields.io/codeclimate/github/hanami/mailer.svg)](https://codeclimate.com/github/hanami/mailer) -[![Dependencies](http://img.shields.io/gemnasium/hanami/mailer.svg)](https://gemnasium.com/hanami/mailer) +[![Gem Version](https://badge.fury.io/rb/hanami-mailer.svg)](https://badge.fury.io/rb/hanami-mailer) +[![TravisCI](https://travis-ci.org/hanami/mailer.svg?branch=master)](https://travis-ci.org/hanami/mailer) +[![CircleCI](https://circleci.com/gh/hanami/mailer/tree/master.svg?style=svg)](https://circleci.com/gh/hanami/mailer/tree/master) +[![Test Coverage](https://codecov.io/gh/hanami/mailer/branch/master/graph/badge.svg)](https://codecov.io/gh/hanami/mailer) +[![Depfu](https://badges.depfu.com/badges/739c6e10eaf20d3ba4240d00828284db/overview.svg)](https://depfu.com/github/hanami/mailer?project=Bundler) [![Inline Docs](http://inch-ci.org/github/hanami/mailer.svg)](http://inch-ci.org/github/hanami/mailer) ## Contact diff --git a/Rakefile b/Rakefile index e1ddb5f..395223e 100644 --- a/Rakefile +++ b/Rakefile @@ -1,25 +1,17 @@ -require 'rake' -require 'bundler/gem_tasks' -require 'rspec/core/rake_task' +# frozen_string_literal: true -require 'rake/testtask' -Rake::TestTask.new do |t| - t.pattern = 'test/**/*_test.rb' - t.libs.push 'test' -end +require "rake" +require "bundler/gem_tasks" +require "rspec/core/rake_task" +require "hanami/devtools/rake_tasks" namespace :spec do RSpec::Core::RakeTask.new(:unit) do |task| - file_list = FileList['spec/**/*_spec.rb'] + file_list = FileList["spec/**/*_spec.rb"] file_list = file_list.exclude("spec/{integration,isolation}/**/*_spec.rb") task.pattern = file_list end - - task :coverage do - ENV['COVERAGE'] = 'true' - Rake::Task['spec:unit'].invoke - end end -task default: 'spec:unit' +task default: "spec:unit" diff --git a/script/ci b/script/ci index c495767..c3946ce 100755 --- a/script/ci +++ b/script/ci @@ -2,50 +2,35 @@ set -euo pipefail IFS=$'\n\t' +prepare_build() { + if [ -d coverage ]; then + rm -rf coverage + fi +} + +print_ruby_version() { + echo "Using $(ruby -v)" + echo +} + run_code_quality_checks() { bundle exec rubocop . } run_unit_tests() { - bundle exec rake spec:coverage + bundle exec rake spec:unit } -run_isolation_tests() { - local pwd=$PWD - local root="$pwd/spec/isolation" - - if [ -d $root ]; then - for test in $(find $root -name '*_spec.rb') - do - run_isolation_test $test - - if [ $? -ne 0 ]; then - local exit_code=$? - echo "Failing test: $test" - exit $exit_code - fi - done - fi -} - -run_isolation_test() { - local test=$1 - - printf "\n\n\nRunning: $test\n" - ruby $test --options spec/isolation/.rspec -} - -run_test() { - local test=$1 - - printf "\n\n\nRunning: $test\n" - COVERAGE=true bundle exec rspec $test +upload_code_coverage() { + bundle exec rake codecov:upload } main() { - run_code_quality_checks && + prepare_build && + print_ruby_version && + run_code_quality_checks && run_unit_tests && - run_isolation_tests + upload_code_coverage } main diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6ddae0f..0c87833 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,61 +1,6 @@ -if ENV['COVERALL'] - require 'coveralls' - Coveralls.wear! -end - -require 'hanami/utils' - -RSpec.configure do |config| - config.expect_with :rspec do |expectations| - expectations.include_chain_clauses_in_custom_matcher_descriptions = true - end - - config.mock_with :rspec do |mocks| - mocks.verify_partial_doubles = true - end - - config.shared_context_metadata_behavior = :apply_to_host_groups - - config.filter_run_when_matching :focus - config.disable_monkey_patching! - - config.warnings = true - - config.default_formatter = 'doc' if config.files_to_run.one? - - config.profile_examples = 10 - - config.order = :random - Kernel.srand config.seed -end - -$LOAD_PATH.unshift 'lib' -require 'hanami/mailer' - -Hanami::Mailer.configure do - root Pathname.new __dir__ + '/support/fixtures/templates' -end - -Hanami::Mailer.class_eval do - def self.reset! - self.configuration = configuration.duplicate - configuration.reset! - end -end - -Hanami::Mailer::Dsl.class_eval do - def reset! - @templates = {} - end -end +$LOAD_PATH.unshift "lib" +require "hanami/utils" +require "hanami/devtools/unit" +require "hanami/mailer" Hanami::Utils.require!("spec/support") - -Hanami::Mailer.configure do - root __dir__ + '/support/fixtures' - delivery_method :test - - prepare do - include DefaultSubject - end -end.load! diff --git a/spec/support/framework.rb b/spec/support/framework.rb new file mode 100644 index 0000000..6eac5b2 --- /dev/null +++ b/spec/support/framework.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +Hanami::Mailer.class_eval do + def self.reset! + self.configuration = configuration.duplicate + configuration.reset! + end +end + +Hanami::Mailer::Dsl.class_eval do + def reset! + @templates = {} + end +end + +Hanami::Mailer.configure do + root __dir__ + "/fixtures" + delivery_method :test + + prepare do + include DefaultSubject + end +end.load! diff --git a/spec/support/rspec.rb b/spec/support/rspec.rb new file mode 100644 index 0000000..bcdd2b0 --- /dev/null +++ b/spec/support/rspec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +RSpec.configure do |config| + config.expect_with :rspec do |expectations| + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + config.mock_with :rspec do |mocks| + mocks.verify_partial_doubles = true + end + + config.shared_context_metadata_behavior = :apply_to_host_groups + + config.filter_run_when_matching :focus + config.disable_monkey_patching! + + config.warnings = true + + config.default_formatter = "doc" if config.files_to_run.one? + + config.profile_examples = 10 + + config.order = :random + Kernel.srand config.seed +end diff --git a/spec/unit/hanami/mailer/dsl_spec.rb b/spec/unit/hanami/mailer/dsl_spec.rb index 1e0451c..f5e2415 100644 --- a/spec/unit/hanami/mailer/dsl_spec.rb +++ b/spec/unit/hanami/mailer/dsl_spec.rb @@ -21,7 +21,7 @@ RSpec.describe Hanami::Mailer do describe 'when no value is set' do it 'returns a set of templates' do template_formats = LazyMailer.templates.keys - expect(template_formats).to eq(%i[html txt]) + expect(template_formats).to match_array(%i[html txt]) end it 'returns only the template for the given format' do