validation_matcher 0.1.7 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/validation_matcher.rb +23 -14
- data/lib/validation_matcher/version.rb +1 -1
- data/spec/spec_helper.rb +1 -0
- data/spec/thing_spec.rb +6 -3
- data/validation_matcher.gemspec +3 -0
- metadata +57 -3
data/lib/validation_matcher.rb
CHANGED
@@ -6,27 +6,25 @@ module ValidationMatcher
|
|
6
6
|
RSpec::Matchers.define :validate do |kind|
|
7
7
|
|
8
8
|
chain(:of) { |field| @field = field }
|
9
|
-
chain(:with) { |hash| @expected_options = hash
|
10
|
-
|
11
|
-
def options_message
|
12
|
-
return '' unless diff.present?
|
13
|
-
str = "\n expected options: " + @expected_options.inspect
|
14
|
-
str << "\n actual options: " + validator_options.inspect
|
15
|
-
str
|
16
|
-
end
|
9
|
+
chain(:with) { |hash| @expected_options = hash }
|
17
10
|
|
18
11
|
description do
|
19
12
|
msg = "validate the #{ kind } of #{ @field.inspect }"
|
20
13
|
msg << " with options: #{ @expected_options.inspect }" if @expected_options
|
14
|
+
@expected_options = nil # for some reason this appears to be cached between runs?
|
21
15
|
msg
|
22
16
|
end
|
23
17
|
|
24
18
|
failure_message_for_should do
|
25
|
-
"Expected #{ described_class } to validate the #{ kind } of #{ @field.inspect } #{
|
19
|
+
"Expected #{ described_class } to validate the #{ kind } of #{ @field.inspect } #{ diff }"
|
26
20
|
end
|
27
21
|
|
28
22
|
failure_message_for_should_not do
|
29
|
-
"Expected #{ described_class } not to validate the #{ kind } of #{ @field.inspect } #{
|
23
|
+
"Expected #{ described_class } not to validate the #{ kind } of #{ @field.inspect } #{ diff }"
|
24
|
+
end
|
25
|
+
|
26
|
+
def expected_options
|
27
|
+
@expected_options || {}
|
30
28
|
end
|
31
29
|
|
32
30
|
def validator
|
@@ -37,14 +35,25 @@ module ValidationMatcher
|
|
37
35
|
@validator_options ||= validator.options rescue {}
|
38
36
|
end
|
39
37
|
|
38
|
+
def diff?
|
39
|
+
# if validator_options is empty and @expected_options is not, there is a problem
|
40
|
+
# if @expected_options is empty and validator_options is not, there is a problem
|
41
|
+
# if neither is empty diff them, if there's a diff, there is a problem
|
42
|
+
|
43
|
+
return true if expected_options.present? ^ validator_options.present?
|
44
|
+
return true if validator_options.diff(expected_options).present?
|
45
|
+
false
|
46
|
+
end
|
47
|
+
|
40
48
|
def diff
|
41
|
-
|
49
|
+
return '' unless diff?
|
50
|
+
str = "\n expected options: #{ expected_options.inspect }"
|
51
|
+
str << "\n actual options: #{ validator_options.inspect }"
|
52
|
+
str
|
42
53
|
end
|
43
54
|
|
44
55
|
match do |actual|
|
45
|
-
|
46
|
-
@expected_options = nil # for some reason this appears to be cached between runs?
|
47
|
-
result
|
56
|
+
validator.present? and not diff?
|
48
57
|
end
|
49
58
|
|
50
59
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/thing_spec.rb
CHANGED
@@ -2,8 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Thing do
|
4
4
|
|
5
|
-
it { should_not validate(:presence).of
|
6
|
-
it { should validate(:presence).of
|
7
|
-
|
5
|
+
it { should_not validate(:presence).of :field_a }
|
6
|
+
it { should validate(:presence).of :field_b }
|
7
|
+
|
8
|
+
it { should_not validate(:numericality).of :field_c }
|
9
|
+
it { should_not validate(:numericality).of(:field_c).with only_integer: true }
|
10
|
+
it { should validate(:numericality).of(:field_c).with only_integer: true, allow_nil: false }
|
8
11
|
|
9
12
|
end
|
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.8
|
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:
|
12
|
+
date: 2013-07-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -75,6 +75,54 @@ dependencies:
|
|
75
75
|
- - ! '>='
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: pry
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: pry-doc
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: pry-debugger
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
78
126
|
description: Use reflection to spec ActiveModel validations
|
79
127
|
email:
|
80
128
|
- me@bm5k.com
|
@@ -105,15 +153,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
153
|
- - ! '>='
|
106
154
|
- !ruby/object:Gem::Version
|
107
155
|
version: '0'
|
156
|
+
segments:
|
157
|
+
- 0
|
158
|
+
hash: -1150667163459900178
|
108
159
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
160
|
none: false
|
110
161
|
requirements:
|
111
162
|
- - ! '>='
|
112
163
|
- !ruby/object:Gem::Version
|
113
164
|
version: '0'
|
165
|
+
segments:
|
166
|
+
- 0
|
167
|
+
hash: -1150667163459900178
|
114
168
|
requirements: []
|
115
169
|
rubyforge_project: validation_matcher
|
116
|
-
rubygems_version: 1.8.
|
170
|
+
rubygems_version: 1.8.25
|
117
171
|
signing_key:
|
118
172
|
specification_version: 3
|
119
173
|
summary: RSpec matcher for ActiveModel validations
|