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: 3c6a528b8c7f28bf7e55be370d295788d6fef1c2de8c0802520aa4c53db46d33
4
- data.tar.gz: 30373e7af37519724176b32ec36c645ce1f15cd0e5e33635127af2967013aad5
3
+ metadata.gz: 439c18f7d1952192bf309d571c0f8b8a36d75409bc7f3cdafcad6c765387a198
4
+ data.tar.gz: dbb77ae1dab7d97d995b4c5dae464506453cfd302a4aa7355aa3bc6b88ed3a4a
5
5
  SHA512:
6
- metadata.gz: 2abb2cf439761505b6af1eb318179cb1be69effdab3fc34170de1be6636d3fb22585fc21a58ed20170a81a0b0438dc67ebb4463149632d6badb0f01224a1906e
7
- data.tar.gz: 4b4e9c3bc47e3add4e47b51868835831eafaae9c8480156285387ca638eb84c4eab796db90c4ee323181ee4b59aec1806390ed680f51fd3a08def48faac075e2
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
@@ -7,7 +7,7 @@ module Validator
7
7
  module VERSION
8
8
  MAJOR = 0
9
9
  MINOR = 0
10
- PATCH = 1
10
+ PATCH = 2
11
11
 
12
12
  STRING = [MAJOR, MINOR, PATCH].join('.')
13
13
  end
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.1
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-24 00:00:00.000000000 Z
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.1
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.1
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: