validator-matchers 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 439c18f7d1952192bf309d571c0f8b8a36d75409bc7f3cdafcad6c765387a198
|
4
|
+
data.tar.gz: dbb77ae1dab7d97d995b4c5dae464506453cfd302a4aa7355aa3bc6b88ed3a4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cac5a39393a8c6fa6ace485a8c1163bd8e3e0b7838cdbe0cc60615f865b59328e817e35b04c28f37479e01db7574c2845c0f7144282e8a8d8c7a30138116500
|
7
|
+
data.tar.gz: c87a2bc3961aae7197e113546f0bcd263be587285c37a1321a44430e7a44dcc4564dd90fa1acc71710fa842142362e099b1643203a264c21c8d9882c8d8e1b80
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,11 @@ Historical changelog for all versions.
|
|
4
4
|
|
5
5
|
## HEAD
|
6
6
|
|
7
|
+
## v0.0.2
|
8
|
+
|
9
|
+
* Add respond_to_missing? method to ModelSpecHelper
|
10
|
+
* Add have_validation_error matcher to ValidatorSpecHelper
|
11
|
+
|
7
12
|
## v0.0.1
|
8
13
|
|
9
14
|
* Added initial model spec helpers, needs further testing and code cleanup
|
@@ -6,12 +6,17 @@ module Validator
|
|
6
6
|
|
7
7
|
def self.included(base)
|
8
8
|
base.class_eval do
|
9
|
+
def respond_to_missing?(method_name, *)
|
10
|
+
(method_name =~ VALIDATOR_REGEX) || super
|
11
|
+
end
|
12
|
+
|
9
13
|
def method_missing(method_name, *args, &block)
|
10
14
|
if regex = method_name.to_s.match(VALIDATOR_REGEX)
|
15
|
+
validator_name = regex[1]
|
16
|
+
validator_class_name = validator_name.camelcase + 'Validator'
|
17
|
+
|
11
18
|
RSpec::Matchers.define method_name do |dynamic_matcher|
|
12
19
|
match do |model|
|
13
|
-
validator_name = regex[1]
|
14
|
-
validator_class_name = validator_name.camelcase + 'Validator'
|
15
20
|
model_validators =
|
16
21
|
model._validators[args.first].map{ |v| v.class.to_s }
|
17
22
|
model_validators.include?(validator_class_name)
|
@@ -4,6 +4,14 @@ module Validator
|
|
4
4
|
module ValidatorSpecHelper
|
5
5
|
DEFAULT_ATTRIBUTE_NAME = :value
|
6
6
|
|
7
|
+
# TODO: Add support for: `have_validation_error('is bad').on(:attribute)`
|
8
|
+
RSpec::Matchers.define :have_validation_error do |matcher|
|
9
|
+
match do |model|
|
10
|
+
model.valid? # Populate errors array
|
11
|
+
model.errors[DEFAULT_ATTRIBUTE_NAME].include?(matcher)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
7
15
|
# Auto extend validator specs when included
|
8
16
|
def self.included(base)
|
9
17
|
base.instance_eval do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validator-matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Buker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec-rails
|
@@ -51,9 +51,9 @@ licenses:
|
|
51
51
|
- MIT
|
52
52
|
metadata:
|
53
53
|
bug_tracker_uri: https://github.com/athix/validator-matchers/issues
|
54
|
-
changelog_uri: https://github.com/athix/validator-matchers/releases/tag/v0.0.
|
54
|
+
changelog_uri: https://github.com/athix/validator-matchers/releases/tag/v0.0.2
|
55
55
|
documentation_uri: https://rubydoc.info/gems/validator-matchers
|
56
|
-
source_code_uri: https://github.com/athix/validator-matchers/tree/v0.0.
|
56
|
+
source_code_uri: https://github.com/athix/validator-matchers/tree/v0.0.2
|
57
57
|
post_install_message:
|
58
58
|
rdoc_options: []
|
59
59
|
require_paths:
|