nala 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nala/rspec.rb +4 -0
- data/lib/nala/version.rb +1 -1
- data/readme.md +38 -14
- 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: cdba579249251211672cfe2194920064d8c347a5
|
4
|
+
data.tar.gz: def872611eadb7bfc924939c4a51792562b50eed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25eca85f93b3b66134ee9ec135eb0842424c349cc6e67bd961564bc16237fc8aad3c08d709d959a933c5ede12f872eb38d1af2046a2715c2220e976a36264484
|
7
|
+
data.tar.gz: 0052b8685f00185a3ca665aa945c060e9e2aafb9cf3d4a9f68a5f182f3b6ad059205de47b285372611005147ff57de99b880613948d8ef4d78bee2c1d454baf5
|
data/lib/nala/rspec.rb
CHANGED
data/lib/nala/version.rb
CHANGED
data/readme.md
CHANGED
@@ -18,11 +18,13 @@ gem "nala"
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
-
Nala is intended to be used with use case style classes where the class performs
|
22
|
-
single action. These classes typically have verb names such as `PlaceOrder`
|
21
|
+
Nala is intended to be used with use case style classes where the class performs
|
22
|
+
a single action. These classes typically have verb names such as `PlaceOrder`
|
23
|
+
etc.
|
23
24
|
|
24
25
|
To use, add the `Nala::Publisher` module to your class and expose a `call`
|
25
|
-
instance method. If your class requires data, it can be passed to it via the
|
26
|
+
instance method. If your class requires data, it can be passed to it via the
|
27
|
+
constructor.
|
26
28
|
|
27
29
|
For example:
|
28
30
|
|
@@ -46,9 +48,9 @@ class PlaceOrder
|
|
46
48
|
end
|
47
49
|
```
|
48
50
|
|
49
|
-
Usage of these use case style classes gives a home to your business logic,
|
50
|
-
conditionals from your Rails controllers and helps prevent your models
|
51
|
-
big.
|
51
|
+
Usage of these use case style classes gives a home to your business logic,
|
52
|
+
removes conditionals from your Rails controllers and helps prevent your models
|
53
|
+
getting too big.
|
52
54
|
|
53
55
|
```ruby
|
54
56
|
class OrderController < ApplicationController
|
@@ -83,13 +85,15 @@ end
|
|
83
85
|
|
84
86
|
## Testing with RSpec
|
85
87
|
|
86
|
-
If you are using RSpec then you can use the supplied matcher by adding the
|
88
|
+
If you are using RSpec then you can use the supplied matcher by adding the
|
89
|
+
following line to your `spec_helper.rb` file:
|
87
90
|
|
88
91
|
```ruby
|
89
92
|
require "nala/rspec"
|
90
93
|
```
|
91
94
|
|
92
|
-
Then within your specs, you can confirm that a handler is called with the
|
95
|
+
Then within your specs, you can confirm that a handler is called with the
|
96
|
+
following:
|
93
97
|
|
94
98
|
```ruby
|
95
99
|
let(:block) { Nala::BlockSpy.new }
|
@@ -101,36 +105,56 @@ it "invokes a handler for a published event" do
|
|
101
105
|
end
|
102
106
|
```
|
103
107
|
|
104
|
-
If you want to check the arguments that are passed to the block you can use the
|
108
|
+
If you want to check the arguments that are passed to the block you can use the
|
109
|
+
following:
|
105
110
|
|
106
111
|
```ruby
|
107
112
|
let(:block) { Nala::BlockSpy.new }
|
108
113
|
|
109
114
|
it "passes multiple arguments to handlers" do
|
110
115
|
PublishArgsClass.call
|
111
|
-
.on(:multiple) { |*
|
116
|
+
.on(:multiple) { |*args| block.called_with!(args) }
|
112
117
|
|
113
118
|
expect(block).to be_called_with(:a, :b, :c)
|
114
119
|
end
|
115
120
|
```
|
116
121
|
|
117
|
-
If you need check the arguments attributes in more detail you can do the
|
122
|
+
If you need check the arguments attributes in more detail you can do the
|
123
|
+
following:
|
118
124
|
|
119
125
|
```ruby
|
120
126
|
let(:block) { Nala::BlockSpy.new }
|
121
127
|
|
122
128
|
it "passes a user with the correct name" do
|
123
129
|
RegisterUser.call
|
124
|
-
.on(:success) { |*
|
130
|
+
.on(:success) { |*args| block.called_with!(args) }
|
125
131
|
|
126
132
|
user = block.args.first
|
127
133
|
expect(user.name).to eq("Andy")
|
128
134
|
end
|
129
135
|
```
|
130
136
|
|
131
|
-
|
137
|
+
You can make the tracking of block arguments less verbose by using the `spy`
|
138
|
+
method of `Nala::BlockSpy` and passing it as an explicit block to the `on`
|
139
|
+
method:
|
132
140
|
|
133
|
-
|
141
|
+
```ruby
|
142
|
+
let(:block) { Nala::BlockSpy.new }
|
143
|
+
|
144
|
+
it "passes multiple arguments to handlers" do
|
145
|
+
PublishArgsClass.call
|
146
|
+
.on(:multiple, &block.spy)
|
147
|
+
|
148
|
+
expect(block).to be_called_with(:a, :b, :c)
|
149
|
+
end
|
150
|
+
```
|
151
|
+
|
152
|
+
## Notes for maintainers
|
153
|
+
|
154
|
+
**Building a publishing gem updates**
|
155
|
+
|
156
|
+
Bump the version number in `lib/nala/version.rb` and use the same number in the
|
157
|
+
command below:
|
134
158
|
|
135
159
|
```
|
136
160
|
gem build nala.gemspec
|