match_hash 0.1.1

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: 9444052b2bfb07b0870ee7f202ee53abba6ec312
4
+ data.tar.gz: cc64e3822421f8b999f873ae846933ec872a7111
5
+ SHA512:
6
+ metadata.gz: f8d70c66123189688786ecbcf5f3d9d796a405b7a87991c5ef8fce2fee3031d1fbf5ca75215291fe6165ab3efc891b95d8747baa2c71dabc4399ed96e263352f
7
+ data.tar.gz: '095625802374af8d88235c5d0fb2a72678701d41db787bd658934da152fa4bf4f67b403171a7ed08601c2b3b91f05b6d8cd61ecd013f625a39d7bcb821897c62'
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ # Ignore bundler config.
2
+ /.bundle
3
+
4
+ # Ignore all logfiles and tempfiles.
5
+ /log/*
6
+ /tmp/*
7
+ !/log/.keep
8
+ !/tmp/.keep
9
+ *.log*
10
+
11
+ # Ignore Byebug command history file.
12
+ .byebug_history
13
+
14
+ # gemは無視
15
+ /vendor/bundle
16
+ .DS_Store
17
+
18
+ # RubyMineが勝手に作ってしまうファイル
19
+ .idea
20
+
21
+ pkg
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.13.6
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ ## v0.1.1
2
+ 2016-01-03
3
+ * RENAME lib/environment.rb -> lib/match_hash.rb
4
+ * ADD CHANGELOG.md & README.md
5
+
6
+ ## v0.1.0
7
+ 2016-01-01
8
+ * First Release
9
+
10
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in match_hash.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,36 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ match_hash (0.1.0)
5
+ rspec-expectations (~> 3.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ diff-lcs (1.2.5)
11
+ rake (10.5.0)
12
+ rspec (3.5.0)
13
+ rspec-core (~> 3.5.0)
14
+ rspec-expectations (~> 3.5.0)
15
+ rspec-mocks (~> 3.5.0)
16
+ rspec-core (3.5.4)
17
+ rspec-support (~> 3.5.0)
18
+ rspec-expectations (3.5.0)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.5.0)
21
+ rspec-mocks (3.5.0)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.5.0)
24
+ rspec-support (3.5.0)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bundler (~> 1.13)
31
+ match_hash!
32
+ rake (~> 10.5.0)
33
+ rspec (~> 3.0)
34
+
35
+ BUNDLED WITH
36
+ 1.13.6
data/README.md ADDED
@@ -0,0 +1,101 @@
1
+ # MatchHash
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/match_hash.svg)](https://badge.fury.io/rb/match_hash)
4
+ [![wercker status](https://app.wercker.com/status/b7b6922e7a90870633ac09993e8aa51b/s/master "wercker status")](https://app.wercker.com/project/byKey/b7b6922e7a90870633ac09993e8aa51b)
5
+
6
+ Easily handle Hash in RSpec.
7
+
8
+ ## RSpec
9
+
10
+ match_hash defines one new RSpec matcher:
11
+
12
+ * `match_hash`
13
+
14
+ ## Installation
15
+
16
+ Add this line to your application's `Gemfile` :
17
+
18
+ ```ruby
19
+ gem 'match_hash'
20
+ ```
21
+ Add this line to your application's `spec_helper.rb` :
22
+ ```ruby
23
+ require 'match_hash'
24
+ ```
25
+
26
+ And then execute:
27
+
28
+ $ bundle
29
+
30
+ Or install it yourself as:
31
+
32
+ $ gem install match_hash
33
+
34
+ ## Usage
35
+
36
+ The new matcher could be used in RSpec as follows:
37
+
38
+ ```ruby
39
+ 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],
49
+ }
50
+
51
+ @B = {
52
+ a11:11,
53
+ a12:{
54
+ b11:21,
55
+ b12:22
56
+ },
57
+ a13:[3,2,1],
58
+ }
59
+ end
60
+
61
+ it "A hash match A hash" do
62
+ expect(@A).to match_hash(@A)
63
+ end
64
+
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
69
+ end
70
+
71
+ end
72
+ ```
73
+
74
+ ## Failure message
75
+
76
+ For example:
77
+
78
+ ```ruby
79
+ 1) MatchHash A hash match A hash
80
+ Failure/Error: expect(@A).to match_hash(@B)
81
+
82
+ Diff:
83
+ @@ -2,6 +2,6 @@
84
+ :a12 => 12,
85
+ :a13 => 13,
86
+ :a14 => {:b11=>11, :b12=>12},
87
+ -:a15 => [3, 2, 1],
88
+ +:a15 => [1, 2, 3],
89
+ :a16 => 16,
90
+
91
+ # ./spec/match_hash_spec.rb:36:in `block (2 levels) in <top (required)>'
92
+ ```
93
+
94
+ ## Contributing
95
+
96
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yukihirop/match_hash.
97
+
98
+ ## Licence
99
+
100
+ * MIT
101
+
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "match_hash"
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,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,31 @@
1
+ # GitHub Gist
2
+ # kroehre/ gist:9cc209bcf43a1d1b001b
3
+ # より引用&一部改造
4
+
5
+ # @abstract json形式のhashのkeyの数と値、hashの構造、keyとvalueのペアの一致(hash完全一致、順不同)
6
+ # をテストする.
7
+ # @params [Hash] expected テストするために用意したhash
8
+ # @example expect(result).to match_hash(data,nil)
9
+ # @note gem 'rspec-rails', '~> 3.5'
10
+ # をGemfileを追加していること
11
+ # @see https://gist.github.com/kroehre/9cc209bcf43a1d1b001b
12
+ RSpec::Matchers.define :match_hash do |expected|
13
+
14
+ include Sub
15
+ match do |actual|
16
+ @is_errors = []
17
+ !match_hash(expected, actual)
18
+ end
19
+
20
+ # RSpecc::Matchers::ExpectedsForMultipleDiffsは
21
+ # private apiであり、Deprecatedであるが今、diffを取るにはこうするしかない。(2016/12/29現在)
22
+ # @see https://github.com/rspec/rspec-expectations/blob/master/lib/rspec/expectations/fail_with.rb
23
+ # @see https://github.com/rspec/rspec-expectations/blob/master/lib/rspec/matchers/expecteds_for_multiple_diffs.rb
24
+ failure_message do |actual|
25
+ differ = RSpec::Expectations.differ
26
+ @failure_message = RSpec::Matchers::ExpectedsForMultipleDiffs.from(expected).message_with_diff(nil, differ,actual)
27
+ @failure_message
28
+ end
29
+
30
+ end
31
+
@@ -0,0 +1,35 @@
1
+ module Sub
2
+
3
+ private
4
+
5
+ def match_hash(expected, actual)
6
+ expected.each do |key, value|
7
+ return true unless actual.has_key?(key)
8
+ @is_errors << match_value(expected[key], actual[key])
9
+ return true if @is_errors.include?(true)
10
+ end
11
+
12
+ return true if @is_errors.include?(true)
13
+ actual.each do |key, value|
14
+ return true unless expected.has_key?(key)
15
+ @is_errors << match_value(expected[key], actual[key])
16
+ return true if @is_errors.include?(true)
17
+ end
18
+ @is_errors.include?(true)
19
+ end
20
+
21
+ def match_array(expected, actual)
22
+ expected.each_with_index do |i|
23
+ match_value(expected[i],actual[i])
24
+ end
25
+ end
26
+
27
+ # trueを返すときがエラー
28
+ def match_value(expected, actual)
29
+ match_hash(expected, actual) if expected.is_a?(Hash)
30
+ match_array(expected, actual) if expected.is_a?(Array)
31
+ return false if expected == actual
32
+ return true
33
+ end
34
+
35
+ end
@@ -0,0 +1,3 @@
1
+ module MatchHash
2
+ VERSION = "0.1.1"
3
+ end
data/lib/match_hash.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "match_hash/version"
2
+ require "match_hash/match_hash"
3
+ require "match_hash/sub/match_hash"
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'match_hash/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "match_hash"
9
+ spec.version = MatchHash::VERSION
10
+ spec.authors = ["yukihirop"]
11
+ spec.email = ["te108186@gmail.com"]
12
+
13
+ spec.summary = "This is a Custom Matcher to match hash in RSpec"
14
+ spec.description = "Custom Matcher errors generate from RSpec::Matchers::ExpectedsForMultipleDiffs.from.message_with_diff"
15
+ spec.homepage = "https://github.com/yukihirop/match_hash"
16
+ spec.license = "MIT"
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ # if spec.respond_to?(:metadata)
21
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
22
+ # else
23
+ # raise "RubyGems 2.0 or newer is required to protect against " \
24
+ # "public gem pushes."
25
+ # end
26
+
27
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
28
+ f.match(%r{^(test|spec|features)/})
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ spec.add_runtime_dependency 'rspec-expectations', '~> 3.0'
35
+
36
+ spec.add_development_dependency "bundler", "~> 1.13"
37
+ spec.add_development_dependency "rake", "~> 10.5.0"
38
+ spec.add_development_dependency "rspec", "~> 3.0"
39
+
40
+ end
data/wercker.yml ADDED
@@ -0,0 +1,27 @@
1
+ # This references the default Ruby container from
2
+ # the Docker Hub.
3
+ # https://registry.hub.docker.com/_/ruby/
4
+ # If you want to use a specific version you would use a tag:
5
+ # ruby:2.2.2
6
+ box: ruby:2.3.1
7
+ # You can also use services such as databases. Read more on our dev center:
8
+ # http://devcenter.wercker.com/docs/services/index.html
9
+ # services:
10
+ # - postgres
11
+ # http://devcenter.wercker.com/docs/services/postgresql.html
12
+
13
+ # - mongo
14
+ # http://devcenter.wercker.com/docs/services/mongodb.html
15
+
16
+ # This is the build pipeline. Pipelines are the core of wercker
17
+ # Read more about pipelines on our dev center
18
+ # http://devcenter.wercker.com/docs/pipelines/index.html
19
+ build:
20
+ # Steps make up the actions in your pipeline
21
+ # Read more about steps on our dev center:
22
+ # http://devcenter.wercker.com/docs/steps/index.html
23
+ steps:
24
+ - bundle-install
25
+ - script:
26
+ name: rspec
27
+ code: bundle exec rspec
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: match_hash
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - yukihirop
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-03 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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
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.5.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.5.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: Custom Matcher errors generate from RSpec::Matchers::ExpectedsForMultipleDiffs.from.message_with_diff
70
+ email:
71
+ - te108186@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CHANGELOG.md
80
+ - Gemfile
81
+ - Gemfile.lock
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - lib/match_hash.rb
87
+ - lib/match_hash/match_hash.rb
88
+ - lib/match_hash/sub/match_hash.rb
89
+ - lib/match_hash/version.rb
90
+ - match_hash.gemspec
91
+ - wercker.yml
92
+ homepage: https://github.com/yukihirop/match_hash
93
+ licenses:
94
+ - MIT
95
+ metadata: {}
96
+ post_install_message:
97
+ rdoc_options: []
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ required_rubygems_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ requirements: []
111
+ rubyforge_project:
112
+ rubygems_version: 2.6.8
113
+ signing_key:
114
+ specification_version: 4
115
+ summary: This is a Custom Matcher to match hash in RSpec
116
+ test_files: []