Code quality tools (#94)
This commit is contained in:
parent
613f5dcf48
commit
2d37af42af
|
@ -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-node
|
||||
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-node
|
||||
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-node
|
||||
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-node
|
||||
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-node
|
||||
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"
|
11
.travis.yml
11
.travis.yml
|
@ -1,11 +1,14 @@
|
|||
language: ruby
|
||||
sudo: false
|
||||
cache: bundler
|
||||
before_script:
|
||||
- gem update --system
|
||||
script: ./script/ci
|
||||
rvm:
|
||||
- 2.3.6
|
||||
- 2.4.2
|
||||
- 2.5.0
|
||||
- jruby-9.1.13.0
|
||||
- 2.4.4
|
||||
- 2.3.7
|
||||
- 2.5.1
|
||||
- jruby-9.1.9.0
|
||||
- ruby-head
|
||||
- jruby-head
|
||||
|
||||
|
|
3
Gemfile
3
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
|
||||
|
@ -15,4 +15,3 @@ gem 'hanami-compass', path: 'spec/support/fixtures/hanami-compass',
|
|||
gem 'hanami-foo-compressor', path: 'spec/support/fixtures/hanami-foo-compressor', require: false
|
||||
|
||||
gem 'hanami-devtools', require: false, git: 'https://github.com/hanami/devtools.git'
|
||||
gem 'coveralls', require: false
|
||||
|
|
10
README.md
10
README.md
|
@ -4,11 +4,11 @@ Assets management for Ruby web projects
|
|||
|
||||
## Status
|
||||
|
||||
[![Gem Version](http://img.shields.io/gem/v/hanami-assets.svg)](https://badge.fury.io/rb/hanami-assets)
|
||||
[![Build Status](http://img.shields.io/travis/hanami/assets/master.svg)](https://travis-ci.org/hanami/assets?branch=master)
|
||||
[![Coverage](http://img.shields.io/coveralls/hanami/assets/master.svg)](https://coveralls.io/r/hanami/assets)
|
||||
[![Code Climate](http://img.shields.io/codeclimate/github/hanami/assets.svg)](https://codeclimate.com/github/hanami/assets)
|
||||
[![Dependencies](http://img.shields.io/gemnasium/hanami/assets.svg)](https://gemnasium.com/hanami/assets)
|
||||
[![Gem Version](https://badge.fury.io/rb/hanami-assets.svg)](https://badge.fury.io/rb/hanami-assets)
|
||||
[![TravisCI](https://travis-ci.org/hanami/assets.svg?branch=master)](https://travis-ci.org/hanami/assets)
|
||||
[![CircleCI](https://circleci.com/gh/hanami/assets/tree/master.svg?style=svg)](https://circleci.com/gh/hanami/assets/tree/master)
|
||||
[![Test Coverage](https://codecov.io/gh/hanami/assets/branch/master/graph/badge.svg)](https://codecov.io/gh/hanami/assets)
|
||||
[![Depfu](https://badges.depfu.com/badges/4b37347bd74042ff96477495cc16531d/overview.svg)](https://depfu.com/github/hanami/assets?project=Bundler)
|
||||
[![Inline Docs](http://inch-ci.org/github/hanami/assets.svg)](http://inch-ci.org/github/hanami/assets)
|
||||
|
||||
## Contact
|
||||
|
|
29
Rakefile
29
Rakefile
|
@ -1,30 +1,17 @@
|
|||
require 'rake'
|
||||
require 'bundler/gem_tasks'
|
||||
require 'rspec/core/rake_task'
|
||||
require 'rake/testtask'
|
||||
# frozen_string_literal: true
|
||||
|
||||
Rake::TestTask.new do |t|
|
||||
t.pattern = 'test/**/*_test.rb'
|
||||
t.libs.push 'test'
|
||||
require "rake"
|
||||
require "bundler/gem_tasks"
|
||||
require "rspec/core/rake_task"
|
||||
require "hanami/devtools/rake_tasks"
|
||||
|
||||
if ENV['TRAVIS']
|
||||
t.verbose = false
|
||||
t.warning = false
|
||||
end
|
||||
end
|
||||
|
||||
RSpec::Core::RakeTask.new(:spec)
|
||||
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'
|
||||
|
||||
task default: "spec:unit"
|
||||
|
|
27
script/ci
27
script/ci
|
@ -2,12 +2,23 @@
|
|||
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() {
|
||||
|
@ -30,9 +41,10 @@ run_isolation_tests() {
|
|||
|
||||
run_isolation_test() {
|
||||
local test=$1
|
||||
local hash="$(shasum "$test" | cut -b 1-40)"
|
||||
|
||||
printf "\n\n\nRunning: $test\n"
|
||||
ruby $test --options spec/isolation/.rspec
|
||||
SIMPLECOV_COMMAND_NAME=$hash ruby $test --options spec/isolation/.rspec
|
||||
}
|
||||
|
||||
run_test() {
|
||||
|
@ -42,10 +54,17 @@ run_test() {
|
|||
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
|
||||
run_isolation_tests &&
|
||||
upload_code_coverage
|
||||
}
|
||||
|
||||
main
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'tilt/sass'
|
|||
require 'tilt/coffee'
|
||||
require 'hanami/assets/compiler'
|
||||
|
||||
describe 'Compiler' do
|
||||
RSpec.describe 'Compiler' do
|
||||
before do
|
||||
require 'hanami/compass'
|
||||
fixtures = __dir__ + "/../../../support/fixtures"
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'digest'
|
||||
require 'open3'
|
||||
|
||||
describe 'Precompile' do
|
||||
RSpec.describe 'Precompile' do
|
||||
before do
|
||||
dest.rmtree if dest.exist?
|
||||
dest.mkpath
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
describe 'Rendering test' do
|
||||
RSpec.describe 'Rendering test' do
|
||||
before do
|
||||
Hanami::Assets.configuration.reset!
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require __dir__ + "/../../../support/fixtures/bookshelf/config/environment"
|
||||
|
||||
describe 'Third part gems integration' do
|
||||
RSpec.describe 'Third part gems integration' do
|
||||
before do
|
||||
load __dir__ + "/../../../support/fixtures/hanami-emberjs/lib/hanami/emberjs.rb"
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require __dir__ + "/../../../support/fixtures/bookshelf/config/environment"
|
||||
|
||||
describe 'Hanami::View integration' do
|
||||
RSpec.describe 'Hanami::View integration' do
|
||||
before do
|
||||
frameworks = [Web::Assets, Admin::Assets]
|
||||
frameworks.each do |framework|
|
||||
|
|
|
@ -1,47 +1,6 @@
|
|||
if ENV['COVERALL']
|
||||
require 'coveralls'
|
||||
Coveralls.wear!
|
||||
end
|
||||
$LOAD_PATH.unshift "lib"
|
||||
require "hanami/utils"
|
||||
require "hanami/devtools/unit"
|
||||
require "hanami/assets"
|
||||
|
||||
$LOAD_PATH.unshift 'lib'
|
||||
$LOAD_PATH.unshift 'spec'
|
||||
require 'hanami/assets'
|
||||
require 'support/test_file'
|
||||
require 'support/ci'
|
||||
require 'support/fixtures'
|
||||
require 'pathname'
|
||||
|
||||
TMP = Pathname.new(__dir__).join('..', 'tmp')
|
||||
TMP.mkpath
|
||||
|
||||
Hanami::Utils::LoadPaths.class_eval do
|
||||
def empty?
|
||||
@paths.empty?
|
||||
end
|
||||
|
||||
def clear
|
||||
@paths.clear
|
||||
end
|
||||
|
||||
def include?(path)
|
||||
@paths.include?(path)
|
||||
end
|
||||
|
||||
def delete(path)
|
||||
@paths.delete(path)
|
||||
end
|
||||
end
|
||||
|
||||
Hanami::Assets::Config::GlobalSources.class_eval do
|
||||
def clear
|
||||
@paths.each do |path|
|
||||
Hanami::Assets.configuration.sources.delete(path)
|
||||
|
||||
Hanami::Assets.duplicates.each do |duplicate|
|
||||
duplicate.configuration.sources.delete(path)
|
||||
end
|
||||
end
|
||||
|
||||
super
|
||||
end
|
||||
end
|
||||
Hanami::Utils.require!("spec/support")
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
module CI
|
||||
def self.enabled?
|
||||
ENV['TRAVIS']
|
||||
ENV['CI']
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
Hanami::Assets::Config::GlobalSources.class_eval do
|
||||
def clear
|
||||
@paths.each do |path|
|
||||
Hanami::Assets.configuration.sources.delete(path)
|
||||
|
||||
Hanami::Assets.duplicates.each do |duplicate|
|
||||
duplicate.configuration.sources.delete(path)
|
||||
end
|
||||
end
|
||||
|
||||
super
|
||||
end
|
||||
end
|
|
@ -0,0 +1,17 @@
|
|||
Hanami::Utils::LoadPaths.class_eval do
|
||||
def empty?
|
||||
@paths.empty?
|
||||
end
|
||||
|
||||
def clear
|
||||
@paths.clear
|
||||
end
|
||||
|
||||
def include?(path)
|
||||
@paths.include?(path)
|
||||
end
|
||||
|
||||
def delete(path)
|
||||
@paths.delete(path)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,25 @@
|
|||
require 'rspec'
|
||||
|
||||
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
|
|
@ -1,5 +1,6 @@
|
|||
require 'securerandom'
|
||||
require_relative 'ci'
|
||||
require_relative 'tmp'
|
||||
|
||||
class TestFile
|
||||
OPEN_MODE = File::WRONLY | File::TRUNC | File::CREAT
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
require 'pathname'
|
||||
|
||||
TMP = Pathname.new(__dir__).join('..', 'tmp')
|
||||
TMP.mkpath
|
|
@ -4,7 +4,7 @@ require 'hanami/assets/compressors/stylesheet'
|
|||
require 'etc'
|
||||
require 'json'
|
||||
|
||||
describe Hanami::Assets::Bundler do
|
||||
RSpec.describe Hanami::Assets::Bundler do
|
||||
before do
|
||||
dest.rmtree if dest.exist?
|
||||
dest.mkpath
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'hanami/assets/compressors/builtin_stylesheet'
|
||||
|
||||
describe Hanami::Assets::Compressors::BuiltinStylesheet do
|
||||
RSpec.describe Hanami::Assets::Compressors::BuiltinStylesheet do
|
||||
let(:compressor) { Hanami::Assets::Compressors::BuiltinStylesheet.new }
|
||||
|
||||
describe '#compress' do
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'hanami/assets/compressors/javascript'
|
||||
require 'hanami/foo/compressor'
|
||||
|
||||
describe Hanami::Assets::Compressors::Javascript do
|
||||
RSpec.describe Hanami::Assets::Compressors::Javascript do
|
||||
describe '.for' do
|
||||
let(:compressor) { Hanami::Assets::Compressors::Javascript.for(engine_name) }
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'hanami/assets/compressors/stylesheet'
|
||||
require 'hanami/foo/compressor'
|
||||
|
||||
describe Hanami::Assets::Compressors::Stylesheet do
|
||||
RSpec.describe Hanami::Assets::Compressors::Stylesheet do
|
||||
describe '.for' do
|
||||
let(:compressor) { Hanami::Assets::Compressors::Stylesheet.for(engine_name) }
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require 'pp'
|
||||
|
||||
describe Hanami::Assets::Config::NullManifest do
|
||||
RSpec.describe Hanami::Assets::Config::NullManifest do
|
||||
let(:configuration) { Hanami::Assets::Configuration.new }
|
||||
let(:manifest) { Hanami::Assets::Config::NullManifest.new(configuration) }
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require 'hanami/assets/compressors/javascript'
|
||||
require 'hanami/assets/compressors/stylesheet'
|
||||
|
||||
describe Hanami::Assets::Configuration do
|
||||
RSpec.describe Hanami::Assets::Configuration do
|
||||
before do
|
||||
@configuration = Hanami::Assets::Configuration.new
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
describe Hanami::Assets::Helpers do
|
||||
RSpec.describe Hanami::Assets::Helpers do
|
||||
let(:view) { ImageHelperView.new({}, {}) }
|
||||
let(:cdn_url) { 'https://bookshelf.cdn-example.com' }
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
describe "Hanami::Assets::VERSION" do
|
||||
RSpec.describe "Hanami::Assets::VERSION" do
|
||||
it "exposes version" do
|
||||
expect(Hanami::Assets::VERSION).to eq("1.2.0")
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
describe Hanami::Assets do
|
||||
RSpec.describe Hanami::Assets do
|
||||
describe '.sources' do
|
||||
before do
|
||||
Hanami::Assets.sources.clear
|
||||
|
|
Loading…
Reference in New Issue