Code quality tools (#139)
This commit is contained in:
parent
9acd2bf17b
commit
2cae7225a0
|
@ -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"
|
10
.travis.yml
10
.travis.yml
|
@ -1,13 +1,15 @@
|
||||||
language: ruby
|
language: ruby
|
||||||
sudo: false
|
sudo: false
|
||||||
cache: bundler
|
cache: bundler
|
||||||
|
before_script:
|
||||||
|
- gem update --system
|
||||||
script: ./script/ci
|
script: ./script/ci
|
||||||
rvm:
|
rvm:
|
||||||
- 2.3.6
|
- 2.4.4
|
||||||
- 2.4.2
|
- 2.3.7
|
||||||
- 2.5.0
|
- 2.5.1
|
||||||
|
- jruby-9.1.9.0
|
||||||
- ruby-head
|
- ruby-head
|
||||||
- jruby-9.1.13.0
|
|
||||||
- jruby-head
|
- jruby-head
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
|
|
3
Gemfile
3
Gemfile
|
@ -1,7 +1,7 @@
|
||||||
source 'https://rubygems.org'
|
source 'https://rubygems.org'
|
||||||
gemspec
|
gemspec
|
||||||
|
|
||||||
unless ENV['TRAVIS']
|
unless ENV['CI']
|
||||||
gem 'byebug', require: false, platforms: :mri
|
gem 'byebug', require: false, platforms: :mri
|
||||||
gem 'pry-debugger-jruby', require: false, platforms: :jruby
|
gem 'pry-debugger-jruby', require: false, platforms: :jruby
|
||||||
gem 'yard', require: false
|
gem 'yard', require: false
|
||||||
|
@ -13,4 +13,3 @@ gem 'hanami-controller', '~> 1.2', git: 'https://github.com/hanami/controller.g
|
||||||
gem 'hanami-view', '~> 1.2', git: 'https://github.com/hanami/view.git', branch: 'master'
|
gem 'hanami-view', '~> 1.2', git: 'https://github.com/hanami/view.git', branch: 'master'
|
||||||
|
|
||||||
gem 'hanami-devtools', git: 'https://github.com/hanami/devtools.git', require: false
|
gem 'hanami-devtools', git: 'https://github.com/hanami/devtools.git', require: false
|
||||||
gem 'coveralls', require: false
|
|
||||||
|
|
10
README.md
10
README.md
|
@ -4,11 +4,11 @@ View helpers for Ruby applications
|
||||||
|
|
||||||
## Status
|
## Status
|
||||||
|
|
||||||
[![Gem Version](http://img.shields.io/gem/v/hanami-helpers.svg)](https://badge.fury.io/rb/hanami-helpers)
|
[![Gem Version](https://badge.fury.io/rb/hanami-helpers.svg)](https://badge.fury.io/rb/hanami-helpers)
|
||||||
[![Build Status](http://img.shields.io/travis/hanami/helpers/master.svg)](https://travis-ci.org/hanami/helpers?branch=master)
|
[![TravisCI](https://travis-ci.org/hanami/helpers.svg?branch=master)](https://travis-ci.org/hanami/helpers)
|
||||||
[![Coverage](http://img.shields.io/coveralls/hanami/helpers/master.svg)](https://coveralls.io/r/hanami/helpers)
|
[![CircleCI](https://circleci.com/gh/hanami/helpers/tree/master.svg?style=svg)](https://circleci.com/gh/hanami/helpers/tree/master)
|
||||||
[![Code Climate](http://img.shields.io/codeclimate/github/hanami/helpers.svg)](https://codeclimate.com/github/hanami/helpers)
|
[![Test Coverage](https://codecov.io/gh/hanami/helpers/branch/master/graph/badge.svg)](https://codecov.io/gh/hanami/helpers)
|
||||||
[![Dependencies](http://img.shields.io/gemnasium/hanami/helpers.svg)](https://gemnasium.com/hanami/helpers)
|
[![Depfu](https://badges.depfu.com/badges/7b30c5d2a2a78954e2ad86e5c7230c23/overview.svg)](https://depfu.com/github/hanami/helpers?project=Bundler)
|
||||||
[![Inline Docs](http://inch-ci.org/github/hanami/helpers.svg)](http://inch-ci.org/github/hanami/helpers)
|
[![Inline Docs](http://inch-ci.org/github/hanami/helpers.svg)](http://inch-ci.org/github/hanami/helpers)
|
||||||
|
|
||||||
## Contact
|
## Contact
|
||||||
|
|
14
Rakefile
14
Rakefile
|
@ -1,25 +1,15 @@
|
||||||
require 'rake'
|
require 'rake'
|
||||||
require 'bundler/gem_tasks'
|
require 'bundler/gem_tasks'
|
||||||
require 'rspec/core/rake_task'
|
require 'rspec/core/rake_task'
|
||||||
require 'rake/testtask'
|
require 'hanami/devtools/rake_tasks'
|
||||||
|
|
||||||
Rake::TestTask.new do |t|
|
|
||||||
t.pattern = 'test/**/*_test.rb'
|
|
||||||
t.libs.push 'test'
|
|
||||||
end
|
|
||||||
|
|
||||||
namespace :spec do
|
namespace :spec do
|
||||||
RSpec::Core::RakeTask.new(:unit) do |task|
|
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/isolation/**/*_spec.rb")
|
file_list = file_list.exclude("spec/{integration,isolation}/**/*_spec.rb")
|
||||||
|
|
||||||
task.pattern = file_list
|
task.pattern = file_list
|
||||||
end
|
end
|
||||||
|
|
||||||
task :coverage do
|
|
||||||
ENV['COVERAGE'] = 'true'
|
|
||||||
Rake::Task['spec:unit'].invoke
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
task default: 'spec:unit'
|
task default: 'spec:unit'
|
||||||
|
|
58
script/ci
58
script/ci
|
@ -2,50 +2,60 @@
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
IFS=$'\n\t'
|
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() {
|
run_code_quality_checks() {
|
||||||
bundle exec rubocop .
|
bundle exec rubocop .
|
||||||
}
|
}
|
||||||
|
|
||||||
run_unit_tests() {
|
run_unit_tests() {
|
||||||
bundle exec rake spec:coverage
|
bundle exec rake spec:unit
|
||||||
}
|
}
|
||||||
|
|
||||||
run_isolation_tests() {
|
run_integration_tests() {
|
||||||
local pwd=$PWD
|
local pwd=$PWD
|
||||||
local root="$pwd/spec/isolation"
|
local root="$pwd/spec/integration"
|
||||||
|
|
||||||
if [ -d $root ]; then
|
for test in $(find $root -name '*_spec.rb')
|
||||||
for test in $(find $root -name '*_spec.rb')
|
do
|
||||||
do
|
run_test $test
|
||||||
run_isolation_test $test
|
|
||||||
|
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
local exit_code=$?
|
local exit_code=$?
|
||||||
echo "Failing test: $test"
|
echo "Failing test: $test"
|
||||||
exit $exit_code
|
exit $exit_code
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
run_isolation_test() {
|
|
||||||
local test=$1
|
|
||||||
|
|
||||||
printf "\n\n\nRunning: $test\n"
|
|
||||||
ruby $test --options spec/isolation/.rspec
|
|
||||||
}
|
}
|
||||||
|
|
||||||
run_test() {
|
run_test() {
|
||||||
local test=$1
|
local test=$1
|
||||||
|
local hash="$(shasum "$test" | cut -b 1-40)"
|
||||||
|
|
||||||
printf "\n\n\nRunning: $test\n"
|
printf "\n\n\nRunning: $test\n"
|
||||||
COVERAGE=true bundle exec rspec $test
|
SIMPLECOV_COMMAND_NAME=$hash bundle exec rspec $test
|
||||||
|
}
|
||||||
|
|
||||||
|
upload_code_coverage() {
|
||||||
|
bundle exec rake codecov:upload
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
run_code_quality_checks &&
|
prepare_build &&
|
||||||
|
print_ruby_version &&
|
||||||
|
run_code_quality_checks &&
|
||||||
run_unit_tests &&
|
run_unit_tests &&
|
||||||
run_isolation_tests
|
run_integration_tests &&
|
||||||
|
upload_code_coverage
|
||||||
}
|
}
|
||||||
|
|
||||||
main
|
main
|
||||||
|
|
|
@ -1,36 +1,9 @@
|
||||||
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'
|
$LOAD_PATH.unshift 'lib'
|
||||||
|
require 'hanami/utils'
|
||||||
|
require 'hanami/devtools/unit'
|
||||||
|
|
||||||
require 'hanami/helpers'
|
require 'hanami/helpers'
|
||||||
require_relative './support/fixtures'
|
require_relative './support/fixtures'
|
||||||
|
|
||||||
|
Hanami::Utils.require!("spec/support")
|
||||||
Hanami::View.load!
|
Hanami::View.load!
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
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
|
Loading…
Reference in New Issue