validation_matcher 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module ValidationMatcher
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -4,45 +4,43 @@ module ValidationMatcher
4
4
 
5
5
  RSpec::Matchers.define :validate do |kind|
6
6
 
7
- chain(:of) { |field| @field = field }
8
- chain(:with) { |hash| @options = hash }
9
-
10
- # simplify access to the described_class
11
- def described_class
12
- @described_class ||= actual.class
13
- end
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: #{ @options.inspect }" if @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
- msg = "Expected #{ described_class } to validate the #{ kind } of #{ @field.inspect }"
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
- msg = "Expected #{ described_class } not to validate the #{ kind } of #{ @field.inspect }"
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
- match do |actual|
41
- validator = find_validator kind
42
- options = validator.options rescue {}
43
- diff = @options ? options.diff(@options) : nil
44
- @options = nil # for some reason this appears to be cached between runs?
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
 
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
  s.add_dependency 'activemodel', '~> 3'
24
24
  s.add_dependency 'activesupport', '~> 3'
25
25
 
26
+ s.add_development_dependency 'rake'
26
27
  s.add_development_dependency 'pry'
27
28
  s.add_development_dependency 'pry-nav'
28
29
  end
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.0
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-05-30 00:00:00.000000000 Z
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
@@ -1,9 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe ValidationMatcher do
4
-
5
- it 'something' do
6
- # binding.pry
7
- end
8
-
9
- end