minitest-pretty_diff 0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7d1bbf3974f1592349a5e83c2b4a49d8e0cf1250
4
+ data.tar.gz: bb170fe21e44ef24b09fd7fac6e7ecc0b8841142
5
+ SHA512:
6
+ metadata.gz: 65bf8651bd5bad7f74edc5b308a0f7728e0f5a11594b1ca4d74bf4d9e34087aeeb0b62fbfe0cf1e982b15b2f907cff0f2419f1d52582b464c45f0d862cf348c2
7
+ data.tar.gz: 698f6b89dbc6bfba9df2ce57678849ff64e22d60c8e85934efe78798a8a4d5da2d32f45ac119cded582130f83ec4769120e449b7cb05c981ab491c290487671d
@@ -0,0 +1,38 @@
1
+ require "json"
2
+
3
+ module MiniTest
4
+ module Assertions
5
+
6
+ #
7
+ # Returns a pretty-printed version of +obj+.
8
+ #
9
+ def mu_pp(obj)
10
+ s = if obj.is_a?(Hash) || obj.is_a?(Array)
11
+ JSON.pretty_generate(sort_keys(obj))
12
+ else
13
+ obj.inspect
14
+ end
15
+
16
+ s = s.encode(Encoding.default_external) if defined? Encoding
17
+ s
18
+ end
19
+
20
+ #
21
+ # Recursively sort the keys of +obj+, which is typically a hash. Recurses
22
+ # into arrays (to allow nested structures), but does not sort them.
23
+ #
24
+ def sort_keys(obj)
25
+ if obj.is_a?(Hash)
26
+ obj.keys.sort.reduce(Hash.new) do |memo, key|
27
+ memo.merge({ key => sort_keys(obj[key]) })
28
+ end
29
+ elsif obj.is_a?(Array)
30
+ obj.map do |item|
31
+ sort_keys(item)
32
+ end
33
+ else
34
+ obj
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,51 @@
1
+ require File.expand_path("../../lib/minitest/pretty_diff", __FILE__)
2
+
3
+ class Whatever
4
+ include MiniTest::Assertions
5
+ end
6
+
7
+ $array = %Q([
8
+ "Alpha",
9
+ "Beta"
10
+ ])
11
+
12
+ $hash = %Q({
13
+ "Alpha": 1,
14
+ "Beta": 2
15
+ })
16
+
17
+ $nested = %Q({
18
+ "Alpha": [
19
+ "Beta",
20
+ {
21
+ "Gamma": "Epsilon"
22
+ }
23
+ ]
24
+ })
25
+
26
+ describe "MiniTest::Assertions#mu_pp" do
27
+ def mu_pp(*args)
28
+ (@w ||= Whatever.new).mu_pp(*args)
29
+ end
30
+
31
+ it "has no effect on bools" do
32
+ assert_equal "true", mu_pp(true)
33
+ assert_equal "false", mu_pp(false)
34
+ end
35
+
36
+ it "has no effect on strings" do
37
+ assert_equal '"Whatever"', mu_pp("Whatever")
38
+ end
39
+
40
+ it "pretty-prints arrays" do
41
+ assert_equal $array, mu_pp(%w[Alpha Beta])
42
+ end
43
+
44
+ it "pretty-prints hashes" do
45
+ assert_equal $hash, mu_pp({ "Alpha" => 1, "Beta" => 2 })
46
+ end
47
+
48
+ it "pretty-prints recursive structures" do
49
+ assert_equal $nested, mu_pp({ "Alpha" => ["Beta", { "Gamma" => "Epsilon" }]})
50
+ end
51
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: minitest-pretty_diff
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Adam Mckaig
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - adam.mckaig@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/minitest/pretty_diff.rb
21
+ - test/test_pretty_diff.rb
22
+ homepage: https://github.com/adammck/minitest-pretty_diff
23
+ licenses: []
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.0.0
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Pretty-print hashes and arrays before diffing them in MiniTest
45
+ test_files:
46
+ - test/test_pretty_diff.rb