validator-matchers 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +58 -0
- data/CHANGELOG.md +9 -0
- data/LICENSE.md +21 -0
- data/README.md +9 -0
- data/lib/validator-matchers.rb +1 -0
- data/lib/validator/matchers.rb +21 -0
- data/lib/validator/matchers/validator_spec_helper.rb +71 -0
- data/lib/validator/matchers/version.rb +15 -0
- data/validator-matchers.gemspec +38 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c29cace69abe0fc863bdb4324cbf72449dbbe4eedd4cf519f7533005922ee055
|
4
|
+
data.tar.gz: 678704e042afb52ce86ae4f65a8b8d2dc85dd554ce6c4f2d5162d32097981f05
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1e58df1c84692e0d70abf43cc0f7f465ffafd474491d41d005d2b394a84402dc74bdcde64169ef1b0c7714da15817de3f2ca5123e8f6af3ef1fb7382aa25bda5
|
7
|
+
data.tar.gz: 51f1f8ad240b36b21b2d9914d45dc0cd8ded26df77bbdb1733be3f3cd6aa3d8beaac8df5bc22c134e6c09fd0d5cf4db6d0ff1b4359d17823c23f426c570ae650
|
data/.gitignore
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# TODO: This is just the default .gitignore, should probably be fine-tuned
|
2
|
+
|
3
|
+
*.gem
|
4
|
+
*.rbc
|
5
|
+
/.config
|
6
|
+
/coverage/
|
7
|
+
/InstalledFiles
|
8
|
+
/pkg/
|
9
|
+
/spec/reports/
|
10
|
+
/spec/examples.txt
|
11
|
+
/test/tmp/
|
12
|
+
/test/version_tmp/
|
13
|
+
/tmp/
|
14
|
+
|
15
|
+
# Used by dotenv library to load environment variables.
|
16
|
+
# .env
|
17
|
+
|
18
|
+
# Ignore Byebug command history file.
|
19
|
+
.byebug_history
|
20
|
+
|
21
|
+
## Specific to RubyMotion:
|
22
|
+
.dat*
|
23
|
+
.repl_history
|
24
|
+
build/
|
25
|
+
*.bridgesupport
|
26
|
+
build-iPhoneOS/
|
27
|
+
build-iPhoneSimulator/
|
28
|
+
|
29
|
+
## Specific to RubyMotion (use of CocoaPods):
|
30
|
+
#
|
31
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
32
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
33
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
34
|
+
#
|
35
|
+
# vendor/Pods/
|
36
|
+
|
37
|
+
## Documentation cache and generated files:
|
38
|
+
/.yardoc/
|
39
|
+
/_yardoc/
|
40
|
+
/doc/
|
41
|
+
/rdoc/
|
42
|
+
|
43
|
+
## Environment normalization:
|
44
|
+
/.bundle/
|
45
|
+
/vendor/bundle
|
46
|
+
/lib/bundler/man/
|
47
|
+
|
48
|
+
# for a library or gem, you might want to ignore these files since the code is
|
49
|
+
# intended to run in multiple environments; otherwise, check them in:
|
50
|
+
# Gemfile.lock
|
51
|
+
# .ruby-version
|
52
|
+
# .ruby-gemset
|
53
|
+
|
54
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
55
|
+
.rvmrc
|
56
|
+
|
57
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
58
|
+
# .rubocop-https?--*
|
data/CHANGELOG.md
ADDED
data/LICENSE.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 [Josh Buker](mailto:crypto@joshbuker.com)
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# RSpec Validator Matchers
|
2
|
+
|
3
|
+
Inspired by the following:
|
4
|
+
|
5
|
+
* [Stack Overflow post](https://stackoverflow.com/questions/7744171/how-to-test-a-custom-validator)
|
6
|
+
* [shoulda-matchers](https://github.com/thoughtbot/shoulda-matchers)
|
7
|
+
* [pundit-matchers](https://github.com/chrisalley/pundit-matchers)
|
8
|
+
* [izumin5210/rspec-validator_spec_helper](https://github.com/izumin5210/rspec-validator_spec_helper).
|
9
|
+
* [RSpec DynamicPredicate](https://github.com/rspec/rspec-expectations/blob/master/lib/rspec/matchers/built_in/has.rb)
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'validator/matchers'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rspec/core'
|
2
|
+
|
3
|
+
module Validator
|
4
|
+
module Matchers
|
5
|
+
autoload :VERSION, 'validator/matchers/version'
|
6
|
+
# autoload :ModelSpecHelper, 'validator/matchers/model_spec_helper'
|
7
|
+
autoload :ValidatorSpecHelper, 'validator/matchers/validator_spec_helper'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
##
|
12
|
+
# Automatically configure RSpec to support validator specs.
|
13
|
+
#
|
14
|
+
RSpec.configure do |config|
|
15
|
+
config.define_derived_metadata(file_path: %r{/spec/validators/}) do |metadata|
|
16
|
+
metadata[:type] = :validator
|
17
|
+
end
|
18
|
+
|
19
|
+
# config.include Validator::Matchers::ModelSpecHelper, type: :model
|
20
|
+
config.include Validator::Matchers::ValidatorSpecHelper, type: :validator
|
21
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Validator
|
2
|
+
module Matchers
|
3
|
+
# TODO: Document and cleanup.
|
4
|
+
module ValidatorSpecHelper
|
5
|
+
DEFAULT_ATTRIBUTE_NAME = :value
|
6
|
+
|
7
|
+
# Auto extend validator specs when included
|
8
|
+
def self.included(base)
|
9
|
+
base.instance_eval do
|
10
|
+
let(:validator_name) do
|
11
|
+
RSpec.current_example.full_description.match(/\A[\w:]+Validator/)[0]
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:validator_class) { Object.const_get(validator_name) }
|
15
|
+
|
16
|
+
let(:validator_type) do
|
17
|
+
if validator_class.ancestors.include? ActiveModel::EachValidator
|
18
|
+
ActiveModel::EachValidator
|
19
|
+
else
|
20
|
+
ActiveModel::Validator
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:validation_name) do
|
25
|
+
validator_name.underscore.gsub(/_validator\Z/, '')
|
26
|
+
end
|
27
|
+
|
28
|
+
let(:attribute_names) { [DEFAULT_ATTRIBUTE_NAME] }
|
29
|
+
|
30
|
+
let(DEFAULT_ATTRIBUTE_NAME) { nil }
|
31
|
+
|
32
|
+
let(:options) { nil }
|
33
|
+
|
34
|
+
# This smells like it can be extracted into two objects.
|
35
|
+
let(:model_class) do
|
36
|
+
example_group = self
|
37
|
+
Struct.new(*attribute_names) do
|
38
|
+
include ActiveModel::Validations
|
39
|
+
|
40
|
+
def self.name
|
41
|
+
'ValidatorModelMock'
|
42
|
+
end
|
43
|
+
|
44
|
+
if example_group.validator_type == ActiveModel::EachValidator
|
45
|
+
args =
|
46
|
+
{
|
47
|
+
example_group.validation_name.to_sym => (
|
48
|
+
example_group.options || true
|
49
|
+
)
|
50
|
+
}
|
51
|
+
validates DEFAULT_ATTRIBUTE_NAME, args
|
52
|
+
else
|
53
|
+
if example_group.options.nil?
|
54
|
+
validates_with example_group.validator_class
|
55
|
+
else
|
56
|
+
validates_with example_group.validator_class,
|
57
|
+
example_group.options
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
let(:validator_model_mock) do
|
64
|
+
attributes = attribute_names.map { |name| eval("#{name}") }
|
65
|
+
model_class.new(*attributes)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'validator/matchers/version'
|
6
|
+
|
7
|
+
version = Validator::Matchers::VERSION::STRING
|
8
|
+
gem_name = 'validator-matchers'
|
9
|
+
repo_url = "https://github.com/athix/#{gem_name}"
|
10
|
+
|
11
|
+
Gem::Specification.new do |s|
|
12
|
+
s.version = version
|
13
|
+
s.platform = Gem::Platform::RUBY
|
14
|
+
s.name = gem_name
|
15
|
+
s.summary = 'RSpec matchers for your custom validator unit testing'
|
16
|
+
# TODO: More descriptive description.
|
17
|
+
# s.description = 'RSpec matchers for your custom validator unit testing'
|
18
|
+
|
19
|
+
s.required_ruby_version = '>= 2.5.0'
|
20
|
+
|
21
|
+
s.license = 'MIT'
|
22
|
+
s.author = 'Josh Buker'
|
23
|
+
s.email = 'crypto@joshbuker.com'
|
24
|
+
s.homepage = repo_url
|
25
|
+
s.metadata = {
|
26
|
+
'bug_tracker_uri' => "#{repo_url}/issues",
|
27
|
+
'changelog_uri' => "#{repo_url}/releases/tag/v#{version}",
|
28
|
+
'documentation_uri' => "https://rubydoc.info/gems/#{gem_name}",
|
29
|
+
'source_code_uri' => "#{repo_url}/tree/v#{version}"
|
30
|
+
}
|
31
|
+
|
32
|
+
s.files = `git ls-files -z`.split("\x0")
|
33
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
34
|
+
|
35
|
+
s.require_paths = ['lib']
|
36
|
+
|
37
|
+
s.add_dependency 'rspec-rails', '>= 3.0', '< 6'
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: validator-matchers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Josh Buker
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-04-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec-rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '6'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '3.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '6'
|
33
|
+
description:
|
34
|
+
email: crypto@joshbuker.com
|
35
|
+
executables: []
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files: []
|
38
|
+
files:
|
39
|
+
- ".gitignore"
|
40
|
+
- CHANGELOG.md
|
41
|
+
- LICENSE.md
|
42
|
+
- README.md
|
43
|
+
- lib/validator-matchers.rb
|
44
|
+
- lib/validator/matchers.rb
|
45
|
+
- lib/validator/matchers/validator_spec_helper.rb
|
46
|
+
- lib/validator/matchers/version.rb
|
47
|
+
- validator-matchers.gemspec
|
48
|
+
homepage: https://github.com/athix/validator-matchers
|
49
|
+
licenses:
|
50
|
+
- MIT
|
51
|
+
metadata:
|
52
|
+
bug_tracker_uri: https://github.com/athix/validator-matchers/issues
|
53
|
+
changelog_uri: https://github.com/athix/validator-matchers/releases/tag/v0.0.0
|
54
|
+
documentation_uri: https://rubydoc.info/gems/validator-matchers
|
55
|
+
source_code_uri: https://github.com/athix/validator-matchers/tree/v0.0.0
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 2.5.0
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubygems_version: 3.1.2
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: RSpec matchers for your custom validator unit testing
|
75
|
+
test_files: []
|