hashes_equal 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rubocop.yml +125 -0
- data/.ruby_version +1 -0
- data/.travis.yml +24 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +9 -0
- data/Guardfile +46 -0
- data/LICENSE.txt +21 -0
- data/Makefile +5 -0
- data/README.md +120 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/hashes_equal.gemspec +51 -0
- data/lib/hashes_equal.rb +7 -0
- data/lib/hashes_equal/hash_compare_helper.rb +19 -0
- data/lib/hashes_equal/hash_diff_displayer.rb +80 -0
- data/lib/hashes_equal/version.rb +5 -0
- metadata +284 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 723e208b4818b3724802a8fb3c54fbe6349ce1fe93ba477d4d1fd7fc4b23a73f
|
4
|
+
data.tar.gz: c55f8bbb2b9c26d263b3b92f6349e4c23a1cfe5113ff3db57483627289087b14
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d34411729d8d5a1b85c6f8f495946377410569afcccf53726ffeadbb69ab24e42e1677c76658c2ce5780ede5111beb33f6c32335404a0e954b372bd946d638d6
|
7
|
+
data.tar.gz: 6913b25aac360fed3290b420780387db5b4bc646976e6347753e8d465d586eef0ac9a6c15c9287b4c205ddb667e284ce8f311e348727ca0848c83f08ec96ec4c
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
|
4
|
+
AllCops:
|
5
|
+
TargetRubyVersion: 2.6
|
6
|
+
|
7
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
8
|
+
Enabled: true
|
9
|
+
|
10
|
+
Layout/HeredocIndentation:
|
11
|
+
Enabled: true
|
12
|
+
|
13
|
+
Layout/LineLength:
|
14
|
+
Max: 80
|
15
|
+
Exclude:
|
16
|
+
- 'config/initializers/devise.rb'
|
17
|
+
- 'config/initializers/content_security_policy.rb'
|
18
|
+
- 'config/environments/production.rb'
|
19
|
+
|
20
|
+
Layout/MultilineArrayLineBreaks:
|
21
|
+
Enabled: true
|
22
|
+
|
23
|
+
Layout/MultilineHashKeyLineBreaks:
|
24
|
+
Enabled: true
|
25
|
+
|
26
|
+
# Enabled means "no space" around call operators
|
27
|
+
Layout/SpaceAroundMethodCallOperator:
|
28
|
+
Enabled: true
|
29
|
+
|
30
|
+
Lint/DeprecatedOpenSSLConstant:
|
31
|
+
Enabled: true
|
32
|
+
|
33
|
+
Lint/MixedRegexpCaptureTypes:
|
34
|
+
Enabled: true
|
35
|
+
|
36
|
+
Lint/StructNewOverride:
|
37
|
+
Enabled: true
|
38
|
+
|
39
|
+
# Meaning you cannot: raise Exception
|
40
|
+
Lint/RaiseException:
|
41
|
+
Enabled: true
|
42
|
+
|
43
|
+
Metrics/ClassLength:
|
44
|
+
Max: 110
|
45
|
+
|
46
|
+
# Would give us false positives on all private(*delegate)
|
47
|
+
Style/AccessModifierDeclarations:
|
48
|
+
Enabled: false
|
49
|
+
|
50
|
+
Style/RegexpLiteral:
|
51
|
+
EnforcedStyle: percent_r
|
52
|
+
|
53
|
+
Style/ClassAndModuleChildren:
|
54
|
+
Enabled: false
|
55
|
+
|
56
|
+
Style/DateTime:
|
57
|
+
Enabled: false
|
58
|
+
|
59
|
+
Style/Documentation:
|
60
|
+
Enabled: false
|
61
|
+
|
62
|
+
Style/ExponentialNotation:
|
63
|
+
Enabled: true
|
64
|
+
|
65
|
+
# Style/MixinUsage:
|
66
|
+
# Exclude:
|
67
|
+
# - 'features/step_definitions/has_orders.rb'
|
68
|
+
# - 'features/support/ember.rb'
|
69
|
+
|
70
|
+
# Currently gives false positive with e.g. generator.date.strftime '%Y%m%d'
|
71
|
+
# https://github.com/bbatsov/rubocop/issues/5398
|
72
|
+
#
|
73
|
+
Style/FormatStringToken:
|
74
|
+
Enabled: false
|
75
|
+
|
76
|
+
Style/HashEachMethods:
|
77
|
+
Enabled: true
|
78
|
+
|
79
|
+
Style/HashTransformKeys:
|
80
|
+
Enabled: true
|
81
|
+
|
82
|
+
Style/HashTransformValues:
|
83
|
+
Enabled: true
|
84
|
+
|
85
|
+
Style/NumericPredicate:
|
86
|
+
EnforcedStyle: comparison
|
87
|
+
|
88
|
+
Style/RedundantRegexpCharacterClass:
|
89
|
+
Enabled: true
|
90
|
+
|
91
|
+
Style/RedundantRegexpEscape:
|
92
|
+
Enabled: true
|
93
|
+
|
94
|
+
Style/SlicingWithRange:
|
95
|
+
Enabled: true
|
96
|
+
|
97
|
+
# Metrics/ClassLength:
|
98
|
+
# Max: 250
|
99
|
+
|
100
|
+
Metrics/BlockLength:
|
101
|
+
Exclude:
|
102
|
+
- 'hashes_equal.gemspec'
|
103
|
+
|
104
|
+
# Naming/HeredocDelimiterNaming:
|
105
|
+
# Exclude:
|
106
|
+
# - 'test/**/*'
|
107
|
+
|
108
|
+
# Naming/MemoizedInstanceVariableName:
|
109
|
+
# Exclude:
|
110
|
+
# - 'test/**/*'
|
111
|
+
|
112
|
+
# Naming/UncommunicativeMethodParamName:
|
113
|
+
# AllowedNames:
|
114
|
+
# - id
|
115
|
+
# - at
|
116
|
+
# - to
|
117
|
+
# - pp
|
118
|
+
# - cb
|
119
|
+
# Exclude:
|
120
|
+
# - 'test/**/*'
|
121
|
+
# - 'features/**/*'
|
122
|
+
|
123
|
+
# Performance/UnfreezeString:
|
124
|
+
# Exclude:
|
125
|
+
# - 'test/**/*'
|
data/.ruby_version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.7.1
|
data/.travis.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
---
|
2
|
+
sudo: false
|
3
|
+
dist: xenial
|
4
|
+
language: ruby
|
5
|
+
cache: bundler
|
6
|
+
rvm:
|
7
|
+
- 2.6.6
|
8
|
+
- 2.7.0
|
9
|
+
before_install:
|
10
|
+
- gem install bundler -v 2.1.4
|
11
|
+
- bundle update --bundler
|
12
|
+
- bundle --version
|
13
|
+
env:
|
14
|
+
- build_type=ruby
|
15
|
+
script:
|
16
|
+
- cat Gemfile.lock
|
17
|
+
- bundle exec rubocop -V
|
18
|
+
- bundle exec rubocop -S
|
19
|
+
- bundle exec rubocop -d
|
20
|
+
- RAILS_ENV=test bundle exec rake test
|
21
|
+
|
22
|
+
after_script:
|
23
|
+
- ps -ejf --forest
|
24
|
+
- ssh-agent -k
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at cedric.degremont@facilecomm.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'byebug'
|
4
|
+
|
5
|
+
# A sample Guardfile
|
6
|
+
# More info at https://github.com/guard/guard#readme
|
7
|
+
|
8
|
+
# Uncomment and set this to only include directories you want to watch
|
9
|
+
def check_dir_existence(dir)
|
10
|
+
return dir if Dir.exist?(dir)
|
11
|
+
|
12
|
+
UI.warning("Directory #{dir} does not exist")
|
13
|
+
false
|
14
|
+
end
|
15
|
+
|
16
|
+
directories(
|
17
|
+
%w[lib test].select do |dir|
|
18
|
+
check_dir_existence(dir)
|
19
|
+
end
|
20
|
+
)
|
21
|
+
|
22
|
+
## Note: if you are using the `directories` clause above and you are not
|
23
|
+
## watching the project directory ('.'), then you will want to move
|
24
|
+
## the Guardfile to a watched dir and symlink it back, e.g.
|
25
|
+
#
|
26
|
+
# $ mkdir config
|
27
|
+
# $ mv Guardfile config/
|
28
|
+
# $ ln -s config/Guardfile .
|
29
|
+
#
|
30
|
+
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
|
31
|
+
|
32
|
+
guard :minitest, all_on_start: false do
|
33
|
+
# with Minitest::Unit
|
34
|
+
watch(%r{^test/(.*)/?test_(.*)\.rb$})
|
35
|
+
watch(%r{^test/(.*)/?(.*)_test\.rb$})
|
36
|
+
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
|
37
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "test/lib/#{m[1]}_test.rb" }
|
38
|
+
watch(%r{^test/test_helper\.rb$}) { 'test' }
|
39
|
+
|
40
|
+
# Rails 4
|
41
|
+
watch(%r{^lib/(.+)\.rb$}) do |m|
|
42
|
+
"test/lib/#{m[1]}_test.rb"
|
43
|
+
end
|
44
|
+
watch(%r{^test/.+_test\.rb$})
|
45
|
+
# watch(%r{^test/test_helper\.rb$}) { 'test' }
|
46
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Shippingbo
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/Makefile
ADDED
data/README.md
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
# HashesEqual
|
2
|
+
|
3
|
+
Provides a MiniTest style assertion `assert_hashes_equal` allowing you to compare two hashes (Hash), with an output that is a bit friendlier on the eye, than what you would get with an `assert_equal`. This is typically useful if you dislike spending time looking for a small difference between two large hashes.
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
require 'hashes_equal/hash_compare_helper'
|
7
|
+
|
8
|
+
class HashCompareHelperTest < Minitest::Test
|
9
|
+
include HashesEqual::HashCompareHelper
|
10
|
+
|
11
|
+
def test_disagreement_in_the_deep
|
12
|
+
expected_hash = {
|
13
|
+
a: {
|
14
|
+
b: 1,
|
15
|
+
c: 2
|
16
|
+
}
|
17
|
+
}
|
18
|
+
actual_hash = {
|
19
|
+
a: {
|
20
|
+
b: 1,
|
21
|
+
c: 3
|
22
|
+
}
|
23
|
+
}
|
24
|
+
assert_hashes_equal(
|
25
|
+
expected_hash,
|
26
|
+
actual_hash
|
27
|
+
)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
```
|
31
|
+
```bash
|
32
|
+
test_disagreement_in_the_deep FAIL (0.00s)
|
33
|
+
|
34
|
+
values for a.c differ
|
35
|
+
expected: 2
|
36
|
+
actual: 3.
|
37
|
+
Expected: {:a=>{:b=>1, :c=>2}}
|
38
|
+
Actual: {:a=>{:b=>1, :c=>3}}
|
39
|
+
hashes_equal/lib/hashes_equal/hash_compare_helper.rb:13:in `assert_hashes_equal'
|
40
|
+
```
|
41
|
+
|
42
|
+
Underneath, [Hashdiff](https://github.com/liufengyun/hashdiff) is used to perform the comparison.
|
43
|
+
|
44
|
+
## Installation
|
45
|
+
|
46
|
+
Add this line to your application's Gemfile:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
gem 'hashes_equal'
|
50
|
+
```
|
51
|
+
|
52
|
+
And then execute:
|
53
|
+
|
54
|
+
$ bundle install
|
55
|
+
|
56
|
+
Or install it yourself as:
|
57
|
+
|
58
|
+
$ gem install hashes_equal
|
59
|
+
|
60
|
+
## Usage
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
require 'hashes_equal/hash_compare_helper'
|
64
|
+
|
65
|
+
class HashCompareHelperTest < Minitest::Test
|
66
|
+
include HashesEqual::HashCompareHelper
|
67
|
+
|
68
|
+
def test_disagreement_in_the_deep
|
69
|
+
expected_hash = {
|
70
|
+
a: {
|
71
|
+
b: 1,
|
72
|
+
c: 2
|
73
|
+
}
|
74
|
+
}
|
75
|
+
actual_hash = {
|
76
|
+
a: {
|
77
|
+
b: 1,
|
78
|
+
c: 3
|
79
|
+
}
|
80
|
+
}
|
81
|
+
assert_hashes_equal(
|
82
|
+
expected_hash,
|
83
|
+
actual_hash
|
84
|
+
)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
```
|
88
|
+
```bash
|
89
|
+
test_disagreement_in_the_deep FAIL (0.00s)
|
90
|
+
|
91
|
+
values for a.c differ
|
92
|
+
expected: 2
|
93
|
+
actual: 3.
|
94
|
+
Expected: {:a=>{:b=>1, :c=>2}}
|
95
|
+
Actual: {:a=>{:b=>1, :c=>3}}
|
96
|
+
hashes_equal/lib/hashes_equal/hash_compare_helper.rb:13:in `assert_hashes_equal'
|
97
|
+
```
|
98
|
+
|
99
|
+
## Development
|
100
|
+
|
101
|
+
Run `bundle exec rake test` to run the tests.
|
102
|
+
|
103
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
104
|
+
|
105
|
+
## Contributing
|
106
|
+
|
107
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/Facilecomm/hashes_equal. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/hashes_equal/blob/master/CODE_OF_CONDUCT.md).
|
108
|
+
|
109
|
+
## Credit
|
110
|
+
Original idea and initial version of the code by [Robert Dober](https://github.com/RobertDober).
|
111
|
+
|
112
|
+
Actual hashes comparison is performed using [Hashdiff](https://github.com/liufengyun/hashdiff).
|
113
|
+
|
114
|
+
## License
|
115
|
+
|
116
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
117
|
+
|
118
|
+
## Code of Conduct
|
119
|
+
|
120
|
+
Everyone interacting in the HashesEqual project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/Facilecomm/hashes_equal/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'bundler/setup'
|
5
|
+
require 'hashes_equal'
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require 'irb'
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/hashes_equal/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'hashes_equal'
|
7
|
+
spec.version = HashesEqual::VERSION
|
8
|
+
spec.authors = ['Shippingbo']
|
9
|
+
spec.email = ['tech@facilecomm.com']
|
10
|
+
|
11
|
+
spec.summary = 'MiniTest style assertion to compare hashes.'
|
12
|
+
spec.description = 'Provides an assertion to test for hashes equality.'
|
13
|
+
spec.homepage = 'https://github.com/Facilecomm/hashes_equal'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
|
16
|
+
|
17
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
18
|
+
|
19
|
+
# spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
# spec.metadata["source_code_uri"] = "Put your gem's public repo URL here."
|
21
|
+
# spec.metadata["changelog_uri"] = "Put your gem's CHANGELOG.md URL here."
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files
|
25
|
+
# in the RubyGem that have been added into git.
|
26
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
27
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
28
|
+
f.match(%r{^(test|spec|features)/})
|
29
|
+
end
|
30
|
+
end
|
31
|
+
spec.bindir = 'exe'
|
32
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
33
|
+
spec.require_paths = ['lib']
|
34
|
+
|
35
|
+
spec.add_dependency 'ansi', '~> 1.5'
|
36
|
+
spec.add_dependency 'assertable'
|
37
|
+
spec.add_dependency 'hashdiff', '~> 1.0', '>= 1.0.1'
|
38
|
+
|
39
|
+
spec.add_development_dependency 'bundler', '~> 2.1', '>= 2.1.4'
|
40
|
+
spec.add_development_dependency 'byebug', '~> 11.1'
|
41
|
+
spec.add_development_dependency 'guard', '~> 2.16'
|
42
|
+
spec.add_development_dependency 'guard-minitest', '~> 2.4'
|
43
|
+
spec.add_development_dependency 'minitest', '~> 5.11'
|
44
|
+
spec.add_development_dependency 'minitest-reporters', '~> 1.4'
|
45
|
+
spec.add_development_dependency 'mocha', '~> 1.11'
|
46
|
+
spec.add_development_dependency 'pry', '~> 0.13'
|
47
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
48
|
+
spec.add_development_dependency 'rubocop', '~> 0.85'
|
49
|
+
spec.add_development_dependency 'rubocop-performance', '~> 1.5'
|
50
|
+
spec.add_development_dependency 'simplecov', '~> 0.18.5'
|
51
|
+
end
|
data/lib/hashes_equal.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'hashes_equal/hash_diff_displayer'
|
4
|
+
|
5
|
+
module HashesEqual
|
6
|
+
module HashCompareHelper
|
7
|
+
def assert_hashes_equal(expected, actual, verbose: true)
|
8
|
+
displayable_diff = HashDiffDisplayer.new(
|
9
|
+
expected: expected,
|
10
|
+
actual: actual
|
11
|
+
).call
|
12
|
+
if verbose
|
13
|
+
assert_equal expected, actual, displayable_diff
|
14
|
+
else
|
15
|
+
assert expected == actual, displayable_diff
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'assertable'
|
4
|
+
require 'hashdiff'
|
5
|
+
|
6
|
+
module HashesEqual
|
7
|
+
class HashDiffDisplayer
|
8
|
+
include Assertable
|
9
|
+
|
10
|
+
class ExpectationMustBeHash < ArgumentError; end
|
11
|
+
class ActualValueMustBeAHash < ArgumentError; end
|
12
|
+
class UnprocessableHashdiff < ArgumentError; end
|
13
|
+
|
14
|
+
def initialize(expected:, actual:)
|
15
|
+
@expected = expected
|
16
|
+
@actual = actual
|
17
|
+
assert_send :expected
|
18
|
+
assert_send :actual
|
19
|
+
raise ExpectationMustBeHash unless expected.is_a?(Hash)
|
20
|
+
raise ActualValueMustBeAHash unless actual.is_a?(Hash)
|
21
|
+
end
|
22
|
+
|
23
|
+
def call
|
24
|
+
compute_diff
|
25
|
+
ANSI.white do
|
26
|
+
formatted_diff
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
attr_reader :expected, :actual, :diff
|
33
|
+
|
34
|
+
def compute_diff
|
35
|
+
@diff = perform_diff_computation
|
36
|
+
end
|
37
|
+
|
38
|
+
def perform_diff_computation
|
39
|
+
Hashdiff.diff(expected, actual)
|
40
|
+
end
|
41
|
+
|
42
|
+
def formatted_diff
|
43
|
+
"\n" + diff.map do |diff_element|
|
44
|
+
format_element diff_element
|
45
|
+
end.join("\n")
|
46
|
+
end
|
47
|
+
|
48
|
+
def format_element(diff_element)
|
49
|
+
# exp_val is act_val in case of "+"
|
50
|
+
type, key, exp_val, act_val = diff_element
|
51
|
+
return missing_value_message(key, exp_val) if type == '-'
|
52
|
+
return spurious_value_message(key, exp_val) if type == '+'
|
53
|
+
return value_disagreement_message(key, exp_val, act_val) if type == '~'
|
54
|
+
|
55
|
+
raise UnprocessableHashdiff, diff_element
|
56
|
+
end
|
57
|
+
|
58
|
+
def missing_value_message(key, exp_val)
|
59
|
+
[
|
60
|
+
"actual value for #{ANSI.red { key }} is missing, expected was",
|
61
|
+
ANSI.green { exp_val.inspect }
|
62
|
+
].join("\n\t")
|
63
|
+
end
|
64
|
+
|
65
|
+
def spurious_value_message(key, exp_val)
|
66
|
+
[
|
67
|
+
"spurious value #{ANSI.red { exp_val.inspect }}",
|
68
|
+
"for #{key} was not expected"
|
69
|
+
].join(' ')
|
70
|
+
end
|
71
|
+
|
72
|
+
def value_disagreement_message(key, exp_val, act_val)
|
73
|
+
[
|
74
|
+
"values for #{key} differ",
|
75
|
+
"expected: #{ANSI.green { exp_val.inspect }}",
|
76
|
+
"actual: #{ANSI.red { act_val.inspect }}"
|
77
|
+
].join("\n\t")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,284 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hashes_equal
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shippingbo
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ansi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: assertable
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: hashdiff
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.0'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 1.0.1
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '1.0'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 1.0.1
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: bundler
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '2.1'
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 2.1.4
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '2.1'
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 2.1.4
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: byebug
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '11.1'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - "~>"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '11.1'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: guard
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - "~>"
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '2.16'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - "~>"
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '2.16'
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: guard-minitest
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - "~>"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '2.4'
|
116
|
+
type: :development
|
117
|
+
prerelease: false
|
118
|
+
version_requirements: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - "~>"
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '2.4'
|
123
|
+
- !ruby/object:Gem::Dependency
|
124
|
+
name: minitest
|
125
|
+
requirement: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - "~>"
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '5.11'
|
130
|
+
type: :development
|
131
|
+
prerelease: false
|
132
|
+
version_requirements: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - "~>"
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '5.11'
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
name: minitest-reporters
|
139
|
+
requirement: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - "~>"
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '1.4'
|
144
|
+
type: :development
|
145
|
+
prerelease: false
|
146
|
+
version_requirements: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - "~>"
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '1.4'
|
151
|
+
- !ruby/object:Gem::Dependency
|
152
|
+
name: mocha
|
153
|
+
requirement: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - "~>"
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '1.11'
|
158
|
+
type: :development
|
159
|
+
prerelease: false
|
160
|
+
version_requirements: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - "~>"
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '1.11'
|
165
|
+
- !ruby/object:Gem::Dependency
|
166
|
+
name: pry
|
167
|
+
requirement: !ruby/object:Gem::Requirement
|
168
|
+
requirements:
|
169
|
+
- - "~>"
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '0.13'
|
172
|
+
type: :development
|
173
|
+
prerelease: false
|
174
|
+
version_requirements: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - "~>"
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '0.13'
|
179
|
+
- !ruby/object:Gem::Dependency
|
180
|
+
name: rake
|
181
|
+
requirement: !ruby/object:Gem::Requirement
|
182
|
+
requirements:
|
183
|
+
- - "~>"
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '13.0'
|
186
|
+
type: :development
|
187
|
+
prerelease: false
|
188
|
+
version_requirements: !ruby/object:Gem::Requirement
|
189
|
+
requirements:
|
190
|
+
- - "~>"
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
version: '13.0'
|
193
|
+
- !ruby/object:Gem::Dependency
|
194
|
+
name: rubocop
|
195
|
+
requirement: !ruby/object:Gem::Requirement
|
196
|
+
requirements:
|
197
|
+
- - "~>"
|
198
|
+
- !ruby/object:Gem::Version
|
199
|
+
version: '0.85'
|
200
|
+
type: :development
|
201
|
+
prerelease: false
|
202
|
+
version_requirements: !ruby/object:Gem::Requirement
|
203
|
+
requirements:
|
204
|
+
- - "~>"
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
version: '0.85'
|
207
|
+
- !ruby/object:Gem::Dependency
|
208
|
+
name: rubocop-performance
|
209
|
+
requirement: !ruby/object:Gem::Requirement
|
210
|
+
requirements:
|
211
|
+
- - "~>"
|
212
|
+
- !ruby/object:Gem::Version
|
213
|
+
version: '1.5'
|
214
|
+
type: :development
|
215
|
+
prerelease: false
|
216
|
+
version_requirements: !ruby/object:Gem::Requirement
|
217
|
+
requirements:
|
218
|
+
- - "~>"
|
219
|
+
- !ruby/object:Gem::Version
|
220
|
+
version: '1.5'
|
221
|
+
- !ruby/object:Gem::Dependency
|
222
|
+
name: simplecov
|
223
|
+
requirement: !ruby/object:Gem::Requirement
|
224
|
+
requirements:
|
225
|
+
- - "~>"
|
226
|
+
- !ruby/object:Gem::Version
|
227
|
+
version: 0.18.5
|
228
|
+
type: :development
|
229
|
+
prerelease: false
|
230
|
+
version_requirements: !ruby/object:Gem::Requirement
|
231
|
+
requirements:
|
232
|
+
- - "~>"
|
233
|
+
- !ruby/object:Gem::Version
|
234
|
+
version: 0.18.5
|
235
|
+
description: Provides an assertion to test for hashes equality.
|
236
|
+
email:
|
237
|
+
- tech@facilecomm.com
|
238
|
+
executables: []
|
239
|
+
extensions: []
|
240
|
+
extra_rdoc_files: []
|
241
|
+
files:
|
242
|
+
- ".gitignore"
|
243
|
+
- ".rubocop.yml"
|
244
|
+
- ".ruby_version"
|
245
|
+
- ".travis.yml"
|
246
|
+
- CODE_OF_CONDUCT.md
|
247
|
+
- Gemfile
|
248
|
+
- Gemfile.lock
|
249
|
+
- Guardfile
|
250
|
+
- LICENSE.txt
|
251
|
+
- Makefile
|
252
|
+
- README.md
|
253
|
+
- Rakefile
|
254
|
+
- bin/console
|
255
|
+
- bin/setup
|
256
|
+
- hashes_equal.gemspec
|
257
|
+
- lib/hashes_equal.rb
|
258
|
+
- lib/hashes_equal/hash_compare_helper.rb
|
259
|
+
- lib/hashes_equal/hash_diff_displayer.rb
|
260
|
+
- lib/hashes_equal/version.rb
|
261
|
+
homepage: https://github.com/Facilecomm/hashes_equal
|
262
|
+
licenses:
|
263
|
+
- MIT
|
264
|
+
metadata: {}
|
265
|
+
post_install_message:
|
266
|
+
rdoc_options: []
|
267
|
+
require_paths:
|
268
|
+
- lib
|
269
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
270
|
+
requirements:
|
271
|
+
- - ">="
|
272
|
+
- !ruby/object:Gem::Version
|
273
|
+
version: 2.6.0
|
274
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
275
|
+
requirements:
|
276
|
+
- - ">="
|
277
|
+
- !ruby/object:Gem::Version
|
278
|
+
version: '0'
|
279
|
+
requirements: []
|
280
|
+
rubygems_version: 3.0.1
|
281
|
+
signing_key:
|
282
|
+
specification_version: 4
|
283
|
+
summary: MiniTest style assertion to compare hashes.
|
284
|
+
test_files: []
|