hash_dealer 1.3.4 → 1.3.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.
- data/VERSION +1 -1
- data/hash_dealer.gemspec +2 -2
- data/lib/matcher.rb +4 -4
- data/lib/path_string.rb +35 -2
- data/spec/lib/matcher_spec.rb +6 -0
- data/spec/lib/path_string_spec.rb +1 -0
- metadata +3 -3
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.3.
|
|
1
|
+
1.3.5
|
data/hash_dealer.gemspec
CHANGED
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = %q{hash_dealer}
|
|
8
|
-
s.version = "1.3.
|
|
8
|
+
s.version = "1.3.5"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Dan Langevin"]
|
|
12
|
-
s.date = %q{2011-09-
|
|
12
|
+
s.date = %q{2011-09-13}
|
|
13
13
|
s.description = %q{Like Factory Girl but for Hashes only}
|
|
14
14
|
s.email = %q{dan.langevin@lifebooker.com}
|
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/matcher.rb
CHANGED
|
@@ -9,11 +9,11 @@ RSpec::Matchers.define(:match_response) do |actual|
|
|
|
9
9
|
end
|
|
10
10
|
|
|
11
11
|
failure_message_for_should do |container|
|
|
12
|
-
"expected #{PathString.as_sorted_json(actual).pretty_inspect}\n to equal\n #{PathString.as_sorted_json(container).pretty_inspect}"
|
|
12
|
+
"expected #{PathString.as_sorted_json(actual).pretty_inspect}\n to equal\n #{PathString.as_sorted_json(container).pretty_inspect} \n\n Diff: \n #{PathString.diff(container, actual)}"
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
failure_message_for_should_not do |container|
|
|
16
|
-
"expected #{PathString.as_sorted_json(actual).pretty_inspect}\n not to equal\n #{PathString.as_sorted_json(container).pretty_inspect}"
|
|
16
|
+
"expected #{PathString.as_sorted_json(actual).pretty_inspect}\n not to equal\n #{PathString.as_sorted_json(container).pretty_inspect} \n\n Diff: \n #{PathString.diff(container, actual)}"
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
|
|
@@ -36,11 +36,11 @@ RSpec::Matchers.define(:match_list) do |actual|
|
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
failure_message_for_should do |container|
|
|
39
|
-
"expected #{PathString.as_sorted_json(normalize(actual))}\n to equal\n #{PathString.as_sorted_json(normalize(container))}"
|
|
39
|
+
"expected #{PathString.as_sorted_json(normalize(actual))}\n to equal\n #{PathString.as_sorted_json(normalize(container))} \n\n Diff: \n #{PathString.diff(container, actual)}"
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
failure_message_for_should_not do |container|
|
|
43
|
-
"expected #{PathString.as_sorted_json(normalize(actual))}\n not to equal\n #{PathString.as_sorted_json(normalize(container))}"
|
|
43
|
+
"expected #{PathString.as_sorted_json(normalize(actual))}\n not to equal\n #{PathString.as_sorted_json(normalize(container))} \n\n Diff: \n #{PathString.diff(container, actual)}"
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
end
|
data/lib/path_string.rb
CHANGED
|
@@ -61,16 +61,49 @@ class PathString < String
|
|
|
61
61
|
return params
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
+
def self.diff(a,b)
|
|
65
|
+
a, b = self.as_sorted_json(a), self.as_sorted_json(b)
|
|
66
|
+
diff = []
|
|
67
|
+
a.each_index do |i|
|
|
68
|
+
unless a[i] == b[i]
|
|
69
|
+
diff << {:expected => a[i], :got => b[i]}
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
diff
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
|
|
64
76
|
private
|
|
65
77
|
|
|
66
78
|
def self.stringify_keys(hash)
|
|
67
|
-
new_hash =
|
|
79
|
+
new_hash = hash.class.new
|
|
68
80
|
hash.each_pair do |k,v|
|
|
69
|
-
new_hash[k.to_s] =
|
|
81
|
+
new_hash[k.to_s] = case v
|
|
82
|
+
when Hash
|
|
83
|
+
self.stringify_keys(v)
|
|
84
|
+
when Array
|
|
85
|
+
self.stringify_array_keys(v)
|
|
86
|
+
else
|
|
87
|
+
v
|
|
88
|
+
end
|
|
70
89
|
end
|
|
71
90
|
new_hash
|
|
72
91
|
end
|
|
73
92
|
|
|
93
|
+
#
|
|
94
|
+
def self.stringify_array_keys(array)
|
|
95
|
+
array.collect{|v|
|
|
96
|
+
case v
|
|
97
|
+
when Hash
|
|
98
|
+
self.stringify_keys(v)
|
|
99
|
+
when Array
|
|
100
|
+
self.stringify_array_keys(v)
|
|
101
|
+
else
|
|
102
|
+
v
|
|
103
|
+
end
|
|
104
|
+
}
|
|
105
|
+
end
|
|
106
|
+
|
|
74
107
|
def self.get_zipped_array(known_path, entered_path)
|
|
75
108
|
# make these strings
|
|
76
109
|
known_path, entered_path = known_path.to_s, entered_path.to_s
|
data/spec/lib/matcher_spec.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
require 'json'
|
|
1
2
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
2
3
|
|
|
3
4
|
describe "match_response Matcher" do
|
|
@@ -23,4 +24,9 @@ describe "match_response Matcher" do
|
|
|
23
24
|
{"a" => [{"a" => "b"}]}.matcher.should match_response({"a" => [{"a" => "c"},{"a" => "x"},{"a" => "y"}]})
|
|
24
25
|
end
|
|
25
26
|
|
|
27
|
+
it "should stringify keys so it matches symbols to strings" do
|
|
28
|
+
{:a => "a"}.matcher.should match_response({"a" => "abcde"})
|
|
29
|
+
{:a => {:b => "c"}}.should match_response({"a" => {"b" => "c"}})
|
|
30
|
+
end
|
|
31
|
+
|
|
26
32
|
end
|
metadata
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: hash_dealer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease:
|
|
5
|
-
version: 1.3.
|
|
5
|
+
version: 1.3.5
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
8
8
|
- Dan Langevin
|
|
@@ -10,7 +10,7 @@ autorequire:
|
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
12
|
|
|
13
|
-
date: 2011-09-
|
|
13
|
+
date: 2011-09-13 00:00:00 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: activesupport
|
|
@@ -141,7 +141,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
141
141
|
requirements:
|
|
142
142
|
- - ">="
|
|
143
143
|
- !ruby/object:Gem::Version
|
|
144
|
-
hash:
|
|
144
|
+
hash: 882149138124409394
|
|
145
145
|
segments:
|
|
146
146
|
- 0
|
|
147
147
|
version: "0"
|