diff --git a/.gitignore b/.gitignore index b1cdab6..3d68483 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,4 @@ *.a mkmf.log .greenbar -.rubocop-https---raw-githubusercontent-com-hanami-hanami-master--rubocop-yml +.rubocop-*yml diff --git a/.rubocop.yml b/.rubocop.yml index 1444038..9790ad7 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,9 +1,4 @@ # Please keep AllCops, Bundler, Style, Metrics groups and then order cops # alphabetically inherit_from: - - https://raw.githubusercontent.com/hanami/hanami/master/.rubocop.yml -Metrics/BlockLength: - Exclude: - - 'spec/**/*' -Style/SymbolArray: - Enabled: false + - https://raw.githubusercontent.com/hanami/devtools/master/.rubocop.yml diff --git a/.travis.yml b/.travis.yml index 4204503..d5e7b2f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: ruby sudo: false cache: bundler -script: 'bundle exec rake spec:coverage --trace && bundle exec rubocop' +script: ./script/ci before_install: - rvm @global do gem uninstall bundler -a -x - rvm @global do gem install bundler -v 1.13.7 diff --git a/Gemfile b/Gemfile index d55410f..1abf6ef 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,8 @@ unless ENV['TRAVIS'] gem 'yard', require: false end -gem 'hanami-utils', '1.1.0.beta1', require: false, git: 'https://github.com/hanami/utils.git', branch: 'develop' -gem 'i18n', '~> 0.7', require: false -gem 'rubocop', '0.48.0', require: false -gem 'coveralls', require: false +gem 'hanami-utils', '1.1.0.beta2', require: false, git: 'https://github.com/hanami/utils.git', branch: 'develop' + +gem 'hanami-devtools', require: false, git: 'https://github.com/hanami/devtools.git' +gem 'i18n', '~> 0.7', require: false +gem 'coveralls', require: false diff --git a/hanami-validations.gemspec b/hanami-validations.gemspec index abb924b..1159852 100644 --- a/hanami-validations.gemspec +++ b/hanami-validations.gemspec @@ -1,5 +1,3 @@ -# coding: utf-8 - lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'hanami/validations/version' @@ -20,8 +18,8 @@ Gem::Specification.new do |spec| spec.require_paths = ['lib'] spec.required_ruby_version = '>= 2.3.0' - spec.add_dependency 'hanami-utils', '1.1.0.beta1' - spec.add_dependency 'dry-validation', '~> 0.10' + spec.add_dependency 'hanami-utils', '1.1.0.beta2' + spec.add_dependency 'dry-validation', '~> 0.11' spec.add_development_dependency 'bundler', '~> 1.6' spec.add_development_dependency 'rake', '~> 10' diff --git a/lib/hanami-validations.rb b/lib/hanami-validations.rb index c3d580b..695bd53 100644 --- a/lib/hanami-validations.rb +++ b/lib/hanami-validations.rb @@ -1 +1 @@ -require 'hanami/validations' # rubocop:disable Style/FileName +require 'hanami/validations' # rubocop:disable Naming/FileName diff --git a/lib/hanami/validations.rb b/lib/hanami/validations.rb index b9ddd62..00c4c53 100644 --- a/lib/hanami/validations.rb +++ b/lib/hanami/validations.rb @@ -6,9 +6,9 @@ require 'hanami/validations/inline_predicate' require 'set' Dry::Validation::Messages::Namespaced.configure do |config| - config.lookup_paths = config.lookup_paths + %w( - %{root}.%{rule}.%{predicate} - ).freeze + config.lookup_paths = config.lookup_paths + %w[ + %s.%s.%s + ].freeze end # @since 0.1.0 @@ -289,7 +289,7 @@ module Hanami return if _predicates_module.nil? && _predicates.empty? lambda do |config| - config.messages = _predicates_module && _predicates_module.messages || DEFAULT_MESSAGES_ENGINE + config.messages = _predicates_module&.messages || DEFAULT_MESSAGES_ENGINE config.messages_file = _predicates_module.messages_path unless _predicates_module.nil? end end diff --git a/script/ci b/script/ci new file mode 100755 index 0000000..c495767 --- /dev/null +++ b/script/ci @@ -0,0 +1,51 @@ +#!/bin/bash +set -euo pipefail +IFS=$'\n\t' + +run_code_quality_checks() { + bundle exec rubocop . +} + +run_unit_tests() { + bundle exec rake spec:coverage +} + +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 +} + +main() { + run_code_quality_checks && + run_unit_tests && + run_isolation_tests +} + +main diff --git a/spec/unit/hanami/validations/form/rules_spec.rb b/spec/unit/hanami/validations/form/rules_spec.rb index 9b85253..62f0a17 100644 --- a/spec/unit/hanami/validations/form/rules_spec.rb +++ b/spec/unit/hanami/validations/form/rules_spec.rb @@ -18,7 +18,7 @@ RSpec.describe Hanami::Validations::Form do optional(:website).filled(:str?, format?: URI::REGEXP) - rule(location: %i(location remote)) do |location, remote| + rule(location: %i[location remote]) do |location, remote| (remote.none? | remote.false?).then(location.filled?) & remote.true?.then(location.none?) end diff --git a/spec/unit/hanami/validations/predicates/form/array_spec.rb b/spec/unit/hanami/validations/predicates/form/array_spec.rb index 49c1b69..ef79aff 100644 --- a/spec/unit/hanami/validations/predicates/form/array_spec.rb +++ b/spec/unit/hanami/validations/predicates/form/array_spec.rb @@ -61,7 +61,7 @@ RSpec.describe 'Predicates: Array' do end describe 'with invalid input (array with non-integers)' do - let(:input) { { 'foo' => %w(foo bar) } } + let(:input) { { 'foo' => %w[foo bar] } } it 'is not successful' do expect_not_successful result, 0 => ['must be an integer'], 1 => ['must be an integer'] @@ -69,7 +69,7 @@ RSpec.describe 'Predicates: Array' do end describe 'with invalid input (mixed array)' do - let(:input) { { 'foo' => %w(1 bar) } } + let(:input) { { 'foo' => %w[1 bar] } } it 'is not successful' do expect_not_successful result, 1 => ['must be an integer'] @@ -83,7 +83,7 @@ RSpec.describe 'Predicates: Array' do include Hanami::Validations::Form validations do - optional(:foo) { included_in?(%w(1 3 5)) } + optional(:foo) { included_in?(%w[1 3 5]) } end end end diff --git a/spec/unit/hanami/validations/predicates/form/excluded_from_spec.rb b/spec/unit/hanami/validations/predicates/form/excluded_from_spec.rb index 9ad897c..0ba767a 100644 --- a/spec/unit/hanami/validations/predicates/form/excluded_from_spec.rb +++ b/spec/unit/hanami/validations/predicates/form/excluded_from_spec.rb @@ -7,7 +7,7 @@ RSpec.describe 'Predicates: Excluded From' do include Hanami::Validations::Form validations do - required(:foo) { excluded_from?(%w(1 3 5)) } + required(:foo) { excluded_from?(%w[1 3 5]) } end end end @@ -67,7 +67,7 @@ RSpec.describe 'Predicates: Excluded From' do include Hanami::Validations::Form validations do - optional(:foo) { excluded_from?(%w(1 3 5)) } + optional(:foo) { excluded_from?(%w[1 3 5]) } end end end @@ -129,7 +129,7 @@ RSpec.describe 'Predicates: Excluded From' do include Hanami::Validations::Form validations do - required(:foo).value(excluded_from?: %w(1 3 5)) + required(:foo).value(excluded_from?: %w[1 3 5]) end end end @@ -189,7 +189,7 @@ RSpec.describe 'Predicates: Excluded From' do include Hanami::Validations::Form validations do - required(:foo).filled(excluded_from?: %w(1 3 5)) + required(:foo).filled(excluded_from?: %w[1 3 5]) end end end @@ -249,7 +249,7 @@ RSpec.describe 'Predicates: Excluded From' do include Hanami::Validations::Form validations do - required(:foo).maybe(excluded_from?: %w(1 3 5)) + required(:foo).maybe(excluded_from?: %w[1 3 5]) end end end @@ -311,7 +311,7 @@ RSpec.describe 'Predicates: Excluded From' do include Hanami::Validations::Form validations do - optional(:foo).value(excluded_from?: %w(1 3 5)) + optional(:foo).value(excluded_from?: %w[1 3 5]) end end end @@ -371,7 +371,7 @@ RSpec.describe 'Predicates: Excluded From' do include Hanami::Validations::Form validations do - optional(:foo).filled(excluded_from?: %w(1 3 5)) + optional(:foo).filled(excluded_from?: %w[1 3 5]) end end end @@ -431,7 +431,7 @@ RSpec.describe 'Predicates: Excluded From' do include Hanami::Validations::Form validations do - optional(:foo).maybe(excluded_from?: %w(1 3 5)) + optional(:foo).maybe(excluded_from?: %w[1 3 5]) end end end diff --git a/spec/unit/hanami/validations/predicates/form/included_in_spec.rb b/spec/unit/hanami/validations/predicates/form/included_in_spec.rb index e42a3cc..62decb8 100644 --- a/spec/unit/hanami/validations/predicates/form/included_in_spec.rb +++ b/spec/unit/hanami/validations/predicates/form/included_in_spec.rb @@ -7,7 +7,7 @@ RSpec.describe 'Predicates: Included In' do include Hanami::Validations::Form validations do - required(:foo) { included_in?(%w(1 3 5)) } + required(:foo) { included_in?(%w[1 3 5]) } end end end @@ -67,7 +67,7 @@ RSpec.describe 'Predicates: Included In' do include Hanami::Validations::Form validations do - optional(:foo) { included_in?(%w(1 3 5)) } + optional(:foo) { included_in?(%w[1 3 5]) } end end end @@ -129,7 +129,7 @@ RSpec.describe 'Predicates: Included In' do include Hanami::Validations::Form validations do - required(:foo).value(included_in?: %w(1 3 5)) + required(:foo).value(included_in?: %w[1 3 5]) end end end @@ -189,7 +189,7 @@ RSpec.describe 'Predicates: Included In' do include Hanami::Validations::Form validations do - required(:foo).filled(included_in?: %w(1 3 5)) + required(:foo).filled(included_in?: %w[1 3 5]) end end end @@ -249,7 +249,7 @@ RSpec.describe 'Predicates: Included In' do include Hanami::Validations::Form validations do - required(:foo).maybe(included_in?: %w(1 3 5)) + required(:foo).maybe(included_in?: %w[1 3 5]) end end end @@ -311,7 +311,7 @@ RSpec.describe 'Predicates: Included In' do include Hanami::Validations::Form validations do - optional(:foo).value(included_in?: %w(1 3 5)) + optional(:foo).value(included_in?: %w[1 3 5]) end end end @@ -371,7 +371,7 @@ RSpec.describe 'Predicates: Included In' do include Hanami::Validations::Form validations do - optional(:foo).filled(included_in?: %w(1 3 5)) + optional(:foo).filled(included_in?: %w[1 3 5]) end end end @@ -431,7 +431,7 @@ RSpec.describe 'Predicates: Included In' do include Hanami::Validations::Form validations do - optional(:foo).maybe(included_in?: %w(1 3 5)) + optional(:foo).maybe(included_in?: %w[1 3 5]) end end end diff --git a/spec/unit/hanami/validations/predicates/form/max_size_spec.rb b/spec/unit/hanami/validations/predicates/form/max_size_spec.rb index 082657d..eafc7ed 100644 --- a/spec/unit/hanami/validations/predicates/form/max_size_spec.rb +++ b/spec/unit/hanami/validations/predicates/form/max_size_spec.rb @@ -13,7 +13,7 @@ RSpec.describe 'Predicates: Max Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -65,7 +65,7 @@ RSpec.describe 'Predicates: Max Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -119,7 +119,7 @@ RSpec.describe 'Predicates: Max Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -171,7 +171,7 @@ RSpec.describe 'Predicates: Max Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -223,7 +223,7 @@ RSpec.describe 'Predicates: Max Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -277,7 +277,7 @@ RSpec.describe 'Predicates: Max Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -329,7 +329,7 @@ RSpec.describe 'Predicates: Max Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result diff --git a/spec/unit/hanami/validations/predicates/form/min_size_spec.rb b/spec/unit/hanami/validations/predicates/form/min_size_spec.rb index 271e3e2..1b7bbff 100644 --- a/spec/unit/hanami/validations/predicates/form/min_size_spec.rb +++ b/spec/unit/hanami/validations/predicates/form/min_size_spec.rb @@ -13,7 +13,7 @@ RSpec.describe 'Predicates: Min Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -65,7 +65,7 @@ RSpec.describe 'Predicates: Min Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -119,7 +119,7 @@ RSpec.describe 'Predicates: Min Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -171,7 +171,7 @@ RSpec.describe 'Predicates: Min Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -223,7 +223,7 @@ RSpec.describe 'Predicates: Min Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -277,7 +277,7 @@ RSpec.describe 'Predicates: Min Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -329,7 +329,7 @@ RSpec.describe 'Predicates: Min Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -381,7 +381,7 @@ RSpec.describe 'Predicates: Min Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result diff --git a/spec/unit/hanami/validations/predicates/form/size/fixed_test.rb b/spec/unit/hanami/validations/predicates/form/size/fixed_test.rb index ecbea29..4097f6e 100644 --- a/spec/unit/hanami/validations/predicates/form/size/fixed_test.rb +++ b/spec/unit/hanami/validations/predicates/form/size/fixed_test.rb @@ -16,7 +16,7 @@ describe 'Predicates: Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -68,7 +68,7 @@ describe 'Predicates: Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -122,7 +122,7 @@ describe 'Predicates: Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -174,7 +174,7 @@ describe 'Predicates: Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -226,7 +226,7 @@ describe 'Predicates: Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -280,7 +280,7 @@ describe 'Predicates: Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -332,7 +332,7 @@ describe 'Predicates: Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -384,7 +384,7 @@ describe 'Predicates: Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result diff --git a/spec/unit/hanami/validations/predicates/form/size/range_test.rb b/spec/unit/hanami/validations/predicates/form/size/range_test.rb index d2d232c..34be931 100644 --- a/spec/unit/hanami/validations/predicates/form/size/range_test.rb +++ b/spec/unit/hanami/validations/predicates/form/size/range_test.rb @@ -16,7 +16,7 @@ describe 'Predicates: Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -68,7 +68,7 @@ describe 'Predicates: Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -122,7 +122,7 @@ describe 'Predicates: Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -174,7 +174,7 @@ describe 'Predicates: Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -226,7 +226,7 @@ describe 'Predicates: Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -280,7 +280,7 @@ describe 'Predicates: Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -332,7 +332,7 @@ describe 'Predicates: Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result @@ -384,7 +384,7 @@ describe 'Predicates: Size' do end describe 'with valid input' do - let(:input) { { 'foo' => %w(1 2 3) } } + let(:input) { { 'foo' => %w[1 2 3] } } it 'is successful' do expect_successful result diff --git a/spec/unit/hanami/validations/predicates/schema/array_spec.rb b/spec/unit/hanami/validations/predicates/schema/array_spec.rb index 9a11c24..d7ea40e 100644 --- a/spec/unit/hanami/validations/predicates/schema/array_spec.rb +++ b/spec/unit/hanami/validations/predicates/schema/array_spec.rb @@ -64,7 +64,7 @@ RSpec.describe 'Predicates: Array' do end describe 'with invalid input (array with non-integers)' do - let(:input) { { foo: %i(foo bar) } } + let(:input) { { foo: %i[foo bar] } } it 'is not successful' do expect_not_successful result, 0 => ['must be an integer'], 1 => ['must be an integer'] diff --git a/spec/unit/hanami/validations/rules_spec.rb b/spec/unit/hanami/validations/rules_spec.rb index b888b7a..f9ca5a9 100644 --- a/spec/unit/hanami/validations/rules_spec.rb +++ b/spec/unit/hanami/validations/rules_spec.rb @@ -20,15 +20,15 @@ RSpec.describe Hanami::Validations do end end - required(:connection_type).filled(:str?, included_in?: %w(a b c)) + required(:connection_type).filled(:str?, included_in?: %w[a b c]) optional(:quick_code).maybe(:str?) optional(:uuid).maybe(:str?) - rule(quick_code_presence: %i(connection_type quick_code)) do |connection_type, quick_code| + rule(quick_code_presence: %i[connection_type quick_code]) do |connection_type, quick_code| connection_type.eql?('a') > quick_code.filled? end - rule(uuid_presence: %i(connection_type uuid)) do |connection_type, uuid| + rule(uuid_presence: %i[connection_type uuid]) do |connection_type, uuid| connection_type.eql?('b') > uuid.filled? end end