validation_matcher 0.1.0 → 0.1.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.
- data/lib/validation_matcher/version.rb +1 -1
- data/lib/validation_matcher.rb +23 -25
- data/validation_matcher.gemspec +1 -0
- metadata +18 -4
- data/spec/matchers_spec.rb +0 -9
data/lib/validation_matcher.rb
CHANGED
@@ -4,45 +4,43 @@ module ValidationMatcher
|
|
4
4
|
|
5
5
|
RSpec::Matchers.define :validate do |kind|
|
6
6
|
|
7
|
-
chain(:of) { |field| @field
|
8
|
-
chain(:with) { |hash| @
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
# Attempts to find the selected validator
|
16
|
-
#
|
17
|
-
# @param [Symbol] kind the type of validator we're looking for
|
18
|
-
def find_validator kind
|
19
|
-
described_class.validators_on(@field).detect { |v| v.kind == kind }
|
7
|
+
chain(:of) { |field| @field = field }
|
8
|
+
chain(:with) { |hash| @expected_options = hash }
|
9
|
+
|
10
|
+
def options_message
|
11
|
+
return '' unless diff.present?
|
12
|
+
str = "\n expected options: " + @expected_options.inspect
|
13
|
+
str << "\n actual options: " + validator_options.inspect
|
14
|
+
str
|
20
15
|
end
|
21
16
|
|
22
17
|
description do
|
23
18
|
msg = "validate the #{ kind } of #{ @field.inspect }"
|
24
|
-
msg << " with options: #{ @
|
19
|
+
msg << " with options: #{ @expected_options.inspect }" if @expected_options
|
25
20
|
msg
|
26
21
|
end
|
27
22
|
|
28
23
|
failure_message_for_should do
|
29
|
-
|
30
|
-
msg << "\n with options: #{ @options.inspect }" if @options.present?
|
31
|
-
msg
|
24
|
+
"Expected #{ described_class } to validate the #{ kind } of #{ @field.inspect } #{ options_message }"
|
32
25
|
end
|
33
26
|
|
34
27
|
failure_message_for_should_not do
|
35
|
-
|
36
|
-
msg << "\n with options: #{ @options.inspect }" if @options.present?
|
37
|
-
msg
|
28
|
+
"Expected #{ described_class } not to validate the #{ kind } of #{ @field.inspect } #{ options_message }"
|
38
29
|
end
|
39
30
|
|
40
|
-
|
41
|
-
validator
|
42
|
-
|
43
|
-
|
44
|
-
|
31
|
+
def validator
|
32
|
+
@validator ||= actual.class.validators_on(@field).detect { |v| @expected.include? v.kind }
|
33
|
+
end
|
34
|
+
|
35
|
+
def validator_options
|
36
|
+
@validator_options ||= validator.options rescue {}
|
37
|
+
end
|
45
38
|
|
39
|
+
def diff
|
40
|
+
@diff ||= @expected_options ? validator_options.diff(@expected_options) : {}
|
41
|
+
end
|
42
|
+
|
43
|
+
match do |actual|
|
46
44
|
validator.present? and diff.blank?
|
47
45
|
end
|
48
46
|
|
data/validation_matcher.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validation_matcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-06-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -59,6 +59,22 @@ dependencies:
|
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '3'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
62
78
|
- !ruby/object:Gem::Dependency
|
63
79
|
name: pry
|
64
80
|
requirement: !ruby/object:Gem::Requirement
|
@@ -106,7 +122,6 @@ files:
|
|
106
122
|
- Rakefile
|
107
123
|
- lib/validation_matcher.rb
|
108
124
|
- lib/validation_matcher/version.rb
|
109
|
-
- spec/matchers_spec.rb
|
110
125
|
- spec/spec_helper.rb
|
111
126
|
- spec/thing_spec.rb
|
112
127
|
- validation_matcher.gemspec
|
@@ -135,6 +150,5 @@ signing_key:
|
|
135
150
|
specification_version: 3
|
136
151
|
summary: RSpec matcher for ActiveModel validations
|
137
152
|
test_files:
|
138
|
-
- spec/matchers_spec.rb
|
139
153
|
- spec/spec_helper.rb
|
140
154
|
- spec/thing_spec.rb
|