Code quality tools (#74)

This commit is contained in:
Luca Guidi 2018-07-24 12:03:38 +02:00 committed by GitHub
parent cf9477a050
commit a8226a522d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 232 additions and 119 deletions

141
.circleci/config.yml Normal file
View File

@ -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"

1
.jrubyrc Normal file
View File

@ -0,0 +1 @@
debug.fullTrace=true

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -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!

23
spec/support/framework.rb Normal file
View File

@ -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!

25
spec/support/rspec.rb Normal file
View File

@ -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

View File

@ -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