match_hash 0.1.1 → 0.1.2
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +8 -2
- data/README.md +43 -30
- data/lib/match_hash/sub/match_hash.rb +17 -5
- data/lib/match_hash/version.rb +1 -1
- data/match_hash.gemspec +1 -0
- metadata +17 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 517de75736bb5f7ea565f2ecc9cb6812a1feccd2
|
|
4
|
+
data.tar.gz: eb2869112fdfdf27c0a8da6fd4d438f6c3f8eefd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a9647e92789d25f1b6b92c6a0938cc43774fa33de8d8bbbc65015d8ed384ba52b29f9244f7db005980220def25c2650c08c72c612938ed6da237cddfd9a42978
|
|
7
|
+
data.tar.gz: e7e8e751cbd450ce613095018deb0693bb2bc46cd57a0d2b1106a3b465135784518b4294804e25871e7d83d6a49770abb45a0c8d5abc59ab1589867978e47d33
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
match_hash (0.1.
|
|
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.
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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 "
|
|
62
|
-
expect(
|
|
66
|
+
it "has a version number" do
|
|
67
|
+
expect(MatchHash::VERSION).not_to be nil
|
|
63
68
|
end
|
|
64
69
|
|
|
65
|
-
it "
|
|
66
|
-
expect
|
|
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
|
-
|
|
80
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
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
|
data/lib/match_hash/version.rb
CHANGED
data/match_hash.gemspec
CHANGED
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.
|
|
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:
|
|
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.
|
|
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
|