minitest-great_expectations 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
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 actual}\nto equal contents of:\n #{mu_pp expected}."
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 actual}\nto contain every element in:\n #{mu_pp expected}."
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 actual}\nnot to contain any element in:\n #{mu_pp expected}."
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
@@ -1,5 +1,5 @@
1
1
  module Minitest
2
2
  module GreatExpectations
3
- VERSION = "0.0.3"
3
+ VERSION = "0.0.4"
4
4
  end
5
5
  end
@@ -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.3
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-01-05 00:00:00.000000000 Z
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: -246921461347167831
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: -246921461347167831
104
+ hash: 285768661627063719
105
105
  requirements: []
106
106
  rubyforge_project:
107
107
  rubygems_version: 1.8.23