grasshopper 1.0.3 → 1.1.0
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.
- checksums.yaml +4 -4
- data/lib/grasshopper/mock.rb +15 -6
- data/test/mock_test.rb +20 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f36a0c227cf946ef50021e982dd5ff157e3081ef
|
4
|
+
data.tar.gz: 7ab775ed1bf4de49d066a9052b2140b7aa1ac6ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5e265459c4bcebae31daffacbce85cb3e7699b2112bc405236f0e81a0bed5aed82a8a2fa151b9a800280307f8f469cc8488313e6de55bb846149e9c474eeabb9
|
7
|
+
data.tar.gz: 9099f632b40f45619d4341f26871f7efeab7be24fb42059e48bc77b9593ebc32bb5b6ea95dec0b796e2f334acf54eee4ee00346c517159e0d470c3cf7288bed2
|
data/lib/grasshopper/mock.rb
CHANGED
@@ -11,17 +11,17 @@ module Grasshopper
|
|
11
11
|
def method_missing(message, *args, &block)
|
12
12
|
request = MessageHeard.new(message, args)
|
13
13
|
|
14
|
-
@
|
14
|
+
@requests ||= []
|
15
15
|
if @verify_next
|
16
16
|
if args.first.is_a? AnyParams
|
17
|
-
index = @
|
17
|
+
index = @requests.index { |heard| request.message == heard.message }
|
18
18
|
else
|
19
|
-
index = @
|
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
|
-
@
|
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#{@
|
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
|
-
@
|
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
|
data/test/mock_test.rb
CHANGED
@@ -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
|
-
|
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
|
75
|
-
mock.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
|
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
|
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-
|
11
|
+
date: 2017-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|