match_hash 0.1.1 → 0.1.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
  SHA1:
3
- metadata.gz: 9444052b2bfb07b0870ee7f202ee53abba6ec312
4
- data.tar.gz: cc64e3822421f8b999f873ae846933ec872a7111
3
+ metadata.gz: 517de75736bb5f7ea565f2ecc9cb6812a1feccd2
4
+ data.tar.gz: eb2869112fdfdf27c0a8da6fd4d438f6c3f8eefd
5
5
  SHA512:
6
- metadata.gz: f8d70c66123189688786ecbcf5f3d9d796a405b7a87991c5ef8fce2fee3031d1fbf5ca75215291fe6165ab3efc891b95d8747baa2c71dabc4399ed96e263352f
7
- data.tar.gz: '095625802374af8d88235c5d0fb2a72678701d41db787bd658934da152fa4bf4f67b403171a7ed08601c2b3b91f05b6d8cd61ecd013f625a39d7bcb821897c62'
6
+ metadata.gz: a9647e92789d25f1b6b92c6a0938cc43774fa33de8d8bbbc65015d8ed384ba52b29f9244f7db005980220def25c2650c08c72c612938ed6da237cddfd9a42978
7
+ data.tar.gz: e7e8e751cbd450ce613095018deb0693bb2bc46cd57a0d2b1106a3b465135784518b4294804e25871e7d83d6a49770abb45a0c8d5abc59ab1589867978e47d33
@@ -1,3 +1,7 @@
1
+ ## v0.1.2
2
+ 2018-08-04
3
+ * [Don't choke on hashes inside arrays](https://github.com/yukihirop/match_hash/pull/3)
4
+
1
5
  ## v0.1.1
2
6
  2016-01-03
3
7
  * RENAME lib/environment.rb -> lib/match_hash.rb
@@ -1,13 +1,18 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- match_hash (0.1.0)
4
+ match_hash (0.1.2)
5
5
  rspec-expectations (~> 3.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
+ coderay (1.1.2)
10
11
  diff-lcs (1.2.5)
12
+ method_source (0.9.0)
13
+ pry (0.11.3)
14
+ coderay (~> 1.1.0)
15
+ method_source (~> 0.9.0)
11
16
  rake (10.5.0)
12
17
  rspec (3.5.0)
13
18
  rspec-core (~> 3.5.0)
@@ -29,8 +34,9 @@ PLATFORMS
29
34
  DEPENDENCIES
30
35
  bundler (~> 1.13)
31
36
  match_hash!
37
+ pry
32
38
  rake (~> 10.5.0)
33
39
  rspec (~> 3.0)
34
40
 
35
41
  BUNDLED WITH
36
- 1.13.6
42
+ 1.16.0.pre.3
data/README.md CHANGED
@@ -18,10 +18,6 @@ Add this line to your application's `Gemfile` :
18
18
  ```ruby
19
19
  gem 'match_hash'
20
20
  ```
21
- Add this line to your application's `spec_helper.rb` :
22
- ```ruby
23
- require 'match_hash'
24
- ```
25
21
 
26
22
  And then execute:
27
23
 
@@ -37,37 +33,49 @@ The new matcher could be used in RSpec as follows:
37
33
 
38
34
  ```ruby
39
35
  describe MatchHash do
40
-
41
- before do
42
- @A = {
43
- a11:11,
44
- a12:{
45
- b11:21,
46
- b12:22
47
- },
48
- a13:[1,2,3],
36
+ let(:expected) do
37
+ {
38
+ a11:11,
39
+ a12:12,
40
+ a13:13,
41
+ a14:{
42
+ b11:11,
43
+ b12:12
44
+ },
45
+ a15:[1,2,3],
46
+ a16:16,
47
+ a17: [{b13: 13}]
49
48
  }
49
+ end
50
50
 
51
- @B = {
52
- a11:11,
53
- a12:{
54
- b11:21,
55
- b12:22
56
- },
57
- a13:[3,2,1],
51
+ let(:actual) do
52
+ {
53
+ a11:11,
54
+ a12:12,
55
+ a13:13,
56
+ a14:{
57
+ b11:11,
58
+ b12:12
59
+ },
60
+ a15:[3,2,1],
61
+ a16:16,
62
+ a17: [{b13: 14}]
58
63
  }
59
64
  end
60
65
 
61
- it "A hash match A hash" do
62
- expect(@A).to match_hash(@A)
66
+ it "has a version number" do
67
+ expect(MatchHash::VERSION).not_to be nil
63
68
  end
64
69
 
65
- it "A hash do not match B hash and occured raise_error" do
66
- expect do
67
- expect(@A).to match_hash(@B)
68
- end.to raise_error
70
+ it "expected hash match expected hash" do
71
+ expect(expected).to match_hash(expected)
69
72
  end
70
73
 
74
+ it "expected hash do not match actual hash and occured raise_error" do
75
+ expect do
76
+ expect(expected).to match_hash(actual)
77
+ end.to raise_error(RSpec::Expectations::ExpectationNotMetError)
78
+ end
71
79
  end
72
80
  ```
73
81
 
@@ -76,19 +84,24 @@ end
76
84
  For example:
77
85
 
78
86
  ```ruby
79
- 1) MatchHash A hash match A hash
80
- Failure/Error: expect(@A).to match_hash(@B)
87
+ Failures:
88
+
89
+ 1) MatchHash expected hash match expected hash
90
+ Failure/Error: expect(expected).to match_hash(actual)
81
91
 
82
92
  Diff:
83
- @@ -2,6 +2,6 @@
93
+
94
+ @@ -2,7 +2,7 @@
84
95
  :a12 => 12,
85
96
  :a13 => 13,
86
97
  :a14 => {:b11=>11, :b12=>12},
87
98
  -:a15 => [3, 2, 1],
88
99
  +:a15 => [1, 2, 3],
89
100
  :a16 => 16,
101
+ -:a17 => [{:b13=>14}],
102
+ +:a17 => [{:b13=>13}],
90
103
 
91
- # ./spec/match_hash_spec.rb:36:in `block (2 levels) in <top (required)>'
104
+ # ./spec/match_hash_spec.rb:40:in `block (2 levels) in <top (required)>'
92
105
  ```
93
106
 
94
107
  ## Contributing
@@ -1,8 +1,10 @@
1
+ require 'pry'
2
+
1
3
  module Sub
2
4
 
3
5
  private
4
6
 
5
- def match_hash(expected, actual)
7
+ def match_hash?(expected, actual)
6
8
  expected.each do |key, value|
7
9
  return true unless actual.has_key?(key)
8
10
  @is_errors << match_value(expected[key], actual[key])
@@ -17,19 +19,29 @@ module Sub
17
19
  end
18
20
  @is_errors.include?(true)
19
21
  end
22
+ alias :match_hash :match_hash?
20
23
 
21
- def match_array(expected, actual)
22
- expected.each_with_index do |i|
23
- match_value(expected[i],actual[i])
24
+ def match_array?(expected, actual)
25
+ expected.each_with_index do |data,i|
26
+ case data
27
+ when Hash
28
+ match_hash(data, actual[i])
29
+ when Array
30
+ match_array(data, actual[i])
31
+ else
32
+ match_value(data, actual[i])
33
+ end
24
34
  end
25
35
  end
36
+ alias :match_array :match_array?
26
37
 
27
38
  # trueを返すときがエラー
28
- def match_value(expected, actual)
39
+ def match_value?(expected, actual)
29
40
  match_hash(expected, actual) if expected.is_a?(Hash)
30
41
  match_array(expected, actual) if expected.is_a?(Array)
31
42
  return false if expected == actual
32
43
  return true
33
44
  end
45
+ alias :match_value :match_value?
34
46
 
35
47
  end
@@ -1,3 +1,3 @@
1
1
  module MatchHash
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -36,5 +36,6 @@ Gem::Specification.new do |spec|
36
36
  spec.add_development_dependency "bundler", "~> 1.13"
37
37
  spec.add_development_dependency "rake", "~> 10.5.0"
38
38
  spec.add_development_dependency "rspec", "~> 3.0"
39
+ spec.add_development_dependency "pry"
39
40
 
40
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: match_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - yukihirop
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-03 00:00:00.000000000 Z
11
+ date: 2018-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-expectations
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: Custom Matcher errors generate from RSpec::Matchers::ExpectedsForMultipleDiffs.from.message_with_diff
70
84
  email:
71
85
  - te108186@gmail.com
@@ -109,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
123
  version: '0'
110
124
  requirements: []
111
125
  rubyforge_project:
112
- rubygems_version: 2.6.8
126
+ rubygems_version: 2.6.11
113
127
  signing_key:
114
128
  specification_version: 4
115
129
  summary: This is a Custom Matcher to match hash in RSpec