rspec-hash_matchers 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ea2a03da6e3912a91d08f5fc6108f17f0dcffac7
4
+ data.tar.gz: 557ec4129a587ac8e6f5341e1cdff7e41485d49b
5
+ SHA512:
6
+ metadata.gz: 3df47e60b9de66c56e1c6d943c6271fde23006e1522a3ace80ff8a95a5f9a0d15008f3a5ebfac23ca3149ea697e602339f4a0f333bf4630e1b64c24fbf71f1d7
7
+ data.tar.gz: 767c7411e29f503fc10230bb689a67bc6343171c3a41e946f5f03e580ac54f9c0063cf17e321b668ca8422371a161abeedb1e6dd6d1fab0dcf5315a32a1932a6
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.3
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rspec-hash_matchers.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # RSpec::HashMatchers
2
+
3
+ This gem is an extension to [RSpec](https://github.com/rspec/rspec) that allows
4
+ additional matchers for ruby hashes.
5
+
6
+ Especially useful when testing API responses.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'rspec-hash_matchers'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install rspec-hash_matchers
23
+
24
+ ## Usage
25
+
26
+ ### Contain exactly keys (in array)
27
+
28
+ Like RSpec's `contain_exactly`, but for hash and array of hashes.
29
+
30
+ * Order never matters
31
+ * Allows any mix of keys and keys with values (make sure you put the keys with
32
+ values last)
33
+ * Must contain all entries (hash keys or array entries), nothing more and
34
+ nothing less
35
+
36
+ ```ruby
37
+ specify do
38
+ # Hash
39
+ expect(a: 1, b: 2, c: 3, d: 4).to contain_exactly_keys :d, :b, c: 3, a: 1
40
+ # Array of hashes
41
+ expect([
42
+ { a: 1, b: 2, c: 3 },
43
+ { d: 4, e: 5, f: 6 },
44
+ { g: 7, h: 8, i: 9 },
45
+ ]).to contain_exactly_keys_in_array(
46
+ [:e, f: 6, d: 4], # second line
47
+ [:a, :b, :c], # first line
48
+ { i: 9, h: 8, g: 7 }, # third line
49
+ )
50
+ end
51
+ ```
52
+
53
+ See [the spec](spec/rspec/hash_matchers/contain_exactly_spec.rb) for all
54
+ examples of matches and mismatches.
55
+
56
+ ## Development
57
+
58
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
59
+
60
+ 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).
61
+
62
+ ## Contributing
63
+
64
+ Bug reports and pull requests are welcome on GitHub at https://github.com/odedniv/rspec-hash_matchers. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
65
+
data/Rakefile ADDED
@@ -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
data/UNLICENSE ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org/>
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rspec/hash_matchers"
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
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,48 @@
1
+ require 'active_support'
2
+
3
+ module RSpec
4
+ module HashMatchers
5
+ module ContainExactly
6
+ extend RSpec::Matchers::DSL
7
+
8
+ matcher :contain_exactly_keys do |*expected|
9
+ match do |actual|
10
+ hash_matchers_contain_exactly_keys?(actual, expected)
11
+ end
12
+ end
13
+
14
+ matcher :contain_exactly_keys_in_array do |*expected|
15
+ match do |actual|
16
+ next false if not actual.is_a?(Array)
17
+ next false if actual.length != expected.length
18
+ actual = actual.clone
19
+ expected = expected.clone
20
+ result = true
21
+ while expected.any?
22
+ e = expected.shift
23
+ i = actual.find_index { |a| hash_matchers_contain_exactly_keys?(a, e) }
24
+ break result = false if i.nil?
25
+ actual.delete_at(i)
26
+ end
27
+ result
28
+ end
29
+ end
30
+
31
+ def hash_matchers_contain_exactly_keys?(actual, expected)
32
+ return false if not actual.is_a?(Hash)
33
+
34
+ array = expected.is_a?(Hash) ? [expected] : expected.clone
35
+ hash = array.extract_options!
36
+
37
+ return false if actual.length != array.length + hash.length
38
+ return false if array.any? { |k| not actual.include?(k) }
39
+ return false if hash.any? { |k, v| actual[k] != v }
40
+ true
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ RSpec.configure do |config|
47
+ config.include RSpec::HashMatchers::ContainExactly
48
+ end
@@ -0,0 +1,5 @@
1
+ module RSpec
2
+ module HashMatchers
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "rspec/hash_matchers/version"
2
+ require "rspec/hash_matchers/contain_exactly"
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rspec/hash_matchers/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rspec-hash_matchers"
8
+ spec.version = RSpec::HashMatchers::VERSION
9
+ spec.authors = ["Oded Niv"]
10
+ spec.email = ["oded.niv@gmail.com"]
11
+
12
+ spec.summary = %q{Better matchers for hashes.}
13
+ spec.description = %q{RSpec extension to better match hashes.}
14
+ spec.homepage = "https://github.com/odedniv/rspec-hash_matchers"
15
+ spec.license = "UNLICENSE"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "rspec-expectations", ">= 3.0"
23
+ spec.add_runtime_dependency "activesupport", ">= 2.0"
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.10"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec"
28
+ end
metadata ADDED
@@ -0,0 +1,128 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-hash_matchers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Oded Niv
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-06-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec-expectations
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
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'
83
+ description: RSpec extension to better match hashes.
84
+ email:
85
+ - oded.niv@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - README.md
96
+ - Rakefile
97
+ - UNLICENSE
98
+ - bin/console
99
+ - bin/setup
100
+ - lib/rspec/hash_matchers.rb
101
+ - lib/rspec/hash_matchers/contain_exactly.rb
102
+ - lib/rspec/hash_matchers/version.rb
103
+ - rspec-hash_matchers.gemspec
104
+ homepage: https://github.com/odedniv/rspec-hash_matchers
105
+ licenses:
106
+ - UNLICENSE
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.4.7
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Better matchers for hashes.
128
+ test_files: []