validation_matcher 3.2.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +36 -0
- data/.rubocop.yml +17 -0
- data/.rubocop_todo.yml +16 -0
- data/Dockerfile +17 -0
- data/Gemfile +3 -7
- data/Rakefile +3 -1
- data/docker-compose.yml +38 -0
- data/lib/validation_matcher.rb +48 -34
- data/lib/validation_matcher/version.rb +5 -1
- data/spec/spec_helper.rb +4 -0
- data/spec/thing_spec.rb +34 -10
- data/validation_matcher.gemspec +8 -4
- metadata +37 -6
- data/.travis.yml +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44aea0bbd6d53fd36664be6e5f80d2f42d4b7dca
|
4
|
+
data.tar.gz: d2a20e572b8ed5e999cb54324bd8fe8770727b8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f00bd4e341890244dfbd9f7e154fb3b8df854aabf0a02a981e438e3b5ef61311fd3d4801eed0c91deab0c539455571bc2ec7608c1cf8e0b8bd91c8a6065cdac5
|
7
|
+
data.tar.gz: cdd896f57cf72f9c32755f5e90e939c3979d5063c89d88e1776baec4cd936dfb551f1ec9b47ec6afbe90aa97a908df7dd115ce2b940ea33f7acaa85a386bf9c8
|
data/.gitlab-ci.yml
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
stages:
|
2
|
+
- style
|
3
|
+
- specs
|
4
|
+
|
5
|
+
.ruby: &ruby
|
6
|
+
before_script: ["bundle install"]
|
7
|
+
cache:
|
8
|
+
key: "$CI_COMMIT_REF_NAME"
|
9
|
+
paths: ["vendor/bundle"]
|
10
|
+
image: devfu/ci:2.4-alpine
|
11
|
+
variables:
|
12
|
+
BUNDLE_CLEAN: "true"
|
13
|
+
BUNDLE_JOBS: "$(nproc)"
|
14
|
+
BUNDLE_PATH: "vendor/bundle"
|
15
|
+
BUNDLE_RETRY: "3"
|
16
|
+
BUNDLE_WITHOUT: "production,staging"
|
17
|
+
|
18
|
+
#
|
19
|
+
# style
|
20
|
+
#
|
21
|
+
|
22
|
+
rubocop:
|
23
|
+
<<: *ruby
|
24
|
+
except: [tags]
|
25
|
+
script: ["rubocop"]
|
26
|
+
stage: style
|
27
|
+
|
28
|
+
#
|
29
|
+
# specs
|
30
|
+
#
|
31
|
+
|
32
|
+
rspec:
|
33
|
+
<<: *ruby
|
34
|
+
except: [tags]
|
35
|
+
script: ["rake spec"]
|
36
|
+
stage: specs
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.4
|
3
|
+
DisplayCopNames: true
|
4
|
+
DisplayStyleGuide: true
|
5
|
+
ExtraDetails: true
|
6
|
+
Exclude:
|
7
|
+
- Gemfile.lock
|
8
|
+
- vendor/**/*
|
9
|
+
|
10
|
+
inherit_from:
|
11
|
+
- .rubocop_todo.yml
|
12
|
+
|
13
|
+
inherit_gem:
|
14
|
+
yoshiki: .devfu-rubocop.yml
|
15
|
+
|
16
|
+
Style/Documentation:
|
17
|
+
Enabled: false
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# This configuration was generated by
|
2
|
+
# `rubocop --auto-gen-config`
|
3
|
+
# on 2017-08-28 06:11:21 +0000 using RuboCop version 0.49.1.
|
4
|
+
# The point is for the user to remove these configuration records
|
5
|
+
# one by one as the offenses are removed from the code base.
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
8
|
+
|
9
|
+
# Offense count: 2
|
10
|
+
Metrics/AbcSize:
|
11
|
+
Max: 19
|
12
|
+
|
13
|
+
# Offense count: 1
|
14
|
+
# Configuration parameters: CountComments.
|
15
|
+
Metrics/MethodLength:
|
16
|
+
Max: 13
|
data/Dockerfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
FROM devfu/ci:2.4-alpine
|
2
|
+
|
3
|
+
ENV app /src
|
4
|
+
ENV BUNDLE_NO_PRUNE true
|
5
|
+
ENV BUNDLE_PATH /bundle
|
6
|
+
RUN bundle config jobs $(nproc)
|
7
|
+
|
8
|
+
# Copy the bundle config
|
9
|
+
# COPY .bundle/config /usr/local/bundle/config
|
10
|
+
|
11
|
+
RUN mkdir $app
|
12
|
+
WORKDIR $app
|
13
|
+
ADD . $app
|
14
|
+
|
15
|
+
VOLUME /bundle
|
16
|
+
|
17
|
+
CMD bundle console
|
data/Gemfile
CHANGED
@@ -1,10 +1,6 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
# Specify your gem's dependencies in validation_matcher.gemspec
|
4
|
-
gemspec :
|
5
|
-
|
6
|
-
group :development do
|
7
|
-
# install the appropriate pry debug tool
|
8
|
-
gem 'pry-byebug', require: false, platform: 'ruby_20'
|
9
|
-
gem 'pry-debugger', require: false, platform: 'ruby_19'
|
10
|
-
end
|
6
|
+
gemspec development_group: :test
|
data/Rakefile
CHANGED
data/docker-compose.yml
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
version: '3'
|
2
|
+
|
3
|
+
services:
|
4
|
+
ruby:
|
5
|
+
build: .
|
6
|
+
volumes: &ruby_volumes
|
7
|
+
- .:/src:cached
|
8
|
+
- gems:/bundle:cached
|
9
|
+
|
10
|
+
#
|
11
|
+
# fake binstubs with additional services
|
12
|
+
#
|
13
|
+
|
14
|
+
# docker-compose run bundle [cmd]
|
15
|
+
bundle:
|
16
|
+
build: .
|
17
|
+
command: check
|
18
|
+
entrypoint: ["bundle"]
|
19
|
+
volumes: *ruby_volumes
|
20
|
+
|
21
|
+
# docker-compose run rake [task]
|
22
|
+
rake:
|
23
|
+
build: .
|
24
|
+
command: spec
|
25
|
+
entrypoint: ["bundle", "exec", "rake"]
|
26
|
+
volumes: *ruby_volumes
|
27
|
+
|
28
|
+
# docker-compose run rspec [pattern]
|
29
|
+
rspec:
|
30
|
+
build: .
|
31
|
+
command: spec
|
32
|
+
entrypoint: ["bundle", "exec", "rspec"]
|
33
|
+
volumes: *ruby_volumes
|
34
|
+
|
35
|
+
volumes:
|
36
|
+
gems:
|
37
|
+
external:
|
38
|
+
name: docker-gems
|
data/lib/validation_matcher.rb
CHANGED
@@ -1,56 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'validation_matcher/version'
|
2
4
|
require 'rspec/expectations'
|
3
5
|
|
4
6
|
module ValidationMatcher
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
attr_reader :validator
|
8
|
+
RSpec::Matchers.define :validate do |_expected|
|
9
|
+
chain(:of) { |attr| @attribute = attr }
|
9
10
|
|
10
|
-
|
11
|
-
@
|
11
|
+
chain(:with) do |*opts|
|
12
|
+
@options = opts.extract_options!
|
13
|
+
@options = opts if @options.empty?
|
12
14
|
end
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
match do |_actual|
|
17
|
+
if @attribute
|
18
|
+
validator.present? && (@options ? validator.options.should =~ @options : true)
|
19
|
+
else
|
20
|
+
callback.present? && (@options ? check_callback_options : true)
|
21
|
+
end
|
19
22
|
end
|
20
23
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
24
|
+
match_when_negated do |_actual|
|
25
|
+
if @attribute
|
26
|
+
raise "Negating a matcher with options doesn't really make sense!" if @options
|
27
|
+
validator.should be_nil
|
28
|
+
else
|
29
|
+
callback.should be_nil
|
30
|
+
end
|
31
|
+
end
|
25
32
|
|
26
|
-
|
27
|
-
|
33
|
+
def callback
|
34
|
+
actual.class._validate_callbacks.detect { |c| c.filter == expected }
|
35
|
+
end
|
28
36
|
|
29
|
-
|
30
|
-
|
31
|
-
@expected_validator = expected.first
|
37
|
+
def check_callback_options
|
38
|
+
opts = parse_callback_options
|
32
39
|
|
33
|
-
|
40
|
+
if @options.is_a? Hash
|
41
|
+
raise 'Cannot expect custom procs' if @options.values.any? { |v| v.is_a? Proc }
|
42
|
+
@options.each { |k, _| opts[k].should =~ Array(@options[k]) }
|
43
|
+
else
|
44
|
+
opts.keys.should =~ @options
|
45
|
+
end
|
34
46
|
end
|
35
47
|
|
36
|
-
def
|
37
|
-
|
38
|
-
end
|
48
|
+
def parse_callback_options
|
49
|
+
ifs = callback.instance_variable_get '@if'
|
39
50
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
51
|
+
if ifs.first.is_a? Proc
|
52
|
+
proc_binding = ifs.first.binding
|
53
|
+
if proc_binding.local_variables.include? :options
|
54
|
+
ons = proc_binding.local_variable_get(:options)[:on]
|
55
|
+
ifs = ifs[1..-1]
|
56
|
+
end
|
57
|
+
end
|
45
58
|
|
46
|
-
|
47
|
-
|
59
|
+
{
|
60
|
+
if: Array(ifs),
|
61
|
+
on: Array(ons),
|
62
|
+
unless: Array(callback.instance_variable_get('@unless'))
|
63
|
+
}.reject { |_, v| v.empty? }
|
48
64
|
end
|
49
65
|
|
50
|
-
def validator
|
51
|
-
|
52
|
-
validator.kind == expected_validator && validator.options == expected_options
|
53
|
-
end
|
66
|
+
def validator
|
67
|
+
actual.class.validators_on(@attribute).detect { |v| v.kind == expected }
|
54
68
|
end
|
55
69
|
end
|
56
70
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
libs = %w[
|
2
4
|
active_model
|
3
5
|
active_support/core_ext
|
@@ -38,6 +40,8 @@ class Thing
|
|
38
40
|
validates :field_c, numericality: { allow_nil: false, only_integer: true }
|
39
41
|
|
40
42
|
validate :custom_validator
|
43
|
+
validate :another_custom_validator, on: :update
|
44
|
+
validate :procs_cannot_be_speced, if: -> { new_record? }
|
41
45
|
|
42
46
|
private
|
43
47
|
|
data/spec/thing_spec.rb
CHANGED
@@ -1,23 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Thing do
|
4
6
|
|
5
7
|
describe 'each validators' do
|
6
8
|
|
7
|
-
describe '
|
9
|
+
describe 'with options' do
|
8
10
|
|
9
|
-
it
|
10
|
-
|
11
|
+
it 'can be expected without specifying options' do
|
12
|
+
should validate(:numericality).of :field_c
|
13
|
+
end
|
11
14
|
|
12
|
-
it
|
15
|
+
it 'can be expected with specified options' do
|
16
|
+
should validate(:numericality).of(:field_c).with only_integer: true, allow_nil: false
|
17
|
+
end
|
13
18
|
|
14
|
-
|
19
|
+
it 'cannot be negated with specified options' do
|
20
|
+
lambda do
|
21
|
+
opts = { only_integer: false }
|
22
|
+
should_not validate(:numericality).of(:field_c).with opts
|
23
|
+
end.should raise_exception RuntimeError
|
24
|
+
end
|
15
25
|
|
16
|
-
|
26
|
+
end
|
17
27
|
|
18
|
-
|
28
|
+
describe 'without options' do
|
19
29
|
|
20
|
-
it {
|
30
|
+
it { should_not validate(:presence).of :field_a }
|
31
|
+
it { should validate(:presence).of :field_b }
|
21
32
|
|
22
33
|
end
|
23
34
|
|
@@ -28,13 +39,26 @@ describe Thing do
|
|
28
39
|
describe 'without options' do
|
29
40
|
|
30
41
|
it { should validate :custom_validator }
|
42
|
+
it { should validate :another_custom_validator }
|
31
43
|
|
32
44
|
end
|
33
45
|
|
34
46
|
describe 'with options' do
|
35
47
|
|
36
|
-
it
|
37
|
-
|
48
|
+
it { should validate(:another_custom_validator).with on: :update }
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'with a proc' do
|
53
|
+
|
54
|
+
it 'cannot be specced by key & value' do
|
55
|
+
lambda do
|
56
|
+
should validate(:procs_cannot_be_speced).with if: -> { new_record? }
|
57
|
+
end.should raise_exception RuntimeError
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'can be specced by key ONLY' do
|
61
|
+
should validate(:procs_cannot_be_speced).with :if
|
38
62
|
end
|
39
63
|
|
40
64
|
end
|
data/validation_matcher.gemspec
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
3
5
|
require 'validation_matcher/version'
|
4
6
|
|
5
7
|
Gem::Specification.new do |s|
|
@@ -7,7 +9,7 @@ Gem::Specification.new do |s|
|
|
7
9
|
s.version = ValidationMatcher::VERSION
|
8
10
|
s.authors = ['BM5k']
|
9
11
|
s.email = ['me@bm5k.com']
|
10
|
-
s.homepage =
|
12
|
+
s.homepage = ''
|
11
13
|
s.summary = 'RSpec matcher for ActiveModel validations'
|
12
14
|
s.description = 'Use reflection to spec ActiveModel validations'
|
13
15
|
s.licenses = ['MIT']
|
@@ -16,16 +18,18 @@ Gem::Specification.new do |s|
|
|
16
18
|
|
17
19
|
s.files = `git ls-files`.split("\n")
|
18
20
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename f }
|
20
22
|
s.require_paths = ['lib']
|
21
23
|
|
22
|
-
s.required_ruby_version = '>= 2.1'
|
24
|
+
s.required_ruby_version = '>= 2.4.1'
|
23
25
|
|
24
26
|
s.add_dependency 'rspec-expectations', '~> 3.1'
|
25
27
|
|
26
28
|
s.add_development_dependency 'activemodel', '>= 3'
|
27
29
|
s.add_development_dependency 'pry'
|
28
30
|
s.add_development_dependency 'pry-doc'
|
31
|
+
s.add_development_dependency 'pry-byebug'
|
29
32
|
s.add_development_dependency 'rake'
|
30
33
|
s.add_development_dependency 'rspec'
|
34
|
+
s.add_development_dependency 'yoshiki'
|
31
35
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validation_matcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- BM5k
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-expectations
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rake
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +108,20 @@ dependencies:
|
|
94
108
|
- - ">="
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: yoshiki
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
97
125
|
description: Use reflection to spec ActiveModel validations
|
98
126
|
email:
|
99
127
|
- me@bm5k.com
|
@@ -102,12 +130,16 @@ extensions: []
|
|
102
130
|
extra_rdoc_files: []
|
103
131
|
files:
|
104
132
|
- ".gitignore"
|
133
|
+
- ".gitlab-ci.yml"
|
105
134
|
- ".rspec"
|
106
|
-
- ".
|
135
|
+
- ".rubocop.yml"
|
136
|
+
- ".rubocop_todo.yml"
|
137
|
+
- Dockerfile
|
107
138
|
- Gemfile
|
108
139
|
- LICENSE
|
109
140
|
- README.md
|
110
141
|
- Rakefile
|
142
|
+
- docker-compose.yml
|
111
143
|
- lib/validation_matcher.rb
|
112
144
|
- lib/validation_matcher/version.rb
|
113
145
|
- spec/spec_helper.rb
|
@@ -125,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
157
|
requirements:
|
126
158
|
- - ">="
|
127
159
|
- !ruby/object:Gem::Version
|
128
|
-
version:
|
160
|
+
version: 2.4.1
|
129
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
162
|
requirements:
|
131
163
|
- - ">="
|
@@ -133,11 +165,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
165
|
version: '0'
|
134
166
|
requirements: []
|
135
167
|
rubyforge_project: validation_matcher
|
136
|
-
rubygems_version: 2.
|
168
|
+
rubygems_version: 2.6.11
|
137
169
|
signing_key:
|
138
170
|
specification_version: 4
|
139
171
|
summary: RSpec matcher for ActiveModel validations
|
140
172
|
test_files:
|
141
173
|
- spec/spec_helper.rb
|
142
174
|
- spec/thing_spec.rb
|
143
|
-
has_rdoc:
|