minitest-great_expectations 0.0.3 → 0.0.4
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/README.md +6 -0
- data/lib/minitest/great_expectations.rb +31 -3
- data/lib/minitest/great_expectations/version.rb +1 -1
- data/test/great_expectations_test.rb +24 -0
- metadata +4 -4
data/README.md
CHANGED
@@ -5,6 +5,7 @@ having, especially if you're coming from rspec:
|
|
5
5
|
|
6
6
|
``` ruby
|
7
7
|
[1, 2, 3].must_equal_contents [3, 2, 1]
|
8
|
+
{:a => 1, :b => 2}.must_equal_hash {:b => 2, :a => 1}
|
8
9
|
[1, 2, 3].must_include_all [1, 2]
|
9
10
|
something.works?.should_be_true
|
10
11
|
```
|
@@ -39,6 +40,11 @@ And then execute:
|
|
39
40
|
|
40
41
|
## Changelog
|
41
42
|
|
43
|
+
### 0.0.4
|
44
|
+
|
45
|
+
* Added ```assert_equal_hash```/```must_equal_hash```
|
46
|
+
* Reordered error messages to be more consistent with must_equal/assert_equal
|
47
|
+
|
42
48
|
### 0.0.3
|
43
49
|
|
44
50
|
* Added ```assert_includes_none```/```wont_include_any```
|
@@ -18,7 +18,34 @@ module MiniTest::Assertions
|
|
18
18
|
error_msgs << "Extraneous actual elements:\n #{mu_pp missing_from_expected}"
|
19
19
|
end
|
20
20
|
unless error_msgs.empty?
|
21
|
-
message ||= "Expected:\n #{mu_pp
|
21
|
+
message ||= "Expected:\n #{mu_pp expected}\nDid not match contents of Actual:\n #{mu_pp actual}."
|
22
|
+
flunk("#{message}\n#{error_msgs.join("\n")}")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Hash keys and values must be the same
|
27
|
+
def assert_equal_hash(expected, actual, message = nil)
|
28
|
+
e_keys = expected.keys
|
29
|
+
a_keys = actual.keys
|
30
|
+
error_msgs = []
|
31
|
+
missing_from_actual = e_keys - a_keys
|
32
|
+
unless missing_from_actual.empty?
|
33
|
+
error_msgs << "Missing expected keys:\n #{mu_pp missing_from_actual}"
|
34
|
+
end
|
35
|
+
missing_from_expected = a_keys - e_keys
|
36
|
+
unless missing_from_expected.empty?
|
37
|
+
error_msgs << "Extraneous actual keys:\n #{mu_pp missing_from_expected}"
|
38
|
+
end
|
39
|
+
intersecting_keys = e_keys & a_keys
|
40
|
+
intersecting_keys.each do |ea|
|
41
|
+
exp = expected[ea]
|
42
|
+
act = actual[ea]
|
43
|
+
unless exp == act
|
44
|
+
error_msgs << "Expected [#{mu_pp ea}]: #{mu_pp exp}\nActual [#{mu_pp ea}]: #{mu_pp act}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
unless error_msgs.empty?
|
48
|
+
message ||= "Expected:\n #{mu_pp expected}\ndid not equal Actual:\n #{mu_pp actual}."
|
22
49
|
flunk("#{message}\n#{error_msgs.join("\n")}")
|
23
50
|
end
|
24
51
|
end
|
@@ -27,7 +54,7 @@ module MiniTest::Assertions
|
|
27
54
|
def assert_includes_all(expected, actual, message = nil)
|
28
55
|
missing_from_expected = expected.to_a - actual.to_a
|
29
56
|
unless missing_from_expected.empty?
|
30
|
-
message ||= "Expected:\n #{mu_pp
|
57
|
+
message ||= "Expected:\n #{mu_pp expected}\ndid not contain every element in Actual:\n #{mu_pp actual}."
|
31
58
|
flunk("#{message}\nMissing expected elements:\n #{mu_pp missing_from_expected}")
|
32
59
|
end
|
33
60
|
end
|
@@ -35,7 +62,7 @@ module MiniTest::Assertions
|
|
35
62
|
def assert_includes_none(expected, actual, message = nil)
|
36
63
|
unexpected = expected.to_a & actual.to_a
|
37
64
|
unless unexpected.empty?
|
38
|
-
message ||= "Expected:\n #{mu_pp
|
65
|
+
message ||= "Expected:\n #{mu_pp expected}\ncontained elements in Actual:\n #{mu_pp actual}."
|
39
66
|
flunk("#{message}\nUnexpected elements:\n #{mu_pp unexpected.sort}")
|
40
67
|
end
|
41
68
|
end
|
@@ -65,6 +92,7 @@ end
|
|
65
92
|
|
66
93
|
module MiniTest::Expectations
|
67
94
|
infect_an_assertion :assert_equal_contents, :must_equal_contents
|
95
|
+
infect_an_assertion :assert_equal_hash, :must_equal_hash
|
68
96
|
infect_an_assertion :assert_includes_all, :must_include_all
|
69
97
|
infect_an_assertion :assert_includes_none, :wont_include_any
|
70
98
|
infect_an_assertion :assert_true, :must_be_true, :unary
|
@@ -46,6 +46,30 @@ describe "must_equal_contents" do
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
describe "assert_equal_hash" do
|
50
|
+
it "passes for empty" do
|
51
|
+
assert_equal_hash({}, {})
|
52
|
+
end
|
53
|
+
it "passes for hash" do
|
54
|
+
assert_equal_hash({:a => 1, :b => 2}, {:b => 2, :a => 1})
|
55
|
+
end
|
56
|
+
it "complains about missing values" do
|
57
|
+
l = lambda { assert_equal_hash({:a => 1, :b => 2}, {:b => 2}) }
|
58
|
+
error = assert_raises(MiniTest::Assertion, &l)
|
59
|
+
error.message.must_match /Missing expected keys:.*\[:a\]/im
|
60
|
+
end
|
61
|
+
it "complains about extra values" do
|
62
|
+
l = lambda { assert_equal_hash({:a => 1}, {:a => 1, :b => 2}) }
|
63
|
+
error = assert_raises(MiniTest::Assertion, &l)
|
64
|
+
error.message.must_match /Extraneous actual keys.*\[:b\]/im
|
65
|
+
end
|
66
|
+
it "complains about different values for the same key" do
|
67
|
+
l = lambda { assert_equal_hash({:a => 1}, {:a => 2}) }
|
68
|
+
error = assert_raises(MiniTest::Assertion, &l)
|
69
|
+
error.message.must_match /Expected \[:a\]:.*1.Actual \[:a\]:.*2/im
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
49
73
|
describe "assert_includes_all" do
|
50
74
|
it "passes on empty expected" do
|
51
75
|
assert_includes_all([], [])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-great_expectations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-02-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -92,7 +92,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
92
92
|
version: '0'
|
93
93
|
segments:
|
94
94
|
- 0
|
95
|
-
hash:
|
95
|
+
hash: 285768661627063719
|
96
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
97
|
none: false
|
98
98
|
requirements:
|
@@ -101,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '0'
|
102
102
|
segments:
|
103
103
|
- 0
|
104
|
-
hash:
|
104
|
+
hash: 285768661627063719
|
105
105
|
requirements: []
|
106
106
|
rubyforge_project:
|
107
107
|
rubygems_version: 1.8.23
|