rspec-deep-ignore-order-matcher 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d2244d3fcec9f57c9d45e2b022dde0b6bf558df9
4
- data.tar.gz: 333205ef8c16c71cc1ac20a3c83672208bd6b8c1
3
+ metadata.gz: a2257779b21b1a50868089800d5690efde4fa1d0
4
+ data.tar.gz: d15545218269e125ec5ccd419957e24b6f29b7b6
5
5
  SHA512:
6
- metadata.gz: efbe677499be87632d29c8e5714d54117b77d7f0d511aebd892e693cdd42a2d59227347dd219d2f2d5e5a33f60629fb6ff606040eab3496c9a49e7c1aead0408
7
- data.tar.gz: 80d031e32c1dcf7dde01921f413ea109912537c71e92c9b87b6b62ee0addd940239500779ee52b7f018aa7c51c2c34c6903ff164ca2290b927fee394e00579e8
6
+ metadata.gz: 56f4e23dca2f18ca95e9815aa0bf17c1c3ccdfb4deaa7e0b3bb2c7b22fe4ba2fc67fc763fc5f3e2461c96479da431ca03b4e4a6ab6c7e70a934daf385faeb1f9
7
+ data.tar.gz: abbd4f285c7264864be59ef170de4daf337209bd528fd5105a32d6c208d2153db83a5006ab859b1b18524033c17e0e57200a36fcc62f4dc53fafa9de6c0b9ac9
@@ -0,0 +1,6 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.0
3
+ Exclude:
4
+ - rspec-deep-ignore-order-matcher.gemspec
5
+ Metrics/LineLength:
6
+ Max: 120
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0
4
+ before_install:
5
+ - gem install bundler
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
1
  # RSpec Deep Matcher
2
2
 
3
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
+ [![Code Climate](https://codeclimate.com/github/amogil/rspec-deep-ignore-order-matcher/badges/gpa.svg)](https://codeclimate.com/github/amogil/rspec-deep-ignore-order-matcher)
5
+ [![Build Status](https://travis-ci.org/amogil/rspec-deep-ignore-order-matcher.svg?branch=master)](https://travis-ci.org/amogil/rspec-deep-ignore-order-matcher)
6
+ [![Dependency Status](https://gemnasium.com/badges/github.com/amogil/rspec-deep-ignore-order-matcher.svg)](https://gemnasium.com/github.com/amogil/rspec-deep-ignore-order-matcher)
4
7
 
5
8
  This gem adds a custom matcher to RSpec to recursively compare nested Ruby data-structures consisting of Hash and Array elements.
6
9
  An order of elements in an array is ignored.
@@ -26,7 +29,7 @@ describe 'Products' do
26
29
  it "should ignore order of product's tags" do
27
30
  expected = [{ :product => { :title => 'Product 1', :tags => ['large', 'blue', 'heavy'] } }]
28
31
  actual = [{ :product => { :title => 'Product 1', :tags => ['blue', 'large', 'heavy'] } }]
29
- actual.should be_deep_equal expected
32
+ expect(actual).to be_deep_equal expected
30
33
  end
31
34
  end
32
35
  ```
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task default: :spec
@@ -1,9 +1,9 @@
1
1
  module Deep
2
- module Ignore
3
- module Order
4
- module Matcher
5
- VERSION = '0.0.4'
6
- end
7
- end
8
- end
2
+ module Ignore
3
+ module Order
4
+ module Matcher
5
+ VERSION = '0.0.5'.freeze
6
+ end
7
+ end
8
+ end
9
9
  end
@@ -0,0 +1,40 @@
1
+ require 'rspec'
2
+ require 'rspec-deep-ignore-order-matcher/version'
3
+
4
+ RSpec::Matchers.define :be_deep_equal do |expected|
5
+ match { |actual| match? 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 match?(actual, expected)
20
+ return arrays_match?(actual, expected) if expected.is_a?(Array) && actual.is_a?(Array)
21
+ return hashes_match?(actual, expected) if expected.is_a?(Hash) && actual.is_a?(Hash)
22
+ expected == actual
23
+ end
24
+
25
+ def arrays_match?(actual, expected)
26
+ exp = expected.clone
27
+ actual.each do |a|
28
+ index = exp.find_index { |e| match? a, e }
29
+ return false if index.nil?
30
+ exp.delete_at(index)
31
+ end
32
+ exp.empty?
33
+ end
34
+
35
+ def hashes_match?(actual, expected)
36
+ return false unless actual.keys.sort == expected.keys.sort
37
+ actual.each { |key, value| return false unless match? value, expected[key] }
38
+ true
39
+ end
40
+ end
@@ -4,18 +4,23 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'rspec-deep-ignore-order-matcher/version'
5
5
 
6
6
  Gem::Specification.new do |gem|
7
- gem.name = "rspec-deep-ignore-order-matcher"
8
- gem.version = Deep::Ignore::Order::Matcher::VERSION
9
- gem.authors = ["Alexey Mogilnikov"]
10
- gem.email = ["alexey@mogilnikov.name"]
11
- gem.description = %q{This gem adds a custom matcher to RSpec to recursively compare nested Ruby data-structures consisting of `Hash` and `Array` elements. An order of elements in an array is ignored.}
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/amogil/rspec-deep-ignore-order-matcher'
7
+ gem.name = 'rspec-deep-ignore-order-matcher'
8
+ gem.version = Deep::Ignore::Order::Matcher::VERSION
9
+ gem.authors = ['Alexey Mogilnikov']
10
+ gem.email = ['alexey@mogilnikov.name']
11
+ gem.description = 'This gem adds a custom matcher to RSpec to recursively compare nested Ruby data-structures consisting of `Hash` and `Array` elements. An order of elements in an array is ignored.'
12
+ gem.summary = 'A custom matcher to RSpec to recursively compare nested Ruby data-structures consisting of `Hash` and `Array` elements.'
13
+ gem.homepage = 'https://github.com/amogil/rspec-deep-ignore-order-matcher'
14
+ gem.license = 'MIT'
14
15
 
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"]
16
+ gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ['lib']
20
+ gem.required_ruby_version = '>= 2.0'
19
21
 
20
- gem.add_dependency 'rspec', '~> 2.6'
22
+ gem.add_dependency 'rspec', '~> 3.0'
23
+ gem.add_development_dependency 'bundler', '~> 1.6'
24
+ gem.add_development_dependency 'rake', '~> 0'
25
+ gem.add_development_dependency 'rubocop', '~> 0'
21
26
  end
@@ -1,39 +1,38 @@
1
1
  require 'rspec'
2
- require 'rspec-deep-ignore-order-matcher'
2
+ require 'rspec_deep_ignore_order_matcher'
3
3
 
4
4
  describe Deep::Ignore::Order::Matcher do
5
+ it 'should matches usual values' do
6
+ ['an_string', 1, 13.5, nil, [1, 2, 3], { a: 1, b: 2 }].each_slice(2) do |value1, value2|
7
+ expect(value1).to be_deep_equal value1
8
+ expect(value2).to be_deep_equal value2
9
+ expect(value1).to_not be_deep_equal value2
10
+ expect(value2).to_not be_deep_equal value1
11
+ end
12
+ end
5
13
 
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
+ it 'should ignore order in plain arrays' do
15
+ actual = Array.new(5) { Random.rand(1000) }
16
+ expected = actual.sort
17
+ expect(actual).to be_deep_equal expected
18
+ end
14
19
 
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
+ it 'should match deep structs' do
21
+ actual = [{ a: 1, b: 'str', c: [1, 2, 3] }, [{ a: [2, { a: 4 }] }, { b: 2 }, { c: 3 }]]
22
+ expected = [{ a: 1, b: 'str', c: [3, 1, 2] }, [{ b: 2 }, { a: [{ a: 4 }, 2] }, { c: 3 }]]
23
+ expect(actual).to be_deep_equal expected
24
+ actual[0][:c].push(4)
25
+ expect(actual).to_not be_deep_equal expected
26
+ end
20
27
 
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
+ it 'should do not match partials' do
29
+ expect([1, 2, 3]).to_not be_deep_equal [1, 2]
30
+ expect([1, 2]).to_not be_deep_equal [1, 2, 3]
31
+ expect(a: 1, b: 2).to_not be_deep_equal(a: 1)
32
+ expect(a: 1).to_not be_deep_equal(a: 1, b: 2)
33
+ end
28
34
 
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
35
+ it 'should ignore hash keys order' do
36
+ expect(a: 1, b: 2).to be_deep_equal(b: 2, a: 1)
37
+ end
38
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-deep-ignore-order-matcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexey Mogilnikov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-07 00:00:00.000000000 Z
11
+ date: 2016-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -16,14 +16,56 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.6'
19
+ version: '3.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.6'
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.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
27
69
  description: This gem adds a custom matcher to RSpec to recursively compare nested
28
70
  Ruby data-structures consisting of `Hash` and `Array` elements. An order of elements
29
71
  in an array is ignored.
@@ -34,17 +76,19 @@ extensions: []
34
76
  extra_rdoc_files: []
35
77
  files:
36
78
  - ".gitignore"
79
+ - ".rubocop.yml"
80
+ - ".travis.yml"
37
81
  - Gemfile
38
82
  - LICENSE.txt
39
83
  - README.md
40
84
  - Rakefile
41
- - lib/rspec-deep-ignore-order-matcher.rb
42
85
  - lib/rspec-deep-ignore-order-matcher/version.rb
86
+ - lib/rspec_deep_ignore_order_matcher.rb
43
87
  - rspec-deep-ignore-order-matcher.gemspec
44
88
  - spec/matcher_spec.rb
45
- - vexor.yml
46
89
  homepage: https://github.com/amogil/rspec-deep-ignore-order-matcher
47
- licenses: []
90
+ licenses:
91
+ - MIT
48
92
  metadata: {}
49
93
  post_install_message:
50
94
  rdoc_options: []
@@ -54,7 +98,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
98
  requirements:
55
99
  - - ">="
56
100
  - !ruby/object:Gem::Version
57
- version: '0'
101
+ version: '2.0'
58
102
  required_rubygems_version: !ruby/object:Gem::Requirement
59
103
  requirements:
60
104
  - - ">="
@@ -1,40 +0,0 @@
1
- require 'rspec'
2
- require 'rspec-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_for_should do |actual|
8
- "expected that #{actual} would be deep equal with #{expected}"
9
- end
10
-
11
- failure_message_for_should_not 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
data/vexor.yml DELETED
@@ -1,2 +0,0 @@
1
- language: ruby
2
- script: bundle exec rspec