rspec-deep-ignore-order-matcher 0.0.4 → 0.0.5
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 +4 -4
- data/.rubocop.yml +6 -0
- data/.travis.yml +5 -0
- data/README.md +4 -1
- data/Rakefile +6 -1
- data/lib/rspec-deep-ignore-order-matcher/version.rb +7 -7
- data/lib/rspec_deep_ignore_order_matcher.rb +40 -0
- data/rspec-deep-ignore-order-matcher.gemspec +17 -12
- data/spec/matcher_spec.rb +31 -32
- metadata +52 -8
- data/lib/rspec-deep-ignore-order-matcher.rb +0 -40
- data/vexor.yml +0 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: a2257779b21b1a50868089800d5690efde4fa1d0
         | 
| 4 | 
            +
              data.tar.gz: d15545218269e125ec5ccd419957e24b6f29b7b6
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 56f4e23dca2f18ca95e9815aa0bf17c1c3ccdfb4deaa7e0b3bb2c7b22fe4ba2fc67fc763fc5f3e2461c96479da431ca03b4e4a6ab6c7e70a934daf385faeb1f9
         | 
| 7 | 
            +
              data.tar.gz: abbd4f285c7264864be59ef170de4daf337209bd528fd5105a32d6c208d2153db83a5006ab859b1b18524033c17e0e57200a36fcc62f4dc53fafa9de6c0b9ac9
         | 
    
        data/.rubocop.yml
    ADDED
    
    
    
        data/.travis.yml
    ADDED
    
    
    
        data/README.md
    CHANGED
    
    | @@ -1,6 +1,9 @@ | |
| 1 1 | 
             
            # RSpec Deep Matcher
         | 
| 2 2 |  | 
| 3 3 | 
             
            [](http://badge.fury.io/rb/rspec-deep-ignore-order-matcher)
         | 
| 4 | 
            +
            [](https://codeclimate.com/github/amogil/rspec-deep-ignore-order-matcher)
         | 
| 5 | 
            +
            [](https://travis-ci.org/amogil/rspec-deep-ignore-order-matcher)
         | 
| 6 | 
            +
            [](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. | 
| 32 | 
            +
            		expect(actual).to be_deep_equal expected
         | 
| 30 33 | 
             
            	end
         | 
| 31 34 | 
             
            end
         | 
| 32 35 | 
             
            ```
         | 
    
        data/Rakefile
    CHANGED
    
    
| @@ -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 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 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 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 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 | 
            -
             | 
| 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
         | 
    
        data/spec/matcher_spec.rb
    CHANGED
    
    | @@ -1,39 +1,38 @@ | |
| 1 1 | 
             
            require 'rspec'
         | 
| 2 | 
            -
            require ' | 
| 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 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
             | 
| 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 | 
            -
             | 
| 16 | 
            -
             | 
| 17 | 
            -
             | 
| 18 | 
            -
             | 
| 19 | 
            -
             | 
| 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 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 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 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
             | 
| 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 | 
            +
              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:  | 
| 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: ' | 
| 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: ' | 
| 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