nala 0.0.7 → 0.0.8
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/nala/rspec.rb +16 -0
- data/lib/nala/version.rb +1 -1
- data/readme.md +19 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10e423acb67e8578fc4b9c652b138b9b1979dce6
|
4
|
+
data.tar.gz: 85e858c8451d9ef09346981ccee760dbc804e140
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35dcef02bab31d9ca81df1a6ef999731ec10f58cf388f1b27d10fbd7a5cfc912e2788f17656ee54cbd8cc158dcc3e4c871dc66913bf9a9c1d2e0c7eb00df8690
|
7
|
+
data.tar.gz: ba908b8cd78c9d0d3f14d04a8bc698c9b8dff44128250c8fde68a4387cf6c20f86bfc60c7f0d40d7c6440f38e38a846e8a904aae338691db3f80e09d04c54647
|
data/lib/nala/rspec.rb
CHANGED
@@ -26,6 +26,22 @@ module Nala
|
|
26
26
|
proc { |*args| called_with!(args) }
|
27
27
|
end
|
28
28
|
end
|
29
|
+
|
30
|
+
module RSpecHelpers
|
31
|
+
def emit(event, *args)
|
32
|
+
Nala::EventEmitter.new.tap do |emitter|
|
33
|
+
emitter.store_result(event, args)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def block_spy
|
38
|
+
Nala::BlockSpy.new
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
RSpec.configure do |config|
|
44
|
+
config.include Nala::RSpecHelpers
|
29
45
|
end
|
30
46
|
|
31
47
|
RSpec::Matchers.define :be_called_with do |*expected_args|
|
data/lib/nala/version.rb
CHANGED
data/readme.md
CHANGED
@@ -106,7 +106,7 @@ Then within your specs, you can confirm that a handler is called with the
|
|
106
106
|
following:
|
107
107
|
|
108
108
|
```ruby
|
109
|
-
let(:block) {
|
109
|
+
let(:block) { block_spy }
|
110
110
|
|
111
111
|
it "invokes a handler for a published event" do
|
112
112
|
SuccessClass.call.on(:success) { block.called! }
|
@@ -119,7 +119,7 @@ If you want to check the arguments that are passed to the block you can use the
|
|
119
119
|
following:
|
120
120
|
|
121
121
|
```ruby
|
122
|
-
let(:block) {
|
122
|
+
let(:block) { block_spy }
|
123
123
|
|
124
124
|
it "passes multiple arguments to handlers" do
|
125
125
|
PublishArgsClass.call
|
@@ -133,7 +133,7 @@ If you need check the arguments attributes in more detail you can do the
|
|
133
133
|
following:
|
134
134
|
|
135
135
|
```ruby
|
136
|
-
let(:block) {
|
136
|
+
let(:block) { block_spy }
|
137
137
|
|
138
138
|
it "passes a user with the correct name" do
|
139
139
|
RegisterUser.call
|
@@ -145,11 +145,10 @@ end
|
|
145
145
|
```
|
146
146
|
|
147
147
|
You can make the tracking of block arguments less verbose by using the `spy`
|
148
|
-
method of `Nala::BlockSpy` and passing it as an explicit block to the `on`
|
149
|
-
method:
|
148
|
+
method of `Nala::BlockSpy` (which `block_spy` returns) and passing it as an explicit block to the `on` method:
|
150
149
|
|
151
150
|
```ruby
|
152
|
-
let(:block) {
|
151
|
+
let(:block) { block_spy }
|
153
152
|
|
154
153
|
it "passes multiple arguments to handlers" do
|
155
154
|
PublishArgsClass.call.on(:multiple, &block.spy)
|
@@ -163,8 +162,8 @@ recommend naming your block after the event it will be called by (rather than
|
|
163
162
|
just `block`):
|
164
163
|
|
165
164
|
```ruby
|
166
|
-
let(:success) {
|
167
|
-
let(:notified) {
|
165
|
+
let(:success) { block_spy }
|
166
|
+
let(:notified) { block_spy }
|
168
167
|
|
169
168
|
it "calls multiple handlers" do
|
170
169
|
PlaceOrder.call
|
@@ -176,6 +175,18 @@ it "calls multiple handlers" do
|
|
176
175
|
end
|
177
176
|
```
|
178
177
|
|
178
|
+
If you would like to stub calls to the `.call` method of your use case class but want to make sure handlers are called, you can use the supplied `emit` helper method like so:
|
179
|
+
|
180
|
+
```
|
181
|
+
allow(SuccessClass).to receive(:call) { emit(:success) }
|
182
|
+
```
|
183
|
+
|
184
|
+
or you can supply arguments to the block:
|
185
|
+
|
186
|
+
```
|
187
|
+
allow(SuccessClass).to receive(:call) { emit(:success, "My Argument") }
|
188
|
+
```
|
189
|
+
|
179
190
|
## Notes for maintainers
|
180
191
|
|
181
192
|
**Building a publishing gem updates**
|