dynport_tools 0.2.5 → 0.2.6

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.5
1
+ 0.2.6
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dynport_tools}
8
- s.version = "0.2.5"
8
+ s.version = "0.2.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tobias Schwab"]
@@ -1,6 +1,6 @@
1
1
  module DynportTools
2
2
  class Differ
3
- attr_accessor :diff_all, :use_return
3
+ attr_accessor :diff_all, :use_return, :symbolize_keys
4
4
 
5
5
 
6
6
  def initialize(options = {})
@@ -45,7 +45,13 @@ module DynportTools
45
45
 
46
46
  def diff_hash_values(a, b, keys)
47
47
  ret = keys.uniq.inject({}) do |hash, key|
48
- if diff = diff(a[key], b[key])
48
+ value_a = a[key]
49
+ value_b = b[key]
50
+ if symbolize_keys
51
+ value_a ||= a[key.is_a?(Symbol) ? key.to_s : key.to_sym]
52
+ value_b ||= b[key.is_a?(Symbol) ? key.to_s : key.to_sym]
53
+ end
54
+ if diff = diff(value_a, value_b)
49
55
  hash[key] = diff
50
56
  end
51
57
  hash
@@ -9,8 +9,13 @@ module DynportTools::HaveAttributesMatcher
9
9
  end
10
10
 
11
11
  def matches?(target)
12
- @target = target
13
- if diff = differ.diff(@expected, target)
12
+ @target = if target.respond_to?(:attributes)
13
+ differ.symbolize_keys = true
14
+ target.attributes
15
+ else
16
+ target
17
+ end
18
+ if diff = differ.diff(@expected, @target)
14
19
  @error = differ.diff_to_message_lines(diff).join("\n")
15
20
  false
16
21
  else
@@ -21,6 +21,16 @@ describe DynportTools::Differ do
21
21
  differ.diff(hash, hash).should be_nil
22
22
  end
23
23
 
24
+ it "returns true when symbolize_keys is set to true and comparing hashes with symbols and strings" do
25
+ differ.symbolize_keys = true
26
+ differ.diff({ :a => 1 }, { "a" => 1 }).should be_nil
27
+ end
28
+
29
+ it "returns false when symbolize_keys is set to false and comparing hashes with symbols and strings" do
30
+ differ.symbolize_keys = nil
31
+ differ.diff({ :a => 1 }, { "a" => 1 }).should_not be_nil
32
+ end
33
+
24
34
  it "returns the diff when there is one" do
25
35
  a = { :a => 1, :b => 2 }
26
36
  b = { :a => 1, :b => 3 }
@@ -49,4 +49,18 @@ describe "DynportTools::HaveAttributesMatcher" do
49
49
  matcher = DynportTools::HaveAttributesMatcher::HaveAttributes.new(:a => 1, :b => 2)
50
50
  matcher.matches?(:a => 1).should be_false
51
51
  end
52
+
53
+ it "returns true when comparing ActiveRecord like objects with hashes" do
54
+ attributes = { "title" => "Some Title" }
55
+ ar = double("ar", :attributes => attributes)
56
+ matcher = DynportTools::HaveAttributesMatcher::HaveAttributes.new(:title => "Some Title")
57
+ matcher.matches?(ar).should be_true
58
+ end
59
+
60
+ it "returns false when comparing ActiveRecord like objects with hashes but not equal" do
61
+ attributes = { "title" => "Some Title" }
62
+ ar = double("ar", :attributes => attributes)
63
+ matcher = DynportTools::HaveAttributesMatcher::HaveAttributes.new(:title => "Some Other Title")
64
+ matcher.matches?(ar).should be_false
65
+ end
52
66
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynport_tools
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 5
10
- version: 0.2.5
9
+ - 6
10
+ version: 0.2.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tobias Schwab