validator-matchers 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +1 -1
- data/lib/validator/matchers.rb +2 -2
- data/lib/validator/matchers/model_spec_helper.rb +44 -0
- data/lib/validator/matchers/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c6a528b8c7f28bf7e55be370d295788d6fef1c2de8c0802520aa4c53db46d33
|
4
|
+
data.tar.gz: 30373e7af37519724176b32ec36c645ce1f15cd0e5e33635127af2967013aad5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2abb2cf439761505b6af1eb318179cb1be69effdab3fc34170de1be6636d3fb22585fc21a58ed20170a81a0b0438dc67ebb4463149632d6badb0f01224a1906e
|
7
|
+
data.tar.gz: 4b4e9c3bc47e3add4e47b51868835831eafaae9c8480156285387ca638eb84c4eab796db90c4ee323181ee4b59aec1806390ed680f51fd3a08def48faac075e2
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,10 @@ Historical changelog for all versions.
|
|
4
4
|
|
5
5
|
## HEAD
|
6
6
|
|
7
|
+
## v0.0.1
|
8
|
+
|
9
|
+
* Added initial model spec helpers, needs further testing and code cleanup
|
10
|
+
|
7
11
|
## v0.0.0
|
8
12
|
|
9
13
|
* Initial helpers with autoloading for validator specs (heavily based on [izumin5210/rspec-validator_spec_helper](https://github.com/izumin5210/rspec-validator_spec_helper))
|
data/README.md
CHANGED
@@ -6,4 +6,4 @@ Inspired by the following:
|
|
6
6
|
* [shoulda-matchers](https://github.com/thoughtbot/shoulda-matchers)
|
7
7
|
* [pundit-matchers](https://github.com/chrisalley/pundit-matchers)
|
8
8
|
* [izumin5210/rspec-validator_spec_helper](https://github.com/izumin5210/rspec-validator_spec_helper).
|
9
|
-
* [RSpec DynamicPredicate](https://github.com/rspec/rspec-expectations/blob/
|
9
|
+
* [RSpec DynamicPredicate](https://github.com/rspec/rspec-expectations/blob/main/lib/rspec/matchers/built_in/has.rb)
|
data/lib/validator/matchers.rb
CHANGED
@@ -3,7 +3,7 @@ require 'rspec/core'
|
|
3
3
|
module Validator
|
4
4
|
module Matchers
|
5
5
|
autoload :VERSION, 'validator/matchers/version'
|
6
|
-
|
6
|
+
autoload :ModelSpecHelper, 'validator/matchers/model_spec_helper'
|
7
7
|
autoload :ValidatorSpecHelper, 'validator/matchers/validator_spec_helper'
|
8
8
|
end
|
9
9
|
end
|
@@ -16,6 +16,6 @@ RSpec.configure do |config|
|
|
16
16
|
metadata[:type] = :validator
|
17
17
|
end
|
18
18
|
|
19
|
-
|
19
|
+
config.include Validator::Matchers::ModelSpecHelper, type: :model
|
20
20
|
config.include Validator::Matchers::ValidatorSpecHelper, type: :validator
|
21
21
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Validator
|
2
|
+
module Matchers
|
3
|
+
# FIXME: This is really brittle, and poorly written in general. Will replace shortly.
|
4
|
+
module ModelSpecHelper
|
5
|
+
VALIDATOR_REGEX = %r{^(?:validate_)(.+)_of}
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
base.class_eval do
|
9
|
+
def method_missing(method_name, *args, &block)
|
10
|
+
if regex = method_name.to_s.match(VALIDATOR_REGEX)
|
11
|
+
RSpec::Matchers.define method_name do |dynamic_matcher|
|
12
|
+
match do |model|
|
13
|
+
validator_name = regex[1]
|
14
|
+
validator_class_name = validator_name.camelcase + 'Validator'
|
15
|
+
model_validators =
|
16
|
+
model._validators[args.first].map{ |v| v.class.to_s }
|
17
|
+
model_validators.include?(validator_class_name)
|
18
|
+
end
|
19
|
+
|
20
|
+
failure_message do |model|
|
21
|
+
model.class.to_s + ' does not ' +
|
22
|
+
method_name.to_s.humanize.downcase + ' :' + args.first.to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
failure_message_when_negated do |model|
|
26
|
+
model.class.to_s + ' does ' +
|
27
|
+
method_name.to_s.humanize.downcase + ' :' + args.first.to_s
|
28
|
+
end
|
29
|
+
|
30
|
+
description do |model|
|
31
|
+
method_name.to_s.humanize.downcase + ' :' + args.first.to_s
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
self.__send__(method_name, args, block)
|
36
|
+
else
|
37
|
+
super
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Buker
|
@@ -42,6 +42,7 @@ files:
|
|
42
42
|
- README.md
|
43
43
|
- lib/validator-matchers.rb
|
44
44
|
- lib/validator/matchers.rb
|
45
|
+
- lib/validator/matchers/model_spec_helper.rb
|
45
46
|
- lib/validator/matchers/validator_spec_helper.rb
|
46
47
|
- lib/validator/matchers/version.rb
|
47
48
|
- validator-matchers.gemspec
|
@@ -50,9 +51,9 @@ licenses:
|
|
50
51
|
- MIT
|
51
52
|
metadata:
|
52
53
|
bug_tracker_uri: https://github.com/athix/validator-matchers/issues
|
53
|
-
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.1
|
54
55
|
documentation_uri: https://rubydoc.info/gems/validator-matchers
|
55
|
-
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.1
|
56
57
|
post_install_message:
|
57
58
|
rdoc_options: []
|
58
59
|
require_paths:
|