grasshopper 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5035f3e632e16b9ba58e9a5e96abed5328070b6e
4
- data.tar.gz: d3d4ed98cffa450c981d598145e866e020e93d8b
3
+ metadata.gz: d2f0e558f28c51b97c4458d0443572bd0232fc70
4
+ data.tar.gz: 18fe3c7c0729018c8963cc253100cc36c93907e5
5
5
  SHA512:
6
- metadata.gz: 5ad589cd74f3c3333b6f2096118a6b0e0afd53c108f271ea9f453fa19c33b1825828192bc862ba32a1db1332688be9ef64f08ebf72d39bf09331790747a8b899
7
- data.tar.gz: 13af0e1a2278196183e06edb6e2ac1d817cd387745363a345e31e44d43d00c9202c6b978e3208e40dd9b7ec6dc57c9d7e6368cff2fe4f9aac3fbe995378c1be2
6
+ metadata.gz: 081cd246aa43654bf16c1dd466eac5f8354919bd25aae5de58ddf2b2cbaca1e405b8e30de8798b2e802dbdc861ffb6f9d713892b653f85fb44cec06359510f08
7
+ data.tar.gz: 01e85437d1520afe44a96a3c3d9da1568020aa390b00e9d0ee8ffd2a6036fab0fa9729ee5843a60fdef14cd38d29b7734e161f31db7e5404d93eb155228507eb
@@ -19,19 +19,31 @@ module Grasshopper
19
19
  index = @messages.index { |heard| request == heard }
20
20
  end
21
21
  if index.nil?
22
- raise "Should have seen an invocation of #{message}(#{args.join(", ")})\n#{@messages.inspect}"
22
+ raise not_seen_exception(request)
23
23
  end
24
24
  @messages.delete_at(index || @messages.length)
25
25
  else
26
- @messages << request
26
+ record_request(request)
27
27
  end
28
28
  nil
29
29
  end
30
30
 
31
- MessageHeard = Struct.new(:message, :args)
31
+ def not_seen_exception(request)
32
+ NotSeen.new("Should have seen an invocation of #{request})\n\nMessages Seen:\n#{@messages.map(&:to_s).join("\n")}")
33
+ end
34
+
35
+ def record_request(request)
36
+ @messages << request
37
+ end
38
+
39
+ MessageHeard = Struct.new(:message, :args) do
40
+ def to_s
41
+ "#{self.message}(#{self.args.join(", ")})"
42
+ end
43
+ end
32
44
 
33
45
  def self.verify mock
34
- raise "Not a #{self.class}" unless mock.is_a? Grasshopper::Mock
46
+ raise "Tried to verify a #{mock.class}" unless mock.is_a? Grasshopper::Mock
35
47
  mock.verify_next
36
48
  mock
37
49
  end
@@ -43,4 +55,7 @@ module Grasshopper
43
55
  class AnyParams
44
56
  end
45
57
  end
58
+
59
+ class NotSeen < ::Exception
60
+ end
46
61
  end
@@ -5,7 +5,7 @@ class MockTest < MiniTest::Test
5
5
  def test_fails_verify_if_no_such_message
6
6
  mock = Grasshopper::Mock.new
7
7
 
8
- assert_raises RuntimeError do
8
+ assert_raises Grasshopper::NotSeen do
9
9
  Grasshopper::Mock.verify(mock).never_sent
10
10
  end
11
11
  end
@@ -26,7 +26,7 @@ class MockTest < MiniTest::Test
26
26
  mock = Grasshopper::Mock.new
27
27
  mock.message_sent_once
28
28
 
29
- assert_raises RuntimeError do
29
+ assert_raises Grasshopper::NotSeen do
30
30
  2.times { Grasshopper::Mock.verify(mock).message_sent_once }
31
31
  end
32
32
  end
@@ -47,16 +47,25 @@ class MockTest < MiniTest::Test
47
47
  mock = Grasshopper::Mock.new
48
48
  mock.message_with_param("param")
49
49
 
50
- assert_raises RuntimeError do
50
+ e = assert_raises Grasshopper::NotSeen do
51
51
  Grasshopper::Mock.verify(mock).message_with_param("wrong param")
52
52
  end
53
+
54
+ expected_message = <<-TXT.chomp
55
+ Should have seen an invocation of message_with_param(wrong param))
56
+
57
+ Messages Seen:
58
+ message_with_param(param)
59
+ TXT
60
+
61
+ assert_equal(expected_message, e.message)
53
62
  end
54
63
 
55
64
  def test_validate_wrong_number_params_explodes
56
65
  mock = Grasshopper::Mock.new
57
66
  mock.message_with_param("param", "two")
58
67
 
59
- assert_raises RuntimeError do
68
+ assert_raises Grasshopper::NotSeen do
60
69
  Grasshopper::Mock.verify(mock).message_with_param("param")
61
70
  end
62
71
  end
@@ -64,7 +73,11 @@ class MockTest < MiniTest::Test
64
73
  def test_any_param_matcher_can_stand_in_for_any_param
65
74
  mock = Grasshopper::Mock.new
66
75
  mock.value = "nice value"
76
+ mock.other_value = "other value"
77
+ mock.takes_two(1, 2)
67
78
  Grasshopper::Mock.verify(mock).value= Grasshopper::Mock.any_params
79
+ Grasshopper::Mock.verify(mock).other_value= Grasshopper::Mock.any_params
80
+ Grasshopper::Mock.verify(mock).takes_two Grasshopper::Mock.any_params
68
81
  end
69
82
 
70
83
  def test_always_returns_nil
@@ -74,10 +87,13 @@ class MockTest < MiniTest::Test
74
87
  assert_nil mock.anything(["even with array params"])
75
88
  end
76
89
 
90
+ OtherObject = Struct.new(:foo)
91
+
77
92
  def test_dont_verify_non_mocks
78
- non_mock = Object.new
79
- assert_raises RuntimeError do
93
+ non_mock = OtherObject.new
94
+ e = assert_raises RuntimeError do
80
95
  Grasshopper::Mock.verify(non_mock)
81
96
  end
97
+ assert_equal("Tried to verify a MockTest::OtherObject", e.message)
82
98
  end
83
99
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grasshopper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt J Raibert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-09 00:00:00.000000000 Z
11
+ date: 2017-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest