inspector_hashes 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 32f9991f9e5502cd172e4d18ce9ca3f00a463588
4
+ data.tar.gz: 7d5bbab7c81cccdfa40c92458e7843c7c140e018
5
+ SHA512:
6
+ metadata.gz: 0eae57aec23580490035b22a1b1929bb48be5fa2670087d6ea108479177858dfcc71584157883fff90e8b32fb440399a3cdfdce0c70a3641ed1d9fa586beaef1
7
+ data.tar.gz: f5c88eef54aeb1d308028784b1d1c94fd521928ff85692c83c811c0a0ad172c2a351b31282cb8e0f4276f825514d6447d757af066424ac4857a89be13f90de83
@@ -0,0 +1 @@
1
+ service_name: travis-ci
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1 @@
1
+ 2.4.0
@@ -0,0 +1,16 @@
1
+ sudo: false
2
+ language: ruby
3
+
4
+ addons:
5
+ code_climate:
6
+ repo_token: c15a6524170d4e8cccd5c7b7dd486be17fd56055a74d747a735032f17f198d74
7
+
8
+ rvm:
9
+ - 2.4.1
10
+ - 2.3.3
11
+ - 2.2.6
12
+ - 2.1.10
13
+ before_install: gem install bundler -v 1.14.6
14
+
15
+ after_success:
16
+ - bundle exec codeclimate-test-reporter
@@ -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 eturino@eturino.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 [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in inspector_hashes.gemspec
4
+ gemspec
5
+
6
+ gem 'coveralls', '>= 0.8.20', require: false
7
+
8
+ group :test do
9
+ gem 'codeclimate-test-reporter', '~> 1.0'
10
+ gem 'simplecov'
11
+ end
@@ -0,0 +1,70 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+
39
+ # Ruby files
40
+ ruby = dsl.ruby
41
+ dsl.watch_spec_files_for(ruby.lib_files)
42
+
43
+ # Rails files
44
+ rails = dsl.rails(view_extensions: %w(erb haml slim))
45
+ dsl.watch_spec_files_for(rails.app_files)
46
+ dsl.watch_spec_files_for(rails.views)
47
+
48
+ watch(rails.controllers) do |m|
49
+ [
50
+ rspec.spec.call("routing/#{m[1]}_routing"),
51
+ rspec.spec.call("controllers/#{m[1]}_controller"),
52
+ rspec.spec.call("acceptance/#{m[1]}")
53
+ ]
54
+ end
55
+
56
+ # Rails config changes
57
+ watch(rails.spec_helper) { rspec.spec_dir }
58
+ watch(rails.routes) { "#{rspec.spec_dir}/routing" }
59
+ watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
60
+
61
+ # Capybara features specs
62
+ watch(rails.view_dirs) { |m| rspec.spec.call("features/#{m[1]}") }
63
+ watch(rails.layouts) { |m| rspec.spec.call("features/#{m[1]}") }
64
+
65
+ # Turnip features and steps
66
+ watch(%r{^spec/acceptance/(.+)\.feature$})
67
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
68
+ Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
69
+ end
70
+ end
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Eduardo Turiño
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.
@@ -0,0 +1,155 @@
1
+ # InspectorHashes
2
+
3
+ [![Code Climate](https://codeclimate.com/github/eturino/inspector_hashes/badges/gpa.svg)](https://codeclimate.com/github/eturino/inspector_hashes)
4
+
5
+ [![Issue Count](https://codeclimate.com/github/eturino/inspector_hashes/badges/issue_count.svg)](https://codeclimate.com/github/eturino/inspector_hashes)
6
+
7
+ [![Test Coverage](https://codeclimate.com/github/eturino/inspector_hashes/badges/coverage.svg)](https://codeclimate.com/github/eturino/inspector_hashes/coverage)
8
+
9
+ [![Coverage Status](https://coveralls.io/repos/github/eturino/inspector_hashes/badge.svg?branch=master)](https://coveralls.io/github/eturino/inspector_hashes?branch=master)
10
+
11
+ Tests failing with huge responses that look basically the same? Don't really know where the issue is? If you try to use any string diff you can't see anything because all the errors are about key ordering in the hashes?
12
+
13
+
14
+ ```ruby
15
+ expected_data = {"data"=>[{"id"=>"1", "type"=>"people", "attributes"=>{"client-key"=>"kassulke-lebsack-and-quitzon-9-ltd", "employment-type"=>"employee", "name"=>"Ewell Ledner", "skills"=>["even-keeled", "methodical"], "start-date"=>"2014-11-20", "job-title"=>"Arsonist", "team-names"=>["Tatooine"], "ed-date"=>nil, "created-at"=>"2017-04-04T23:20:47Z", "current-role-names"=>["Junior Developer"], "current-main-role-name"=>"Junior Developer", "updated-at"=>"2017-04-04T23:20:47Z", "current-project-keys"=>["rm"], "first-activity-date"=>"2017-01-17", "current-main-role-priority"=>1, "salary-currency"=>nil, "last-activity-date"=>"2017-03-29", "person-roles-info"=>[{"role-name"=>"Junior Developer", "project-key"=>"ada"}, {"role-name"=>"Junior Developer", "project-key"=>"bi"}, {"role-name"=>"Junior Developer", "project-key"=>"boatint"}, {"role-name"=>"Junior Developer", "project-key"=>"plink"}, {"role-name"=>"Junior Developer", "project-key"=>"plinkresp"}, {"role-name"=>"Junior Developer", "project-key"=>"mt"}, {"role-name"=>"Junior Developer", "project-key"=>"rm"}, {"role-name"=>"Junior Developer", "project-key"=>"rmyc"}], "salary-period"=>nil, "salary"=>nil, "account-usernames"=>["ledner.ewell"]}}, {"id"=>"2", "type"=>"people", "attributes"=>{"job-title"=>"Arsonist", "client-key"=>"kassulke-lebsack-and-quitzon-9-ltd", "name"=>"Rolando Huel", "team-names"=>[], "created-at"=>"2017-04-04T23:20:47Z", "employment-type"=>"contractor", "start-date"=>"2015-01-05", "end-date"=>nil, "updated-at"=>"2017-04-04T23:20:47Z", "current-main-role-priority"=>10, "current-main-role-name"=>"Director", "skills"=>["directional"], "current-project-keys"=>["mt"], "first-activity-date"=>"2017-02-24", "salary-period"=>nil, "last-activity-date"=>"2017-04-04", "person-roles-info"=>[{"role-name"=>"Director", "project-key"=>"ada"}, {"role-name"=>"Director", "project-key"=>"bi"}, {"role-name"=>"Director", "project-key"=>"boatint"}, {"role-name"=>"Director", "project-key"=>"plink"}, {"role-name"=>"Director", "project-key"=>"plinkresp"}, {"role-name"=>"Director", "project-key"=>"mt"}, {"role-name"=>"Director", "project-key"=>"rm"}, {"role-name"=>"Director", "project-key"=>"rmyc"}], "current-role-names"=>["Director"], "account-usernames"=>["rolando.huel", "rolando_huel"], "salary-currency"=>nil, "salary"=>nil}}], "meta"=>{"total"=>2, "size"=>100, "page"=>1, "offset"=>0, "ids"=>[1, 2], "facets"=>{"team-names"=>[{"value"=>"Tatooine", "count"=>1}], "names"=>[{"value"=>"Rolando Huel", "count"=>1}, {"value"=>"Ewell Ledner", "count"=>1}], "role-names"=>[{"value"=>"Director", "count"=>1}, {"value"=>"Junior Developer", "count"=>1}], "main-roles"=>[{"value"=>"Director", "count"=>1}, {"value"=>"Junior Developer", "count"=>1}], "project-keys"=>[{"value"=>"mt", "count"=>1}, {"value"=>"rm", "count"=>1}], "employment-types"=>[{"value"=>"contractor", "count"=>1}, {"value"=>"employee", "count"=>1}]}}}
16
+
17
+ response_data = {"data"=>[{"id"=>"1", "type"=>"people", "attributes"=>{"client-key"=>"kassulke-lebsack-and-quitzon-9-ltd", "name"=>"Ewell Ledner", "job-title"=>"Arsonist", "employment-type"=>"employee", "team-names"=>["Tatooine"], "start-date"=>"2014-11-20", "end-date"=>nil, "skills"=>["even-keeled", "methodical"], "created-at"=>"2017-04-04T23:20:47Z", "updated-at"=>"2017-04-04T23:20:47Z", "current-main-role-priority"=>1, "current-main-role-name"=>"Junior Developer", "current-project-keys"=>["rm"], "current-role-names"=>["Junior Developer"], "first-activity-date"=>"2017-01-17", "last-activity-date"=>"2017-03-29", "person-roles-info"=>[{"role-name"=>"Junior Developer", "project-key"=>"ada"}, {"role-name"=>"Junior Developer", "project-key"=>"bi"}, {"role-name"=>"Junior Developer", "project-key"=>"boatint"}, {"role-name"=>"Junior Developer", "project-key"=>"plink"}, {"role-name"=>"Junior Developer", "project-key"=>"plinkresp"}, {"role-name"=>"Junior Developer", "project-key"=>"mt"}, {"role-name"=>"Junior Developer", "project-key"=>"rm"}, {"role-name"=>"Junior Developer", "project-key"=>"rmyc"}], "account-usernames"=>["ledner.ewell"], "salary"=>nil, "salary-currency"=>nil, "salary-period"=>nil}}, {"id"=>"2", "type"=>"people", "attributes"=>{"client-key"=>"kassulke-lebsack-and-quitzon-9-ltd", "name"=>"Rolando Huel", "job-title"=>"Arsonist", "employment-type"=>"contractor", "team-names"=>[], "start-date"=>"2015-01-05", "end-date"=>nil, "skills"=>["directional"], "created-at"=>"2017-04-04T23:20:47Z", "updated-at"=>"2017-04-04T23:20:47Z", "current-main-role-priority"=>10, "current-main-role-name"=>"Director", "current-project-keys"=>["mt"], "current-role-names"=>["Director"], "first-activity-date"=>"2017-02-24", "last-activity-date"=>"2017-04-04", "person-roles-info"=>[{"role-name"=>"Director", "project-key"=>"ada"}, {"role-name"=>"Director", "project-key"=>"bi"}, {"role-name"=>"Director", "project-key"=>"boatint"}, {"role-name"=>"Director", "project-key"=>"plink"}, {"role-name"=>"Director", "project-key"=>"plinkresp"}, {"role-name"=>"Director", "project-key"=>"mt"}, {"role-name"=>"Director", "project-key"=>"rm"}, {"role-name"=>"Director", "project-key"=>"rmyc"}], "account-usernames"=>["rolando.huel", "rolando_huel"], "salary"=>nil, "salary-currency"=>nil, "salary-period"=>nil}}], "meta"=>{"total"=>2, "size"=>100, "page"=>1, "offset"=>0, "ids"=>[1, 2], "facets"=>{"team-names"=>[{"value"=>"Tatooine", "count"=>1}], "names"=>[{"value"=>"Rolando Huel", "count"=>1}, {"value"=>"Ewell Ledner", "count"=>1}], "role-names"=>[{"value"=>"Director", "count"=>1}, {"value"=>"Junior Developer", "count"=>1}], "main-roles"=>[{"value"=>"Director", "count"=>1}, {"value"=>"Junior Developer", "count"=>1}], "project-keys"=>[{"value"=>"mt", "count"=>1}, {"value"=>"rm", "count"=>1}], "employment-types"=>[{"value"=>"contractor", "count"=>1}, {"value"=>"employee", "count"=>1}]}}}
18
+
19
+ expected_data == response_data #=> false
20
+
21
+ ```
22
+
23
+ but where?
24
+
25
+ A string diff is going to spot a lot of false positives just because the order of the keys in your expected data is not the same as the order of the keys in your response data. That's not really helpful. And Rspec will show something like
26
+
27
+ ```
28
+ -"data" => [{"id"=>"1", "type"=>"people", "attributes"=>{"client-key"=>"kassulke-lebsack-and-quitzon-9-ltd", "employment-type"=>"employee", "name"=>"Ewell Ledner", "skills"=>["even-keeled", "methodical"], "start-date"=>"2014-11-20", "job-title"=>"Arsonist", "team-names"=>["Tatooine"], "ed-date"=>nil, "created-at"=>"2017-04-04T23:20:47Z", "current-role-names"=>["Junior Developer"], "current-main-role-name"=>"Junior Developer", "updated-at"=>"2017-04-04T23:20:47Z", "current-project-keys"=>["rm"], "first-activity-date"=>"2017-01-17", "current-main-role-priority"=>1, "salary-currency"=>nil, "last-activity-date"=>"2017-03-29", "person-roles-info"=>[{"role-name"=>"Junior Developer", "project-key"=>"ada"}, {"role-name"=>"Junior Developer", "project-key"=>"bi"}, {"role-name"=>"Junior Developer", "project-key"=>"boatint"}, {"role-name"=>"Junior Developer", "project-key"=>"plink"}, {"role-name"=>"Junior Developer", "project-key"=>"plinkresp"}, {"role-name"=>"Junior Developer", "project-key"=>"mt"}, {"role-name"=>"Junior Developer", "project-key"=>"rm"}, {"role-name"=>"Junior Developer", "project-key"=>"rmyc"}], "salary-period"=>nil, "salary"=>nil, "account-usernames"=>["ledner.ewell"]}}, {"id"=>"2", "type"=>"people", "attributes"=>{"job-title"=>"Arsonist", "client-key"=>"kassulke-lebsack-and-quitzon-9-ltd", "name"=>"Rolando Huel", "team-names"=>[], "created-at"=>"2017-04-04T23:20:47Z", "employment-type"=>"contractor", "start-date"=>"2015-01-05", "end-date"=>nil, "updated-at"=>"2017-04-04T23:20:47Z", "current-main-role-priority"=>10, "current-main-role-name"=>"Director", "skills"=>["directional"], "current-project-keys"=>["mt"], "first-activity-date"=>"2017-02-24", "salary-period"=>nil, "last-activity-date"=>"2017-04-04", "person-roles-info"=>[{"role-name"=>"Director", "project-key"=>"ada"}, {"role-name"=>"Director", "project-key"=>"bi"}, {"role-name"=>"Director", "project-key"=>"boatint"}, {"role-name"=>"Director", "project-key"=>"plink"}, {"role-name"=>"Director", "project-key"=>"plinkresp"}, {"role-name"=>"Director", "project-key"=>"mt"}, {"role-name"=>"Director", "project-key"=>"rm"}, {"role-name"=>"Director", "project-key"=>"rmyc"}], "current-role-names"=>["Director"], "account-usernames"=>["rolando.huel", "rolando_huel"], "salary-currency"=>nil, "salary"=>nil}}],
29
+ +"data" => [{"id"=>"1", "type"=>"people", "attributes"=>{"client-key"=>"kassulke-lebsack-and-quitzon-9-ltd", "name"=>"Ewell Ledner", "job-title"=>"Arsonist", "employment-type"=>"employee", "team-names"=>["Tatooine"], "start-date"=>"2014-11-20", "end-date"=>nil, "skills"=>["even-keeled", "methodical"], "created-at"=>"2017-04-04T23:20:47Z", "updated-at"=>"2017-04-04T23:20:47Z", "current-main-role-priority"=>1, "current-main-role-name"=>"Junior Developer", "current-project-keys"=>["rm"], "current-role-names"=>["Junior Developer"], "first-activity-date"=>"2017-01-17", "last-activity-date"=>"2017-03-29", "person-roles-info"=>[{"role-name"=>"Junior Developer", "project-key"=>"ada"}, {"role-name"=>"Junior Developer", "project-key"=>"bi"}, {"role-name"=>"Junior Developer", "project-key"=>"boatint"}, {"role-name"=>"Junior Developer", "project-key"=>"plink"}, {"role-name"=>"Junior Developer", "project-key"=>"plinkresp"}, {"role-name"=>"Junior Developer", "project-key"=>"mt"}, {"role-name"=>"Junior Developer", "project-key"=>"rm"}, {"role-name"=>"Junior Developer", "project-key"=>"rmyc"}], "account-usernames"=>["ledner.ewell"], "salary"=>nil, "salary-currency"=>nil, "salary-period"=>nil}}, {"id"=>"2", "type"=>"people", "attributes"=>{"client-key"=>"kassulke-lebsack-and-quitzon-9-ltd", "name"=>"Rolando Huel", "job-title"=>"Arsonist", "employment-type"=>"contractor", "team-names"=>[], "start-date"=>"2015-01-05", "end-date"=>nil, "skills"=>["directional"], "created-at"=>"2017-04-04T23:20:47Z", "updated-at"=>"2017-04-04T23:20:47Z", "current-main-role-priority"=>10, "current-main-role-name"=>"Director", "current-project-keys"=>["mt"], "current-role-names"=>["Director"], "first-activity-date"=>"2017-02-24", "last-activity-date"=>"2017-04-04", "person-roles-info"=>[{"role-name"=>"Director", "project-key"=>"ada"}, {"role-name"=>"Director", "project-key"=>"bi"}, {"role-name"=>"Director", "project-key"=>"boatint"}, {"role-name"=>"Director", "project-key"=>"plink"}, {"role-name"=>"Director", "project-key"=>"plinkresp"}, {"role-name"=>"Director", "project-key"=>"mt"}, {"role-name"=>"Director", "project-key"=>"rm"}, {"role-name"=>"Director", "project-key"=>"rmyc"}], "account-usernames"=>["rolando.huel", "rolando_huel"], "salary"=>nil, "salary-currency"=>nil, "salary-period"=>nil}}],
30
+ "meta" => {"total"=>2, "size"=>100, "page"=>1, "offset"=>0, "ids"=>[1, 2], "facets"=>{"team-names"=>[{"value"=>"Tatooine", "count"=>1}], "names"=>[{"value"=>"Rolando Huel", "count"=>1}, {"value"=>"Ewell Ledner", "count"=>1}], "role-names"=>[{"value"=>"Director", "count"=>1}, {"value"=>"Junior Developer", "count"=>1}], "main-roles"=>[{"value"=>"Director", "count"=>1}, {"value"=>"Junior Developer", "count"=>1}], "project-keys"=>[{"value"=>"mt", "count"=>1}, {"value"=>"rm", "count"=>1}], "employment-types"=>[{"value"=>"contractor", "count"=>1}, {"value"=>"employee", "count"=>1}]}},
31
+ ```
32
+
33
+ which tells you that while `meta` is the same in both, `data` is different.
34
+
35
+ What you want is to spot that your expected data has a typo, and you expect `ed-date` instead of `end-date` in one of the objects.
36
+
37
+ What you want is something like this:
38
+ ```ruby
39
+ # diff:
40
+ [{:where=>"data > 0 > attributes > ed-date",
41
+ :a=>nil,
42
+ :b=>"<<<key not present>>>"},
43
+ {:where=>"data > 0 > attributes > end-date",
44
+ :a=>"<<<key not present>>>",
45
+ :b=>nil}]
46
+ ```
47
+
48
+ so in `data` array, in the first element (index `0`), in the hash `attributes`, you have misspelled `end-date`.
49
+
50
+ Notice that it has figure out that even when the expected value was `nil`.
51
+
52
+ ## Usage
53
+
54
+ ```ruby
55
+ diff = InspectorHashes.diff(something, similar)
56
+ ```
57
+
58
+ the response of `InspectorHashes.diff` can be:
59
+ - `nil`: those 2 are equal (using `==`)
60
+ - a single "diff object" like `{ where: "", a: <something>, b: <similar> }`: the 2 objects are different, but they are not `Array` or `Hash`
61
+ - if both are `Array` or both are `Hash` instances, a list of "diff objects" showing the differences.
62
+
63
+ Note that it will use `==` to compare equality. For example, all of these are considered equivalent:
64
+ - `1` and `1.0`
65
+ - `[1, 2, 3]` and `[1, 2.0, 3]`
66
+
67
+ ### `where` key
68
+
69
+ in a "diff object" the `where` value shows the path where the diff occurs. It's composed of the list of keys (in Hash) or index (in Array) that you have to follow to get there, separated by ` > `.
70
+
71
+ ```ruby
72
+ diff = InspectorHashes.diff(something, similar)
73
+ #
74
+ # => [{:where=>"data > 0 > attributes > ed-date",
75
+ # :a=>nil,
76
+ # :b=>"<<<key not present>>>"},
77
+ # {:where=>"data > 0 > attributes > end-date",
78
+ # :a=>"<<<key not present>>>",
79
+ # :b=>nil}]
80
+
81
+ first_where = 'data > 0 > attributes > ed-date'
82
+ first_a = a['data'][0]['attributes']['ed-date']
83
+ first_b = b['data'][0]['attributes']['ed-date']
84
+
85
+ ```
86
+
87
+ note that if the key (or index) is not present in any of the objects, it will show `<<<key not present>>>`.
88
+
89
+ if they keys are symbols, where would look like:
90
+
91
+ ```ruby
92
+ where_with_symbols_and_strings = 'data > 0 > :attributes > ed-date'
93
+ first_a = a['data'][0][:attributes]['ed-date']
94
+ first_b = b['data'][0][:attributes]['ed-date']
95
+
96
+ ```
97
+
98
+ a string and a symbol are not considered equal: not in the values nor in the keys.
99
+
100
+ example of diff result:
101
+ ```ruby
102
+ [
103
+ # typo in a['data'][0]['attributes'] vs b['data'][0]['attributes'],
104
+ # one key is called `ed-date` and the other `end-date`
105
+ { where: 'data > 0 > attributes > ed-date', a: nil, b: '<<<key not present>>>' },
106
+ { where: 'data > 0 > attributes > end-date', a: '<<<key not present>>>', b: nil },
107
+
108
+ # one value is a string, the other a symbol
109
+ # a['meta']['facets']['employment-types'][1]['value'] == 'employee'
110
+ # b['meta']['facets']['employment-types'][1]['value'] == :employee
111
+ { where: 'meta > facets > employment-types > 1 > value', a: 'employee', b: :employee },
112
+
113
+ # the order of the elements in the arrays are different:
114
+ # a['meta']['ids'] == [2, 1]
115
+ # b['meta']['ids'] == [1, 2]
116
+ { where: 'meta > ids > 0', a: 2, b: 1 },
117
+ { where: 'meta > ids > 1', a: 1, b: 2 },
118
+
119
+ # `size` key is a string in a['meta'] and a symbol in b['meta']
120
+ { where: 'meta > size', a: 100, b: '<<<key not present>>>' },
121
+ { where: 'meta > :size', a: '<<<key not present>>>', b: 100 },
122
+ ]
123
+ ```
124
+
125
+ ## Installation
126
+
127
+ Add this line to your application's Gemfile:
128
+
129
+ ```ruby
130
+ gem 'inspector_hashes'
131
+ ```
132
+
133
+ And then execute:
134
+
135
+ $ bundle
136
+
137
+ Or install it yourself as:
138
+
139
+ $ gem install inspector_hashes
140
+
141
+ ## Development
142
+
143
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
144
+
145
+ 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).
146
+
147
+ ## Contributing
148
+
149
+ Bug reports and pull requests are welcome on GitHub at https://github.com/eturino/inspector_hashes. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
150
+
151
+
152
+ ## License
153
+
154
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
155
+
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application '_guard-core' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("guard", "_guard-core")
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'inspector_hashes'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require 'pry'
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'guard' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("guard", "guard")
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+ #
4
+ # This file was generated by Bundler.
5
+ #
6
+ # The application 'rake' is installed as part of a gem, and
7
+ # this file is here to facilitate running it.
8
+ #
9
+
10
+ require "pathname"
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
+ Pathname.new(__FILE__).realpath)
13
+
14
+ require "rubygems"
15
+ require "bundler/setup"
16
+
17
+ load Gem.bin_path("rake", "rake")
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'inspector_hashes/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'inspector_hashes'
9
+ spec.version = InspectorHashes::VERSION
10
+ spec.authors = ['Eduardo Turiño']
11
+ spec.email = ['eturino@eturino.com']
12
+
13
+ spec.summary = <<-TXT
14
+ InspectorHashes helps finding hidden differences in hashes and arrays, included nested, also spotting missing keys or indices
15
+ TXT
16
+ spec.description = <<-TXT
17
+ specially useful for spotting differences between expected json response and actual json response on requests specs
18
+ TXT
19
+ spec.homepage = 'https://github.com/eturino/inspector_hashes'
20
+ spec.license = 'MIT'
21
+
22
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
23
+ f.match(%r{^(test|spec|features)/})
24
+ end
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_development_dependency 'bundler', '~> 1.14'
30
+ spec.add_development_dependency 'guard-rspec', '~> 4.7'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'rspec', '~> 3.0'
33
+ end
@@ -0,0 +1,13 @@
1
+ require 'inspector_hashes/version'
2
+ require 'inspector_hashes/inspector'
3
+
4
+ # `InspectorHashes.diff(a, b)` will return the array of differences.
5
+ module InspectorHashes
6
+ def self.diff(a, b)
7
+ inspector_for(a, b).call
8
+ end
9
+
10
+ def self.inspector_for(a, b)
11
+ Inspector.new a: a, b: b
12
+ end
13
+ end
@@ -0,0 +1,84 @@
1
+ module InspectorHashes
2
+
3
+ # `InspectorHashes.diff(a, b)` will return:
4
+ # - nil (if equal)
5
+ # - if given simple objects, a single difference object:
6
+ # ```
7
+ # { where: '', a: a, b: b }
8
+ # ```
9
+ # - if a hash or an array: the array of differences.
10
+ class Inspector
11
+ attr_accessor :a, :b, :a_exists, :b_exists, :prefixes
12
+
13
+ SEPARATOR = ' > '.freeze
14
+ NO_KEY = '<<<key not present>>>'.freeze
15
+
16
+ def initialize(a:, b:, a_exists: true, b_exists: true, prefixes: [])
17
+ self.a = a
18
+ self.b = b
19
+ self.a_exists = a_exists
20
+ self.b_exists = b_exists
21
+ self.prefixes = prefixes
22
+ end
23
+
24
+ def call
25
+ return nil if a_exists && b_exists && a == b
26
+
27
+ prepare_diff
28
+ end
29
+
30
+ private
31
+
32
+ def prepare_diff
33
+ return diff_array if a.is_a?(Array) && b.is_a?(Array)
34
+ return diff_hash if a.is_a?(Hash) && b.is_a?(Hash)
35
+
36
+ { where: prefixes.join(SEPARATOR), a: a_log_value, b: b_log_value }
37
+ end
38
+
39
+ def diff_array
40
+ longest = a.length > b.length ? a : b
41
+ diff_enumerable longest.each_index, :check_array_has_index
42
+ end
43
+
44
+ def diff_hash
45
+ keys = (a.keys + b.keys).uniq.sort_by(&:to_s)
46
+ diff_enumerable keys.uniq, :check_hash_has_key
47
+ end
48
+
49
+ def diff_enumerable(key_enumerable, check_method)
50
+ key_enumerable.map do |key|
51
+ inspector_for(key, check_method).call
52
+ end.compact.flatten
53
+ end
54
+
55
+ def inspector_for(key, check_method)
56
+ Inspector.new a: a[key],
57
+ b: b[key],
58
+ a_exists: send(check_method, a, key),
59
+ b_exists: send(check_method, b, key),
60
+ prefixes: prefixes_for(key)
61
+ end
62
+
63
+ def prefixes_for(key)
64
+ new_prefix = key.is_a?(String) ? key : key.inspect
65
+ prefixes.dup.tap { |l| l << new_prefix }
66
+ end
67
+
68
+ def b_log_value
69
+ b_exists ? b : NO_KEY
70
+ end
71
+
72
+ def a_log_value
73
+ a_exists ? a : NO_KEY
74
+ end
75
+
76
+ def check_array_has_index(list, index)
77
+ list.length > index
78
+ end
79
+
80
+ def check_hash_has_key(hash, key)
81
+ hash.key? key
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,3 @@
1
+ module InspectorHashes
2
+ VERSION = '1.0.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: inspector_hashes
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Eduardo Turiño
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-04-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: guard-rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description: " specially useful for spotting differences between expected json response
70
+ and actual json response on requests specs\n"
71
+ email:
72
+ - eturino@eturino.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".coveralls.yml"
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".ruby-version"
81
+ - ".travis.yml"
82
+ - CODE_OF_CONDUCT.md
83
+ - Gemfile
84
+ - Guardfile
85
+ - LICENSE.txt
86
+ - README.md
87
+ - Rakefile
88
+ - bin/_guard-core
89
+ - bin/console
90
+ - bin/guard
91
+ - bin/rake
92
+ - bin/setup
93
+ - inspector_hashes.gemspec
94
+ - lib/inspector_hashes.rb
95
+ - lib/inspector_hashes/inspector.rb
96
+ - lib/inspector_hashes/version.rb
97
+ homepage: https://github.com/eturino/inspector_hashes
98
+ licenses:
99
+ - MIT
100
+ metadata: {}
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.6.8
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: InspectorHashes helps finding hidden differences in hashes and arrays, included
121
+ nested, also spotting missing keys or indices
122
+ test_files: []