grasshopper 1.0.3 → 1.1.0

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: d2f0e558f28c51b97c4458d0443572bd0232fc70
4
- data.tar.gz: 18fe3c7c0729018c8963cc253100cc36c93907e5
3
+ metadata.gz: f36a0c227cf946ef50021e982dd5ff157e3081ef
4
+ data.tar.gz: 7ab775ed1bf4de49d066a9052b2140b7aa1ac6ef
5
5
  SHA512:
6
- metadata.gz: 081cd246aa43654bf16c1dd466eac5f8354919bd25aae5de58ddf2b2cbaca1e405b8e30de8798b2e802dbdc861ffb6f9d713892b653f85fb44cec06359510f08
7
- data.tar.gz: 01e85437d1520afe44a96a3c3d9da1568020aa390b00e9d0ee8ffd2a6036fab0fa9729ee5843a60fdef14cd38d29b7734e161f31db7e5404d93eb155228507eb
6
+ metadata.gz: 5e265459c4bcebae31daffacbce85cb3e7699b2112bc405236f0e81a0bed5aed82a8a2fa151b9a800280307f8f469cc8488313e6de55bb846149e9c474eeabb9
7
+ data.tar.gz: 9099f632b40f45619d4341f26871f7efeab7be24fb42059e48bc77b9593ebc32bb5b6ea95dec0b796e2f334acf54eee4ee00346c517159e0d470c3cf7288bed2
@@ -11,17 +11,17 @@ module Grasshopper
11
11
  def method_missing(message, *args, &block)
12
12
  request = MessageHeard.new(message, args)
13
13
 
14
- @messages ||= []
14
+ @requests ||= []
15
15
  if @verify_next
16
16
  if args.first.is_a? AnyParams
17
- index = @messages.index { |heard| request.message == heard.message }
17
+ index = @requests.index { |heard| request.message == heard.message }
18
18
  else
19
- index = @messages.index { |heard| request == heard }
19
+ index = @requests.index { |heard| request == heard }
20
20
  end
21
21
  if index.nil?
22
22
  raise not_seen_exception(request)
23
23
  end
24
- @messages.delete_at(index || @messages.length)
24
+ @requests.delete_at(index || @requests.length)
25
25
  else
26
26
  record_request(request)
27
27
  end
@@ -29,11 +29,17 @@ module Grasshopper
29
29
  end
30
30
 
31
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")}")
32
+ NotSeen.new("Should have seen an invocation of #{request})\n\nMessages Seen:\n#{@requests.map(&:to_s).join("\n")}")
33
33
  end
34
34
 
35
35
  def record_request(request)
36
- @messages << request
36
+ @requests << request
37
+ end
38
+
39
+ def verify_responds_to_heard_messages(instance)
40
+ @requests.each do |request|
41
+ raise NotImplemented.new(request) unless instance.respond_to?(request.message)
42
+ end
37
43
  end
38
44
 
39
45
  MessageHeard = Struct.new(:message, :args) do
@@ -58,4 +64,7 @@ module Grasshopper
58
64
 
59
65
  class NotSeen < ::Exception
60
66
  end
67
+
68
+ class NotImplemented < ::Exception
69
+ end
61
70
  end
@@ -16,6 +16,20 @@ class MockTest < MiniTest::Test
16
16
  Grasshopper::Mock.verify(mock).message_was_sent
17
17
  end
18
18
 
19
+ def test_verify_messages_sent_to_mock
20
+ mock = Grasshopper::Mock.new
21
+ mock.message_was_sent
22
+ mock.verify_responds_to_heard_messages(Struct.new(:message_was_sent).new)
23
+ end
24
+
25
+ def test_verify_unimplemented_messages_explode
26
+ mock = Grasshopper::Mock.new
27
+ mock.message_not_implemented
28
+ assert_raises Grasshopper::NotImplemented do
29
+ mock.verify_responds_to_heard_messages(Struct.new(:message_was_sent).new)
30
+ end
31
+ end
32
+
19
33
  def test_can_verify_number_of_invocations
20
34
  mock = Grasshopper::Mock.new
21
35
  2.times { mock.message_sent_twice }
@@ -26,8 +40,9 @@ class MockTest < MiniTest::Test
26
40
  mock = Grasshopper::Mock.new
27
41
  mock.message_sent_once
28
42
 
43
+ Grasshopper::Mock.verify(mock).message_sent_once
29
44
  assert_raises Grasshopper::NotSeen do
30
- 2.times { Grasshopper::Mock.verify(mock).message_sent_once }
45
+ Grasshopper::Mock.verify(mock).message_sent_once
31
46
  end
32
47
  end
33
48
 
@@ -71,11 +86,11 @@ message_with_param(param)
71
86
  end
72
87
 
73
88
  def test_any_param_matcher_can_stand_in_for_any_param
74
- mock = Grasshopper::Mock.new
75
- mock.value = "nice value"
89
+ mock = Grasshopper::Mock.new
90
+ mock.value = "nice value"
76
91
  mock.other_value = "other value"
77
92
  mock.takes_two(1, 2)
78
- Grasshopper::Mock.verify(mock).value= Grasshopper::Mock.any_params
93
+ Grasshopper::Mock.verify(mock).value = Grasshopper::Mock.any_params
79
94
  Grasshopper::Mock.verify(mock).other_value= Grasshopper::Mock.any_params
80
95
  Grasshopper::Mock.verify(mock).takes_two Grasshopper::Mock.any_params
81
96
  end
@@ -91,7 +106,7 @@ message_with_param(param)
91
106
 
92
107
  def test_dont_verify_non_mocks
93
108
  non_mock = OtherObject.new
94
- e = assert_raises RuntimeError do
109
+ e = assert_raises RuntimeError do
95
110
  Grasshopper::Mock.verify(non_mock)
96
111
  end
97
112
  assert_equal("Tried to verify a MockTest::OtherObject", e.message)
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.3
4
+ version: 1.1.0
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-10 00:00:00.000000000 Z
11
+ date: 2017-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest