rspec-match_table 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 +8 -0
- data/.rspec +2 -0
- data/.travis.yml +11 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +37 -0
- data/LICENSE.txt +21 -0
- data/README.md +70 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rspec/match_table.rb +29 -0
- data/lib/rspec/rspec_match_table.rb +25 -0
- data/rspec-match_table.gemspec +25 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 70ddaa683ec6febaad8108d84096a1059787493f
|
4
|
+
data.tar.gz: 4ace972c201e555f231c8756343ee10653841ed2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2dccf24f6ce8025e45f134e2b564d465b5c808d01557691ee55807c55fe10ec08d3378be9da8eaf22dbdaa035fd670fa85879dd711ee108f33e60197c60fecc4
|
7
|
+
data.tar.gz: 4b80fdb99c06d898414a391859c761774d58ba8027c4a73bd9adb1c221c7d397eb5412e2adb5b99e71596297a1e168f38cc8070b7ac5c7602883587ead7dbefe
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
rspec-match_table (0.1.0)
|
5
|
+
pp_sort_hash
|
6
|
+
rspec (~> 3)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
diff-lcs (1.3)
|
12
|
+
pp_sort_hash (0.1.0)
|
13
|
+
rake (10.5.0)
|
14
|
+
rspec (3.7.0)
|
15
|
+
rspec-core (~> 3.7.0)
|
16
|
+
rspec-expectations (~> 3.7.0)
|
17
|
+
rspec-mocks (~> 3.7.0)
|
18
|
+
rspec-core (3.7.0)
|
19
|
+
rspec-support (~> 3.7.0)
|
20
|
+
rspec-expectations (3.7.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.7.0)
|
23
|
+
rspec-mocks (3.7.0)
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
+
rspec-support (~> 3.7.0)
|
26
|
+
rspec-support (3.7.0)
|
27
|
+
|
28
|
+
PLATFORMS
|
29
|
+
ruby
|
30
|
+
|
31
|
+
DEPENDENCIES
|
32
|
+
bundler (~> 1.16)
|
33
|
+
rake (~> 10.0)
|
34
|
+
rspec-match_table!
|
35
|
+
|
36
|
+
BUNDLED WITH
|
37
|
+
1.16.0
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Genki Sugawara
|
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/README.md
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# rspec-match_table
|
2
|
+
|
3
|
+
It is array of hashes matcher.
|
4
|
+
|
5
|
+
[![Build Status](https://travis-ci.org/winebarrel/rspec-match_table.svg?branch=master)](https://travis-ci.org/winebarrel/rspec-match_table)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rspec-match_table'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rspec-match_table
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'rspec/match_table'
|
27
|
+
|
28
|
+
RSpec.describe do
|
29
|
+
specify do
|
30
|
+
context 'when not match' do
|
31
|
+
specify do
|
32
|
+
expect(
|
33
|
+
[
|
34
|
+
{foo: 'bar', 100 => :zoo, '100' => 100},
|
35
|
+
{bar: 'foo', 200 => :baz, '200' => 200},
|
36
|
+
{baz: 'bar', 300 => 'foo', '300' => 300},
|
37
|
+
]
|
38
|
+
).to match_table( # or match_table_without_order
|
39
|
+
[
|
40
|
+
{foo: 'bar', 100 => :zoo, '100' => 100},
|
41
|
+
{bar: 'foo', 200 => 'baz', '200' => 200},
|
42
|
+
{baz: 'bar', 300 => 'foo', '300' => 301},
|
43
|
+
]
|
44
|
+
)
|
45
|
+
#=> Failure/Error:
|
46
|
+
# expect(
|
47
|
+
# [
|
48
|
+
# {foo: 'bar', 100 => :zoo, '100' => 100},
|
49
|
+
# {bar: 'foo', 200 => :baz, '200' => 200},
|
50
|
+
# {baz: 'bar', 300 => 'foo', '300' => 300},
|
51
|
+
# ]
|
52
|
+
# ).to match_table(
|
53
|
+
# [
|
54
|
+
# {foo: 'bar', 100 => :zoo, '100' => 100},
|
55
|
+
# {bar: 'foo', 200 => 'baz', '200' => 200},
|
56
|
+
#
|
57
|
+
# expected: [{:foo=>"bar", 100=>:zoo, "100"=>100}, {:bar=>"foo", 200=>"baz", "200"=>200}, {:baz=>"bar", 300=>"foo", "300"=>301}]
|
58
|
+
# got: [{:foo=>"bar", 100=>:zoo, "100"=>100}, {:bar=>"foo", 200=>:baz, "200"=>200}, {:baz=>"bar", 300=>"foo", "300"=>300}]
|
59
|
+
#
|
60
|
+
# Diff:
|
61
|
+
# @@ -1,4 +1,4 @@
|
62
|
+
# [{100=>:zoo, "100"=>100, :foo=>"bar"},
|
63
|
+
# - {200=>"baz", "200"=>200, :bar=>"foo"},
|
64
|
+
# - {300=>"foo", "300"=>301, :baz=>"bar"}]
|
65
|
+
# + {200=>:baz, "200"=>200, :bar=>"foo"},
|
66
|
+
# + {300=>"foo", "300"=>300, :baz=>"bar"}]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
```
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rspec/match_table"
|
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__)
|
data/bin/setup
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'pp_sort_hash'
|
2
|
+
require 'rspec'
|
3
|
+
require 'rspec/rspec_match_table'
|
4
|
+
|
5
|
+
RSpec::Matchers.define :match_table do |expected|
|
6
|
+
RSpecMatchTable.check_type(expected)
|
7
|
+
|
8
|
+
match do |actual|
|
9
|
+
RSpecMatchTable.check_type(actual)
|
10
|
+
expected == actual
|
11
|
+
end
|
12
|
+
|
13
|
+
failure_message do |actual|
|
14
|
+
RSpecMatchTable.build_failure_message(expected, actual)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
RSpec::Matchers.define :match_table_without_order do |expected|
|
19
|
+
RSpecMatchTable.check_type(expected)
|
20
|
+
|
21
|
+
match do |actual|
|
22
|
+
RSpecMatchTable.check_type(actual)
|
23
|
+
expected.sort_by(&:to_s) == actual.sort_by(&:to_s)
|
24
|
+
end
|
25
|
+
|
26
|
+
failure_message do |actual|
|
27
|
+
RSpecMatchTable.build_failure_message(expected, actual)
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module RSpecMatchTable
|
2
|
+
def check_type(obj)
|
3
|
+
unless obj.is_a?(Array) and obj.all? {|i| i.is_a?(Hash) }
|
4
|
+
raise TypeError, "wrong type #{obj.inspect} (expected Array<Hash>)"
|
5
|
+
end
|
6
|
+
end
|
7
|
+
module_function :check_type
|
8
|
+
|
9
|
+
def build_failure_message(expected, actual)
|
10
|
+
message = <<-EOS.strip
|
11
|
+
expected: #{expected.inspect}
|
12
|
+
got: #{actual.inspect}
|
13
|
+
EOS
|
14
|
+
|
15
|
+
diff = RSpec::Expectations.differ.diff(actual.pretty_inspect, expected.pretty_inspect)
|
16
|
+
|
17
|
+
unless diff.strip.empty?
|
18
|
+
diff_label = RSpec::Matchers::ExpectedsForMultipleDiffs::DEFAULT_DIFF_LABEL
|
19
|
+
message << "\n\n" << diff_label << diff
|
20
|
+
end
|
21
|
+
|
22
|
+
message
|
23
|
+
end
|
24
|
+
module_function :build_failure_message
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "rspec-match_table"
|
6
|
+
spec.version = '0.1.0'
|
7
|
+
spec.authors = ['winebarrel']
|
8
|
+
spec.email = ['sugawara@winebarrel.jp']
|
9
|
+
|
10
|
+
spec.summary = %q{Array of hashes matcher.}
|
11
|
+
spec.description = %q{Array of hashes matcher.}
|
12
|
+
spec.homepage = 'https://github.com/winebarrel/rspec-match_table'
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
15
|
+
f.match(%r{^(test|spec|features)/})
|
16
|
+
end
|
17
|
+
spec.bindir = 'exe'
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_dependency 'rspec', '~> 3'
|
22
|
+
spec.add_dependency 'pp_sort_hash'
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-match_table
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- winebarrel
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-12-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pp_sort_hash
|
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: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
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
|
+
description: Array of hashes matcher.
|
70
|
+
email:
|
71
|
+
- sugawara@winebarrel.jp
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- Gemfile.lock
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- lib/rspec/match_table.rb
|
87
|
+
- lib/rspec/rspec_match_table.rb
|
88
|
+
- rspec-match_table.gemspec
|
89
|
+
homepage: https://github.com/winebarrel/rspec-match_table
|
90
|
+
licenses: []
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.6.13
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Array of hashes matcher.
|
112
|
+
test_files: []
|