rspec-deep-ignore-order-matcher 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # RSpec Deep Matcher
2
2
 
3
- This gem adds a custom matcher to RSpec to recursively compare nested Ruby data-structures consisting of `Hash` and `Array` elements.
3
+ This gem adds a custom matcher to RSpec to recursively compare nested Ruby data-structures consisting of Hash and Array elements.
4
4
  An order of elements in an array is ignored.
5
5
 
6
6
  ## Install
@@ -11,9 +11,15 @@ or add to your `Gemfile`
11
11
  ```
12
12
  gem 'rspec-deep-ignore-order-matcher'
13
13
  ```
14
+ and run
15
+ ```
16
+ bundle install
17
+ ```
14
18
 
15
19
  ## Example
16
20
  ```
21
+ require 'rspec-deep-ignore-order-matcher'
22
+
17
23
  describe 'Products' do
18
24
  it "should ignore order of product's tags" do
19
25
  expected = [{ :product => { :title => 'Product 1', :tags => ['large', 'blue', 'heavy'] } }]
@@ -21,4 +27,4 @@ describe 'Products' do
21
27
  actual.should be_deep_equal expected
22
28
  end
23
29
  end
24
- ```
30
+ ```
@@ -2,7 +2,7 @@ require 'rspec'
2
2
  require 'rspec-deep-ignore-order-matcher/version'
3
3
 
4
4
  RSpec::Matchers.define :be_deep_equal do |expected|
5
- match { |actual| m1 actual, expected }
5
+ match { |actual| m? actual, expected }
6
6
 
7
7
  failure_message_for_should do |actual|
8
8
  "expected that #{actual} would be deep equal with #{expected}"
@@ -16,7 +16,7 @@ RSpec::Matchers.define :be_deep_equal do |expected|
16
16
  "be deep equal with #{expected}"
17
17
  end
18
18
 
19
- def m1(actual, expected)
19
+ def m?(actual, expected)
20
20
  return arrays_matches?(actual, expected) if expected.is_a?(Array) && actual.is_a?(Array)
21
21
  return hashes_matches?(actual, expected) if expected.is_a?(Hash) && actual.is_a?(Hash)
22
22
  expected == actual
@@ -25,7 +25,7 @@ RSpec::Matchers.define :be_deep_equal do |expected|
25
25
  def arrays_matches?(actual, expected)
26
26
  exp = expected.clone
27
27
  actual.each do |a|
28
- index = exp.find_index { |e| m1 a, e }
28
+ index = exp.find_index { |e| m? a, e }
29
29
  return false if index.nil?
30
30
  exp.delete_at(index)
31
31
  end
@@ -33,8 +33,8 @@ RSpec::Matchers.define :be_deep_equal do |expected|
33
33
  end
34
34
 
35
35
  def hashes_matches?(actual, expected)
36
- return false unless actual.keys == expected.keys
37
- actual.each { |key, value| return false unless m1 value, expected[key] }
36
+ return false unless actual.keys.sort == expected.keys.sort
37
+ actual.each { |key, value| return false unless m? value, expected[key] }
38
38
  true
39
39
  end
40
40
  end
@@ -2,7 +2,7 @@ module Deep
2
2
  module Ignore
3
3
  module Order
4
4
  module Matcher
5
- VERSION = "0.0.1"
5
+ VERSION = '0.0.2'
6
6
  end
7
7
  end
8
8
  end
data/spec/matcher_spec.rb CHANGED
@@ -33,4 +33,7 @@ describe Deep::Ignore::Order::Matcher do
33
33
  { :a => 1 }.should_not be_deep_equal({ :a => 1, :b => 2 })
34
34
  end
35
35
 
36
+ it 'should ignore hash keys order' do
37
+ { :a => 1, :b => 2 }.should be_deep_equal({ :b => 2, :a => 1 })
38
+ end
36
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
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.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: