brown 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -9
- data/lib/brown/rspec.rb +11 -0
- data/lib/brown/test.rb +31 -4
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 831f8702bad84d8fe35c098f0a624632ab06f835
|
4
|
+
data.tar.gz: 55684d48c7e8233a7cd6d68621f77116e2b05f49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f879eb251cb5b9e511d4331a2b5e84c1c8590a80a846bf7c1d7ff813f50bf359be28a7421ffa5b718e5190d6a2fa59e25139c47f9399529d203bd8427a238096
|
7
|
+
data.tar.gz: cbf37ca7b491d245d85e389d74ad91187d6824ec86503010b054b5eb9e0a7c5ab00950eaaa871df283a487f684843b59bdae48f18d8f0d6d854c3cb216d4ac52
|
data/README.md
CHANGED
@@ -161,15 +161,14 @@ simply receive stimuli and act on them, testing is quite simple in
|
|
161
161
|
principle, but the parallelism inherent in agents can make them hard to test
|
162
162
|
without some extra helpers.
|
163
163
|
|
164
|
-
To enable the additional testing helpers, you must `require
|
165
|
-
|
166
|
-
|
167
|
-
{Brown::
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
mocks/spies).
|
164
|
+
To enable the additional testing helpers, you must `require 'brown/test'`
|
165
|
+
somewhere in your testing setup, before you define your agents. This will
|
166
|
+
add a bunch of extra methods, defined in {Brown::TestHelpers} to
|
167
|
+
{Brown::Agent}, which you can then call to examine certain aspects of the
|
168
|
+
agent (such as `memo?(name)` and `amqp_publisher?(name)`) as well as send
|
169
|
+
stimuli to the agent and have it behave appropriately, which you can then
|
170
|
+
make assertions about (either by examining the new state of the overall
|
171
|
+
system, or through the use of mocks/spies).
|
173
172
|
|
174
173
|
While full documentation for all of the helper methods are available in the
|
175
174
|
YARD docs for {Brown::TestHelpers}, here are some specific tips for using
|
@@ -178,6 +177,10 @@ them to test certain aspects of your agents in popular testing frameworks.
|
|
178
177
|
|
179
178
|
### RSpec
|
180
179
|
|
180
|
+
To enable additional RSpec-specific test integration (resetting memos at the
|
181
|
+
end of each test), then **instead** of `require 'brown/test'`, you should
|
182
|
+
`require 'brown/rspec'` before your agent code is loaded.
|
183
|
+
|
181
184
|
To test a directly declared stimulus, you don't need to do very much -- you
|
182
185
|
can just instantiate the agent class and call the method you want:
|
183
186
|
|
data/lib/brown/rspec.rb
ADDED
data/lib/brown/test.rb
CHANGED
@@ -5,7 +5,7 @@ require 'brown/agent/amqp_message_mock'
|
|
5
5
|
#
|
6
6
|
# You can cause these methods to become part of {Brown::Agent} with
|
7
7
|
#
|
8
|
-
# require 'brown/
|
8
|
+
# require 'brown/test'
|
9
9
|
#
|
10
10
|
module Brown::TestHelpers
|
11
11
|
#:nodoc:
|
@@ -51,6 +51,23 @@ module Brown::TestHelpers
|
|
51
51
|
@memos[name] = Brown::Agent::Memo.new(generator, safe, true)
|
52
52
|
end
|
53
53
|
|
54
|
+
# Reset all memos to "undefined" values.
|
55
|
+
#
|
56
|
+
# Because memo values are cached at the class level, this means that they're
|
57
|
+
# cached between test cases. Often, this isn't what you want (because if the
|
58
|
+
# value of the memo was changed by a test case, the next test won't run in a
|
59
|
+
# pristine environment). Calling this method will cause all of the memos in
|
60
|
+
# the agent to be reset to a state which is the same as if the memo had never
|
61
|
+
# been called at all.
|
62
|
+
#
|
63
|
+
def reset_memos
|
64
|
+
@memos ||= {}
|
65
|
+
|
66
|
+
@memos.values.each do |memo|
|
67
|
+
memo.instance_variable_set(:@cached_value, nil)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
54
71
|
# Is there a timer which will go off every `n` seconds registered on this
|
55
72
|
# agent?
|
56
73
|
#
|
@@ -67,7 +84,14 @@ module Brown::TestHelpers
|
|
67
84
|
# @param n [Integer]
|
68
85
|
#
|
69
86
|
def trigger(n)
|
70
|
-
self.instance_methods.select { |m| m =~ /^every_#{n}__/ }
|
87
|
+
trigger_methods = self.instance_methods.select { |m| m =~ /^every_#{n}__/ }
|
88
|
+
|
89
|
+
if trigger_methods.empty?
|
90
|
+
raise RuntimeError,
|
91
|
+
"Nothing is set to run every #{n} second#{n == 1 ? "" : "s"}"
|
92
|
+
end
|
93
|
+
|
94
|
+
trigger_methods.each do |m|
|
71
95
|
self.new.__send__(m)
|
72
96
|
end
|
73
97
|
end
|
@@ -146,7 +170,11 @@ module Brown::TestHelpers
|
|
146
170
|
|
147
171
|
msg = Brown::Agent::AMQPMessageMock.new(opts.merge(payload: payload))
|
148
172
|
|
149
|
-
|
173
|
+
self.new.tap do |p|
|
174
|
+
uuid = SecureRandom.uuid
|
175
|
+
p.singleton_class.__send__(:define_method, uuid, &@amqp_listeners[exchange_name])
|
176
|
+
p.__send__(uuid, msg)
|
177
|
+
end
|
150
178
|
|
151
179
|
msg.acked?
|
152
180
|
end
|
@@ -155,4 +183,3 @@ end
|
|
155
183
|
class << Brown::Agent
|
156
184
|
include Brown::TestHelpers
|
157
185
|
end
|
158
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: brown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Palmer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-06-
|
11
|
+
date: 2015-06-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
@@ -206,6 +206,7 @@ files:
|
|
206
206
|
- lib/brown/agent/amqp_publisher.rb
|
207
207
|
- lib/brown/agent/memo.rb
|
208
208
|
- lib/brown/agent/stimulus.rb
|
209
|
+
- lib/brown/rspec.rb
|
209
210
|
- lib/brown/test.rb
|
210
211
|
homepage: http://theshed.hezmatt.org/brown
|
211
212
|
licenses: []
|