Update to: hanami-utils v1.1.0.beta2, dry-validation 0.11, hanami-devtools, rubocop 0.50.0

This commit is contained in:
Luca Guidi 2017-10-03 11:22:02 +02:00
parent 6282fcf77c
commit 1b4ae84741
No known key found for this signature in database
GPG Key ID: 391CF49D12B24CC2
18 changed files with 121 additions and 76 deletions

2
.gitignore vendored
View File

@ -13,4 +13,4 @@
*.a
mkmf.log
.greenbar
.rubocop-https---raw-githubusercontent-com-hanami-hanami-master--rubocop-yml
.rubocop-*yml

View File

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

View File

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

View File

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

View File

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

View File

@ -1 +1 @@
require 'hanami/validations' # rubocop:disable Style/FileName
require 'hanami/validations' # rubocop:disable Naming/FileName

View File

@ -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[
%<root>s.%<rule>s.%<predicate>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

51
script/ci Executable file
View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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