validation_matcher 2.0.1 → 3.0.0

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
  SHA1:
3
- metadata.gz: 98b84120db3a3b9161ee52fa111c725e40c5619a
4
- data.tar.gz: a9fdc92cf3a81969d17940c41ea9e288e23f3d30
3
+ metadata.gz: b16465f924eb98a7218d2f6cc181c61bcb420a72
4
+ data.tar.gz: 50aae6f4842ebe52344b916ef1200d159b07509f
5
5
  SHA512:
6
- metadata.gz: fe8ff27fb896a5bdaee9303e9ffcf66448664ce0ce774b633967efe0ea6fec1ed117b9c715e64dd658c63946bdfa8dc902dc54683649e1ace9657d036406cf74
7
- data.tar.gz: 83de8591e14d9d54567dd23388aff4a8b656fa7bd5c206af8236bd723ddc320340c410053c028c18bd023a0d7a5d7c8c21be8ea13edd329e8ee59a741a470ecb
6
+ metadata.gz: 4f4f0af1a4e941053b8698abdddc5e756d5d070af667ef23cb8ea752d912e2751ceead3c15d7a2ec5f4689935d5a22f71871d09c7b69dc8d1f1b4d6efea89c96
7
+ data.tar.gz: 9b22e0532ac4bd4dce5bd5ba10f496a94733eb3fc712aa92e236a535dc22e3ffd666cc9c20b5728c3ae2d855e463401ad90e81a3cca015e221cd3a70273dfec5
@@ -0,0 +1,17 @@
1
+ module HashDiff
2
+
3
+ refine Hash do
4
+ # Stolen from Rails 4.0.5 since this has been removed!
5
+ #
6
+ # Returns a hash that represents the diff_witherence between two hashes.
7
+ #
8
+ # {1 => 2}.diff_with(1 => 2) # => {}
9
+ # {1 => 2}.diff_with(1 => 3) # => {1 => 2}
10
+ # {}.diff_with(1 => 2) # => {1 => 2}
11
+ # {1 => 2, 3 => 4}.diff_with(1 => 2) # => {3 => 4}
12
+ def diff_with other
13
+ dup.delete_if { |k, v| other[k] == v }.merge!(other.dup.delete_if { |k, v| has_key?(k) })
14
+ end
15
+ end
16
+
17
+ end
@@ -1,3 +1,3 @@
1
1
  module ValidationMatcher
2
- VERSION = '2.0.1'
2
+ VERSION = '3.0.0'
3
3
  end
@@ -1,26 +1,11 @@
1
1
  require 'validation_matcher/version'
2
+ require 'validation_matcher/hash_diff'
2
3
  require 'rspec/expectations'
3
4
 
4
- unless Hash.instance_methods.include?(:diff)
5
- class Hash
6
-
7
- # Stolen from Rails 4.0.5 since this has been removed!
8
- #
9
- # Returns a hash that represents the difference between two hashes.
10
- #
11
- # {1 => 2}.diff(1 => 2) # => {}
12
- # {1 => 2}.diff(1 => 3) # => {1 => 2}
13
- # {}.diff(1 => 2) # => {1 => 2}
14
- # {1 => 2, 3 => 4}.diff(1 => 2) # => {3 => 4}
15
- def diff other
16
- dup.delete_if { |k, v| other[k] == v }.merge!(other.dup.delete_if { |k, v| has_key?(k) })
17
- end
18
-
19
- end
20
- end
21
-
22
5
  module ValidationMatcher
23
6
 
7
+ using HashDiff
8
+
24
9
  RSpec::Matchers.define :validate do |kind|
25
10
 
26
11
  chain(:of) { |field| @field = field }
@@ -34,11 +19,11 @@ module ValidationMatcher
34
19
  end
35
20
 
36
21
  failure_message do
37
- "Expected #{ described_class } to validate the #{ kind } of #{ @field.inspect } #{ diff }"
22
+ "Expected #{ described_class } to validate the #{ kind } of #{ @field.inspect } #{ diff_with }"
38
23
  end
39
24
 
40
25
  failure_message_when_negated do
41
- "Expected #{ described_class } not to validate the #{ kind } of #{ @field.inspect } #{ diff }"
26
+ "Expected #{ described_class } not to validate the #{ kind } of #{ @field.inspect } #{ diff_with }"
42
27
  end
43
28
 
44
29
  def expected_options
@@ -53,25 +38,25 @@ module ValidationMatcher
53
38
  @validator_options ||= validator.options rescue {}
54
39
  end
55
40
 
56
- def diff?
41
+ def diff_with?
57
42
  # if validator_options is empty and @expected_options is not, there is a problem
58
43
  # if @expected_options is empty and validator_options is not, there is a problem
59
- # if neither is empty diff them, if there's a diff, there is a problem
44
+ # if neither is empty diff_with them, if there's a diff_with, there is a problem
60
45
 
61
46
  return true if expected_options.present? ^ validator_options.present?
62
- return true if validator_options.diff(expected_options).present?
47
+ return true if validator_options.diff_with(expected_options).present?
63
48
  false
64
49
  end
65
50
 
66
- def diff
67
- return '' unless diff?
51
+ def diff_with
52
+ return '' unless diff_with?
68
53
  str = "\n expected options: #{ expected_options.inspect }"
69
54
  str << "\n actual options: #{ validator_options.inspect }"
70
55
  str
71
56
  end
72
57
 
73
58
  match do |actual|
74
- validator.present? and not diff?
59
+ validator.present? and not diff_with?
75
60
  end
76
61
 
77
62
  end
@@ -19,6 +19,8 @@ Gem::Specification.new do |s|
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
  s.require_paths = ['lib']
21
21
 
22
+ s.required_ruby_version = '>= 2.0'
23
+
22
24
  s.add_dependency 'rspec-expectations', '~> 3.1'
23
25
 
24
26
  s.add_development_dependency 'activemodel', '>= 3'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validation_matcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - BM5k
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-10 00:00:00.000000000 Z
11
+ date: 2015-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-expectations
@@ -109,6 +109,7 @@ files:
109
109
  - README.md
110
110
  - Rakefile
111
111
  - lib/validation_matcher.rb
112
+ - lib/validation_matcher/hash_diff.rb
112
113
  - lib/validation_matcher/version.rb
113
114
  - spec/spec_helper.rb
114
115
  - spec/thing_spec.rb
@@ -125,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
125
126
  requirements:
126
127
  - - ">="
127
128
  - !ruby/object:Gem::Version
128
- version: '0'
129
+ version: '2.0'
129
130
  required_rubygems_version: !ruby/object:Gem::Requirement
130
131
  requirements:
131
132
  - - ">="
@@ -133,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
134
  version: '0'
134
135
  requirements: []
135
136
  rubyforge_project: validation_matcher
136
- rubygems_version: 2.4.6
137
+ rubygems_version: 2.4.8
137
138
  signing_key:
138
139
  specification_version: 4
139
140
  summary: RSpec matcher for ActiveModel validations