pork 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +10 -0
- data/README.md +1 -0
- data/lib/pork/inspect.rb +28 -5
- data/lib/pork/version.rb +1 -1
- data/pork.gemspec +4 -4
- data/test/test_inspect.rb +49 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 814a6e5d8622a7c77c53f88b539b81d77f39872f
|
4
|
+
data.tar.gz: 4269395ba1774b0051195edd772d1c850298da6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46b0342699c72744ff5cc2fc230c13b328df33ad1593ee872a83ac4283827f27e3b42cc926be1f4a93d586df15e8f813e1cac828fb86e1119e1739abad83f3ac
|
7
|
+
data.tar.gz: 597fb9cbf4754d9866e55d9a7ed4c334d63c067791cfad332169341d1edcce6a7947b77dcd8173dd88732995733bbf7fabee790d11992c62a78e0c9130ac337a
|
data/CHANGES.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
# CHANGES
|
2
2
|
|
3
|
+
## Pork 1.0.2 -- 2014-12-09
|
4
|
+
|
5
|
+
* Hash difference is much improved. Now it uses `/` to separate keys,
|
6
|
+
and use quotes for string keys and colons for symbol keys, so that
|
7
|
+
we won't be confused when comparing string hashes and symbol hashes.
|
8
|
+
Further more, it would show `<undefined>` for hashes missing a key,
|
9
|
+
and `<out-of-bound>` for arrays out of bound. Previously, hash with
|
10
|
+
nil values are indistinguishable with hash missing keys.
|
11
|
+
Thanks Chun-Yi Liu (@trantorliu).
|
12
|
+
|
3
13
|
## Pork 1.0.1 -- 2014-11-21
|
4
14
|
|
5
15
|
* Fixed the failure message for hash diff.
|
data/README.md
CHANGED
data/lib/pork/inspect.rb
CHANGED
@@ -6,6 +6,19 @@ module Pork
|
|
6
6
|
end
|
7
7
|
|
8
8
|
class Inspect < Struct.new(:flip)
|
9
|
+
Undefined = Object.new
|
10
|
+
Undefined.singleton_class.module_eval do
|
11
|
+
def inspect
|
12
|
+
'<undefined>'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
OutOfBound = Object.new
|
16
|
+
OutOfBound.singleton_class.module_eval do
|
17
|
+
def inspect
|
18
|
+
'<out-of-bound>'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
9
22
|
def self.with *args
|
10
23
|
lambda{ public_send("with_#{Pork.inspect_failure_mode}", *args) }
|
11
24
|
end
|
@@ -38,7 +51,7 @@ module Pork
|
|
38
51
|
def self.for_diff_hash msg, negate, result
|
39
52
|
"\n" + result.map do |key, (expect, actual)|
|
40
53
|
body = with_auto(expect, msg, [actual], negate)
|
41
|
-
"\tHash with key path: #{key
|
54
|
+
"\tHash with key path: #{key}\n#{body.sub(/\A\n/, '')}"
|
42
55
|
end.join("\n\n")
|
43
56
|
end
|
44
57
|
|
@@ -68,13 +81,23 @@ module Pork
|
|
68
81
|
|
69
82
|
def diff_hash expect, actual, result={}, prefix=''
|
70
83
|
expect.inject(result) do |r, (key, e)|
|
71
|
-
|
84
|
+
a = if actual.key?(key)
|
85
|
+
actual[key]
|
86
|
+
else
|
87
|
+
Undefined
|
88
|
+
end
|
89
|
+
diff_object(e, a, r, "#{prefix}#{key.inspect}")
|
72
90
|
end
|
73
91
|
end
|
74
92
|
|
75
93
|
def diff_array expect, actual, result={}, prefix=''
|
76
94
|
expect.each.with_index.inject(result) do |r, (e, idx)|
|
77
|
-
|
95
|
+
a = if idx < actual.size
|
96
|
+
actual[idx]
|
97
|
+
else
|
98
|
+
OutOfBound
|
99
|
+
end
|
100
|
+
diff_object(e, a, r, "#{prefix}#{idx}")
|
78
101
|
end
|
79
102
|
end
|
80
103
|
|
@@ -82,9 +105,9 @@ module Pork
|
|
82
105
|
return result if expect == actual
|
83
106
|
|
84
107
|
if expect.kind_of?(Hash) && actual.kind_of?(Hash)
|
85
|
-
diff_hash(expect, actual, result, "#{prefix}
|
108
|
+
diff_hash(expect, actual, result, "#{prefix}/")
|
86
109
|
elsif expect.kind_of?(Array) && actual.kind_of?(Array)
|
87
|
-
diff_array(expect, actual, result, "#{prefix}
|
110
|
+
diff_array(expect, actual, result, "#{prefix}/")
|
88
111
|
elsif flip
|
89
112
|
result[prefix] = [actual, expect]
|
90
113
|
else
|
data/lib/pork/version.rb
CHANGED
data/pork.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
# stub: pork 1.0.
|
2
|
+
# stub: pork 1.0.2 ruby lib
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = "pork"
|
6
|
-
s.version = "1.0.
|
6
|
+
s.version = "1.0.2"
|
7
7
|
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
9
|
s.require_paths = ["lib"]
|
10
10
|
s.authors = ["Lin Jen-Shin (godfat)"]
|
11
|
-
s.date = "2014-
|
11
|
+
s.date = "2014-12-09"
|
12
12
|
s.description = "Pork -- Simple and clean and modular testing library.\n\nInspired by [Bacon][].\n\n[Bacon]: https://github.com/chneukirchen/bacon"
|
13
13
|
s.email = ["godfat (XD) godfat.org"]
|
14
14
|
s.files = [
|
@@ -50,7 +50,7 @@ Gem::Specification.new do |s|
|
|
50
50
|
"test/test_shuffle.rb"]
|
51
51
|
s.homepage = "https://github.com/godfat/pork"
|
52
52
|
s.licenses = ["Apache License 2.0"]
|
53
|
-
s.rubygems_version = "2.4.
|
53
|
+
s.rubygems_version = "2.4.5"
|
54
54
|
s.summary = "Pork -- Simple and clean and modular testing library."
|
55
55
|
s.test_files = [
|
56
56
|
"test/test_bacon.rb",
|
data/test/test_inspect.rb
CHANGED
@@ -21,6 +21,51 @@ describe Pork::Inspect do
|
|
21
21
|
should.eq "String#==(\n#{n}a#{n+1}\n> b\n) to return false"
|
22
22
|
end
|
23
23
|
|
24
|
+
would '#diff_hash with nil and <undefined>' do
|
25
|
+
z = 'z'*80
|
26
|
+
a, b = {:z => z, :a => nil}, {:z => z}
|
27
|
+
Pork::Inspect.with_auto(a, :==, [b], false).should.start_with? <<-MSG.chop
|
28
|
+
|
29
|
+
\tHash with key path: :a
|
30
|
+
nil.==(<undefined>) to return true
|
31
|
+
MSG
|
32
|
+
|
33
|
+
Pork::Inspect.with_auto(b, :==, [a], false).should.start_with? <<-MSG.chop
|
34
|
+
|
35
|
+
\tHash with key path: :a
|
36
|
+
<undefined>.==(nil) to return true
|
37
|
+
MSG
|
38
|
+
end
|
39
|
+
|
40
|
+
would '#diff_hash with nil and <out-of-bound>' do
|
41
|
+
z = 'z'*80
|
42
|
+
a, b = {:a => {:b => [z, nil]}}, {:a => {:b => [z]}}
|
43
|
+
Pork::Inspect.with_auto(a, :==, [b], false).should.start_with? <<-MSG.chop
|
44
|
+
|
45
|
+
\tHash with key path: :a/:b/1
|
46
|
+
nil.==(<out-of-bound>) to return true
|
47
|
+
MSG
|
48
|
+
|
49
|
+
Pork::Inspect.with_auto(b, :==, [a], false).should.start_with? <<-MSG.chop
|
50
|
+
|
51
|
+
\tHash with key path: :a/:b/1
|
52
|
+
<out-of-bound>.==(nil) to return true
|
53
|
+
MSG
|
54
|
+
end
|
55
|
+
|
56
|
+
would '#diff_hash with string keys and symbol keys' do
|
57
|
+
z = 'z'*80
|
58
|
+
a, b = {:a => z}, {'a' => z}
|
59
|
+
Pork::Inspect.with_auto(a, :==, [b], false).should.start_with? <<-MSG.chop
|
60
|
+
|
61
|
+
\tHash with key path: :a
|
62
|
+
#{z.inspect}.==(\n<undefined>) to return true
|
63
|
+
|
64
|
+
\tHash with key path: "a"
|
65
|
+
<undefined>.==(#{z.inspect}) to return true
|
66
|
+
MSG
|
67
|
+
end
|
68
|
+
|
24
69
|
would '#diff_hash' do
|
25
70
|
a = {"category_chats"=>[{"category_name"=>"Cat", "experts_url"=>"cat-experts", "chat_list"=>[{"mentee"=>{"timezone_str"=>"+00:00", "timezone_offset"=>0, "timezone_display"=>"UTC (+00:00)", "username"=>"example", "name"=>"Example", "level"=>"mentor", "rating"=>0.0, "role"=>"user", "avatar_url"=>"https://www.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?d=mm", "small_avatar_url"=>"https://www.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?d=mm?s=64&d=mm"}, "mentor"=>{"timezone_str"=>"+00:00", "timezone_offset"=>0, "timezone_display"=>"UTC (+00:00)", "username"=>"menmen", "name"=>"Menmen", "level"=>"mentor", "rating"=>0.0, "role"=>"mentor", "avatar_url"=>"https://www.gravatar.com/avatar/556611444ab1143c8ad30206fda3926f?d=mm", "small_avatar_url"=>"https://www.gravatar.com/avatar/556611444ab1143c8ad30206fda3926f?d=mm?s=64&d=mm"}, "chatroom_id"=>"8c3dd9387dd30499a4053e07e4a41be4", "chatroom_firebase_id"=>"49c31f7444e199bdaea610dbe518d329"}]}], "longterm"=>[{"rate"=>"3.00", "credit"=>"7.00", "valid_from"=>1416148781, "valid_to"=>1416235181, "mentee"=>{"timezone_str"=>"+00:00", "timezone_offset"=>0, "timezone_display"=>"UTC (+00:00)", "username"=>"example", "name"=>"Example", "level"=>"mentor", "rating"=>0.0, "role"=>"user", "avatar_url"=>"https://www.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?d=mm", "small_avatar_url"=>"https://www.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?d=mm?s=64&d=mm"}, "mentor"=>{"timezone_str"=>"+00:00", "timezone_offset"=>0, "timezone_display"=>"UTC (+00:00)", "username"=>"menmen", "name"=>"Menmen", "level"=>"mentor", "rating"=>0.0, "role"=>"mentor", "avatar_url"=>"https://www.gravatar.com/avatar/556611444ab1143c8ad30206fda3926f?d=mm", "small_avatar_url"=>"https://www.gravatar.com/avatar/556611444ab1143c8ad30206fda3926f?d=mm?s=64&d=mm"}, "chatroom_id"=>"8c3dd9387dd30499a4053e07e4a41be4", "chatroom_firebase_id"=>"49c31f7444e199bdaea610dbe518d329"}], "my"=>[], "recent_chats"=>[{"request"=>{}, "type"=>"message", "id"=>"e71bca4b-a617-4edc-9816-7fc3034c64ea", "content"=>"hi", "created_at"=>"2014-11-16T14:39:41Z", "read_at"=>nil, "sender"=>{"timezone_str"=>"+00:00", "timezone_offset"=>0, "timezone_display"=>"UTC (+00:00)", "username"=>"example", "name"=>"Example", "level"=>"mentor", "rating"=>0.0, "role"=>"user", "avatar_url"=>"https://www.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?d=mm", "small_avatar_url"=>"https://www.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?d=mm?s=64&d=mm"}, "receiver"=>{"timezone_str"=>"+00:00", "timezone_offset"=>0, "timezone_display"=>"UTC (+00:00)", "username"=>"menmen", "name"=>"Menmen", "level"=>"mentor", "rating"=>0.0, "role"=>"mentor", "avatar_url"=>"https://www.gravatar.com/avatar/556611444ab1143c8ad30206fda3926f?d=mm", "small_avatar_url"=>"https://www.gravatar.com/avatar/556611444ab1143c8ad30206fda3926f?d=mm?s=64&d=mm"}, "chatroom_id"=>"8c3dd9387dd30499a4053e07e4a41be4", "chatroom_firebase_id"=>"49c31f7444e199bdaea610dbe518d329"}]}
|
26
71
|
|
@@ -29,12 +74,12 @@ describe Pork::Inspect do
|
|
29
74
|
f = expect.raise(Pork::Failure){ expect(a, 'Additional Message').eq(b) }
|
30
75
|
expect(f.message).eq <<-MSG.sub(/\AExpect/, 'Expect ').chop
|
31
76
|
Expect
|
32
|
-
\tHash with key path: "category_chats
|
77
|
+
\tHash with key path: "category_chats"/0/"chat_list"/0/"mentor"
|
33
78
|
{"timezone_str"=>"+00:00", "timezone_offset"=>0, "timezone_display"=>"UTC (+00:00)", "username"=>"menmen", "name"=>"Menmen", "level"=>"mentor", "rating"=>0.0, "role"=>"mentor", "avatar_url"=>"https://www.gravatar.com/avatar/556611444ab1143c8ad30206fda3926f?d=mm", "small_avatar_url"=>"https://www.gravatar.com/avatar/556611444ab1143c8ad30206fda3926f?d=mm?s=64&d=mm"}.==(
|
34
|
-
|
79
|
+
<undefined>) to return true
|
35
80
|
|
36
|
-
\tHash with key path: "my
|
37
|
-
|
81
|
+
\tHash with key path: "my"/0
|
82
|
+
<out-of-bound>.==({"mentee"=>{"timezone_str"=>"+00:00", "timezone_offset"=>0, "timezone_display"=>"UTC (+00:00)", "username"=>"example", "name"=>"Example", "level"=>"mentor", "rating"=>0.0, "role"=>"user", "avatar_url"=>"https://www.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?d=mm", "small_avatar_url"=>"https://www.gravatar.com/avatar/55502f40dc8b7c769880b10874abc9d0?d=mm?s=64&d=mm"}, "chatroom_id"=>"8c3dd9387dd30499a4053e07e4a41be4", "chatroom_firebase_id"=>"49c31f7444e199bdaea610dbe518d329"}) to return true
|
38
83
|
Additional Message
|
39
84
|
MSG
|
40
85
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pork
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lin Jen-Shin (godfat)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: muack
|
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
92
|
version: '0'
|
93
93
|
requirements: []
|
94
94
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.4.
|
95
|
+
rubygems_version: 2.4.5
|
96
96
|
signing_key:
|
97
97
|
specification_version: 4
|
98
98
|
summary: Pork -- Simple and clean and modular testing library.
|