rspec-rails-deep-ignore-order-matcher 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c3520010610972578f57074cf88597c71fd77d58
4
+ data.tar.gz: f03213cf2377fe356274d54c27ec0ddd15ac0baa
5
+ SHA512:
6
+ metadata.gz: edab07949689d15d2d7730b130c8cc99b4495dbdce3ecaf9330d3b6fea43e7ddaf77cdf3f0a08c4d2806201c8c56752388c32854a5f9e4476568c505d7434ac8
7
+ data.tar.gz: 9f709947553e0f2587850708d10a8d8d2d90e9350e3443504807fc6b93ed72eb0bb5a124481c91999beff153a5062d67b7e8cd3435af6692b4e4bc3689281318
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Alexey Mogilnikov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
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
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,32 @@
1
+ # RSpec Deep Matcher
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/rspec-deep-ignore-order-matcher.png)](http://badge.fury.io/rb/rspec-deep-ignore-order-matcher)
4
+
5
+ This gem adds a custom matcher to RSpec to recursively compare nested Ruby data-structures consisting of Hash and Array elements.
6
+ An order of elements in an array is ignored.
7
+
8
+ ## Install
9
+ ```
10
+ gem install rspec-deep-ignore-order-matcher
11
+ ```
12
+ or add to your `Gemfile`
13
+ ```
14
+ gem 'rspec-deep-ignore-order-matcher'
15
+ ```
16
+ and run
17
+ ```
18
+ bundle install
19
+ ```
20
+
21
+ ## Example
22
+ ```
23
+ require 'rspec-deep-ignore-order-matcher'
24
+
25
+ describe 'Products' do
26
+ it "should ignore order of product's tags" do
27
+ expected = [{ :product => { :title => 'Product 1', :tags => ['large', 'blue', 'heavy'] } }]
28
+ actual = [{ :product => { :title => 'Product 1', :tags => ['blue', 'large', 'heavy'] } }]
29
+ actual.should be_deep_equal expected
30
+ end
31
+ end
32
+ ```
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,40 @@
1
+ require 'rspec-rails'
2
+ require 'rspec-rails-deep-ignore-order-matcher/version'
3
+
4
+ RSpec::Matchers.define :be_deep_equal do |expected|
5
+ match { |actual| m? actual, expected }
6
+
7
+ failure_message do |actual|
8
+ "expected that #{actual} would be deep equal with #{expected}"
9
+ end
10
+
11
+ failure_message_when_negated do |actual|
12
+ "expected that #{actual} would not be deep equal with #{expected}"
13
+ end
14
+
15
+ description do
16
+ "be deep equal with #{expected}"
17
+ end
18
+
19
+ def m?(actual, expected)
20
+ return arrays_matches?(actual, expected) if expected.is_a?(Array) && actual.is_a?(Array)
21
+ return hashes_matches?(actual, expected) if expected.is_a?(Hash) && actual.is_a?(Hash)
22
+ expected == actual
23
+ end
24
+
25
+ def arrays_matches?(actual, expected)
26
+ exp = expected.clone
27
+ actual.each do |a|
28
+ index = exp.find_index { |e| m? a, e }
29
+ return false if index.nil?
30
+ exp.delete_at(index)
31
+ end
32
+ exp.length == 0
33
+ end
34
+
35
+ def hashes_matches?(actual, expected)
36
+ return false unless actual.keys.sort == expected.keys.sort
37
+ actual.each { |key, value| return false unless m? value, expected[key] }
38
+ true
39
+ end
40
+ end
@@ -0,0 +1,9 @@
1
+ module Deep
2
+ module Ignore
3
+ module Order
4
+ module Matcher
5
+ VERSION = '0.0.4'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rspec-rails-deep-ignore-order-matcher/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "rspec-rails-deep-ignore-order-matcher"
8
+ gem.version = Deep::Ignore::Order::Matcher::VERSION
9
+ gem.authors = ["Mohammed Header"]
10
+ gem.email = ["mohheader@hotmail.com"]
11
+ gem.description = %q{This gem adds a custom matcher to RSpec-rails to recursively compare nested Ruby data-structures consisting of `Hash` and `Array` elements. An order of elements in an array is ignored. Based on the other GEM : rspec-deep-ignore-order-matcher }
12
+ gem.summary = %q{A custom matcher to RSpec to recursively compare nested Ruby data-structures consisting of `Hash` and `Array` elements.}
13
+ gem.homepage = 'https://github.com/mohheader/rspec-rails-deep-ignore-order-matcher'
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency 'rspec-rails', '~> 3.2'
21
+ end
@@ -0,0 +1,39 @@
1
+ require 'rspec-rails'
2
+ require 'rspec-rails-deep-ignore-order-matcher'
3
+
4
+ describe Deep::Ignore::Order::Matcher do
5
+
6
+ it 'should matches usual values' do
7
+ ['an_string', 1, 13.5, nil, [1, 2, 3], { a: 1, b: 2 }].each_slice(2) do |value1, value2|
8
+ value1.should be_deep_equal value1
9
+ value2.should be_deep_equal value2
10
+ value1.should_not be_deep_equal value2
11
+ value2.should_not be_deep_equal value1
12
+ end
13
+ end
14
+
15
+ it 'should ignore order in plain arrays' do
16
+ actual = Array.new(5) { Random.rand(1000) }
17
+ expected = actual.sort
18
+ actual.should be_deep_equal expected
19
+ end
20
+
21
+ it 'should match deep structs' do
22
+ actual = [{ a: 1, b: 'str', c: [1, 2, 3] }, [{ a: [2, { a: 4 }] }, { b: 2 }, { c: 3 }]]
23
+ expected = [{ a: 1, b: 'str', c: [3, 1, 2] }, [{ b: 2 }, { a: [{ a: 4 }, 2] }, { c: 3 }]]
24
+ actual.should be_deep_equal expected
25
+ actual[0][:c].push(4)
26
+ actual.should_not be_deep_equal expected
27
+ end
28
+
29
+ it 'should do not match partials' do
30
+ [1, 2, 3].should_not be_deep_equal [1, 2]
31
+ [1, 2].should_not be_deep_equal [1, 2, 3]
32
+ { a: 1, b: 2 }.should_not be_deep_equal({ a: 1 })
33
+ { a: 1 }.should_not be_deep_equal({ a: 1, b: 2 })
34
+ end
35
+
36
+ it 'should ignore hash keys order' do
37
+ { a: 1, b: 2 }.should be_deep_equal({ b: 2, a: 1 })
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-rails-deep-ignore-order-matcher
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Mohammed Header
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec-rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ description: 'This gem adds a custom matcher to RSpec-rails to recursively compare
28
+ nested Ruby data-structures consisting of `Hash` and `Array` elements. An order
29
+ of elements in an array is ignored. Based on the other GEM : rspec-deep-ignore-order-matcher '
30
+ email:
31
+ - mohheader@hotmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - .gitignore
37
+ - Gemfile
38
+ - LICENSE.txt
39
+ - README.md
40
+ - Rakefile
41
+ - lib/rspec-rails-deep-ignore-order-matcher.rb
42
+ - lib/rspec-rails-deep-ignore-order-matcher/version.rb
43
+ - rspec-rails-deep-ignore-order-matcher.gemspec
44
+ - spec/matcher_spec.rb
45
+ homepage: https://github.com/mohheader/rspec-rails-deep-ignore-order-matcher
46
+ licenses: []
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 2.4.3
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: A custom matcher to RSpec to recursively compare nested Ruby data-structures
68
+ consisting of `Hash` and `Array` elements.
69
+ test_files:
70
+ - spec/matcher_spec.rb