rspec-action-check 0.1.2 → 0.2.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/README.md +99 -7
- data/img/action_after_branch.dot +23 -0
- data/img/action_after_branch.png +0 -0
- data/lib/rspec/actioncheck/helpers.rb +60 -43
- data/lib/rspec/actioncheck/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a121b48c55174e651803170283633801b7de78f7
|
4
|
+
data.tar.gz: eb763340fc204484bd0a552e856af20be6a231c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 580488ae10ad6259793c37a4da027d13f336adce5f1c568331c062c68bd18b456bde1c7ee81fdace88a30cb902f2f5cd8746571c187b984a815cfb4260933278
|
7
|
+
data.tar.gz: 86fb40720dd778ab9b622b122e63f5d8d1ec6a424e020a13c72d077a439c11a54e89df6e4a5384d50a38af4b0f3980bcc4637cf87279341547a2904373522657
|
data/README.md
CHANGED
@@ -21,6 +21,24 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
24
|
+
### How to use your projects
|
25
|
+
|
26
|
+
#### Rails
|
27
|
+
|
28
|
+
Please add spec/rails_helper.rb
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
require 'rspec/actioncheck'
|
32
|
+
```
|
33
|
+
|
34
|
+
#### Other
|
35
|
+
|
36
|
+
Please add spec/spec_helper.rb
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
require 'rspec/actioncheck'
|
40
|
+
```
|
41
|
+
|
24
42
|
### Simple case
|
25
43
|
|
26
44
|
You can write that code in spec.
|
@@ -41,7 +59,7 @@ RSpec.describe 'First Example' do
|
|
41
59
|
expect(@some_state1).to eq 100
|
42
60
|
end
|
43
61
|
|
44
|
-
action 'set some_state2 =
|
62
|
+
action 'set some_state2 = 200' do
|
45
63
|
@some_state2 = 200
|
46
64
|
end
|
47
65
|
|
@@ -59,7 +77,7 @@ First Example
|
|
59
77
|
some actions like a scenario test story
|
60
78
|
action:set some_state1 = 100
|
61
79
|
check:some_state1 = 100
|
62
|
-
action:set some_state2 =
|
80
|
+
action:set some_state2 = 200
|
63
81
|
check:some_state2 = 200
|
64
82
|
```
|
65
83
|
|
@@ -165,22 +183,96 @@ It output that when It run
|
|
165
183
|
Branch Example
|
166
184
|
some actions like a scenario test story with branching
|
167
185
|
action:set some_state1 = 100
|
168
|
-
|
186
|
+
branch:branch1
|
169
187
|
check:some_state1 = 100
|
170
188
|
action:set some_state2 = 200
|
171
189
|
check:some_state1 = 100 and some_state2 == 200
|
172
|
-
|
190
|
+
branch:branch in branch1
|
173
191
|
action:set some_state3 = 300
|
174
192
|
check:some_state1 = 100 and some_state2 == 200 and some_state3 == 300
|
175
|
-
|
193
|
+
branch:branch` in branch1
|
176
194
|
check:some_state1 = 100 and some_state2 == 200 and some_state3 is nil
|
177
|
-
|
195
|
+
branch:branch2
|
178
196
|
check:some_state1 = 100 and some_state2 is nil
|
179
197
|
```
|
180
198
|
|
181
199
|
It same as ... That code as too long. I will write it when I feel like it.
|
182
200
|
|
183
|
-
|
201
|
+
### Meger branches
|
202
|
+
|
203
|
+
```ruby
|
204
|
+
RSpec.describe 'Action after branch' do
|
205
|
+
before do
|
206
|
+
@some_state1 = nil
|
207
|
+
@some_state2 = nil
|
208
|
+
@some_state3 = nil
|
209
|
+
end
|
210
|
+
|
211
|
+
actions 'some actions like a scenario test story' do
|
212
|
+
action 'start' do
|
213
|
+
end
|
214
|
+
|
215
|
+
branch 'branch1' do
|
216
|
+
action 'set some_state1 = 100' do
|
217
|
+
@some_state1 = 100
|
218
|
+
end
|
219
|
+
|
220
|
+
action 'set some_state2 = 200' do
|
221
|
+
@some_state2 = 200
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
branch 'branch2' do
|
226
|
+
action 'set some_state1 = 200' do
|
227
|
+
@some_state1 = 200
|
228
|
+
end
|
229
|
+
|
230
|
+
action 'set some_state2 = 100' do
|
231
|
+
@some_state2 = 100
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
check 'both state is not nil' do
|
236
|
+
expect(@some_state1).not_to be_nil
|
237
|
+
expect(@some_state2).not_to be_nil
|
238
|
+
end
|
239
|
+
|
240
|
+
action 'set some_state3 = 300' do
|
241
|
+
@some_state3 = 300
|
242
|
+
end
|
243
|
+
|
244
|
+
check 'some_state3 = 300' do
|
245
|
+
expect(@some_state3).to eq 300
|
246
|
+
end
|
247
|
+
end
|
248
|
+
end
|
249
|
+
```
|
250
|
+
|
251
|
+
It output that when It run
|
252
|
+
|
253
|
+
```
|
254
|
+
Action after branch
|
255
|
+
some actions like a scenario test story
|
256
|
+
action:start
|
257
|
+
branch:branch1
|
258
|
+
action:set some_state1 = 100
|
259
|
+
action:set some_state2 = 200
|
260
|
+
check:both state is not nil
|
261
|
+
action:set some_state3 = 300
|
262
|
+
check:some_state3 = 300
|
263
|
+
branch:branch2
|
264
|
+
action:set some_state1 = 200
|
265
|
+
action:set some_state2 = 100
|
266
|
+
check:both state is not nil
|
267
|
+
action:set some_state3 = 300
|
268
|
+
check:some_state3 = 300
|
269
|
+
```
|
270
|
+
|
271
|
+
In the figure
|
272
|
+
|
273
|
+

|
274
|
+
|
275
|
+
All examples contain in `spec/rspec/example/`
|
184
276
|
|
185
277
|
## Development
|
186
278
|
|
@@ -0,0 +1,23 @@
|
|
1
|
+
// The Round Table
|
2
|
+
digraph {
|
3
|
+
S [label=start]
|
4
|
+
A1 [label=branch1]
|
5
|
+
A2 [label="action:set some_state1 = 100"]
|
6
|
+
A3 [label="action:set some_state2 = 200"]
|
7
|
+
B1 [label=branch2]
|
8
|
+
B2 [label="action:set some_state1 = 200"]
|
9
|
+
B3 [label="action:set some_state2 = 100"]
|
10
|
+
C [label="check:both state is not nil"]
|
11
|
+
D [label="action:set some_state3 = 300"]
|
12
|
+
E [label="check:some_state3 = 300"]
|
13
|
+
S -> A1
|
14
|
+
S -> B1
|
15
|
+
A1 -> A2
|
16
|
+
A2 -> A3
|
17
|
+
B1 -> B2
|
18
|
+
B2 -> B3
|
19
|
+
A3 -> C
|
20
|
+
B3 -> C
|
21
|
+
C -> D
|
22
|
+
D -> E
|
23
|
+
}
|
Binary file
|
@@ -2,13 +2,6 @@ module RSpec
|
|
2
2
|
module ActionCheck
|
3
3
|
module Helpers
|
4
4
|
module ClassMethods
|
5
|
-
def __before_action_name
|
6
|
-
:root
|
7
|
-
end
|
8
|
-
def __action_dags
|
9
|
-
{}
|
10
|
-
end
|
11
|
-
|
12
5
|
def create_from_dag(node)
|
13
6
|
Proc.new do ||
|
14
7
|
node[:forwards].each do |next_node_name|
|
@@ -27,7 +20,14 @@ module RSpec
|
|
27
20
|
|
28
21
|
def actions(description, &actions_block)
|
29
22
|
context description do
|
30
|
-
|
23
|
+
self.define_singleton_method(:__action_dags) do ||
|
24
|
+
{}
|
25
|
+
end
|
26
|
+
self.define_singleton_method(:__branch_tail_actions) do ||
|
27
|
+
[]
|
28
|
+
end
|
29
|
+
_update_before_action_names([:root])
|
30
|
+
before_action_name = __before_action_names[0]
|
31
31
|
self.module_exec(&actions_block)
|
32
32
|
if __action_dags.empty?
|
33
33
|
pending 'actions is empty'
|
@@ -41,39 +41,54 @@ module RSpec
|
|
41
41
|
|
42
42
|
def branch(description, &branch_block)
|
43
43
|
name = "#{description.gsub(/ /, "_")}_#{__action_dags.size}".to_sym
|
44
|
-
|
44
|
+
before_action_names = __before_action_names
|
45
45
|
|
46
|
-
_update_action_dags(name, description,
|
46
|
+
_update_action_dags(name, description, before_action_names, Proc.new{}, 'branch')
|
47
47
|
|
48
|
+
tail_before_action_names = nil
|
48
49
|
context do
|
49
|
-
|
50
|
+
_update_before_action_names([name])
|
51
|
+
self.define_singleton_method(:__branch_tail_actions) do ||
|
52
|
+
[]
|
53
|
+
end
|
50
54
|
self.module_exec(&branch_block)
|
55
|
+
tail_before_action_names = __before_action_names
|
56
|
+
end
|
57
|
+
_update_before_action_names(__before_action_names)
|
58
|
+
t = __branch_tail_actions
|
59
|
+
self.define_singleton_method(:__branch_tail_actions) do ||
|
60
|
+
t + tail_before_action_names
|
51
61
|
end
|
52
62
|
end
|
53
63
|
|
54
64
|
def action(description, &action_block)
|
55
|
-
|
65
|
+
before_action_names = (not __branch_tail_actions.empty?) ? __branch_tail_actions : __before_action_names
|
56
66
|
name = "#{description.gsub(/ /, "_")}_#{__action_dags.size}".to_sym
|
57
67
|
|
58
|
-
|
68
|
+
_update_before_action_names([name])
|
59
69
|
|
60
|
-
_update_action_dags(name, description,
|
70
|
+
_update_action_dags(name, description, before_action_names, action_block)
|
71
|
+
self.define_singleton_method(:__branch_tail_actions) do ||
|
72
|
+
[]
|
73
|
+
end
|
61
74
|
end
|
62
75
|
|
63
76
|
def check(description, &action_block)
|
64
|
-
|
77
|
+
check_action_names = (not __branch_tail_actions.empty?) ? __branch_tail_actions : __before_action_names
|
65
78
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
79
|
+
check_action_names.each do |check_action_name|
|
80
|
+
_action_dags = __action_dags
|
81
|
+
_action_dags[check_action_name][:examples] << {
|
82
|
+
description: description,
|
83
|
+
block: action_block,
|
84
|
+
}
|
85
|
+
define_singleton_method(:__action_dags) do ||
|
86
|
+
_action_dags
|
87
|
+
end
|
73
88
|
end
|
74
89
|
end
|
75
90
|
|
76
|
-
def _update_action_dags(name, action_description,
|
91
|
+
def _update_action_dags(name, action_description, before_action_names, action_block, prefix='action')
|
77
92
|
|
78
93
|
_action_dags = __action_dags
|
79
94
|
_action_dags[name] = {
|
@@ -81,30 +96,32 @@ module RSpec
|
|
81
96
|
backwards: [],
|
82
97
|
examples: [],
|
83
98
|
} if _action_dags[name].nil?
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
99
|
+
|
100
|
+
before_action_names.each do |before_action_name|
|
101
|
+
_action_dags[before_action_name] = {
|
102
|
+
forwards: [],
|
103
|
+
backwards: [],
|
104
|
+
examples: [],
|
105
|
+
} if _action_dags[before_action_name].nil?
|
106
|
+
_action_dags[name].merge!({
|
107
|
+
forwards: _action_dags[name][:forwards],
|
108
|
+
backwards: _action_dags[name][:backwards] | [before_action_name],
|
109
|
+
action: {description: "#{prefix}:#{action_description}", block: action_block},
|
110
|
+
})
|
111
|
+
_action_dags[before_action_name].merge!({
|
112
|
+
forwards: _action_dags[before_action_name][:forwards] | [name],
|
113
|
+
backwards: _action_dags[before_action_name][:backwards],
|
114
|
+
})
|
115
|
+
self.define_singleton_method(:__action_dags) do ||
|
116
|
+
_action_dags
|
117
|
+
end
|
100
118
|
end
|
101
119
|
end
|
102
120
|
|
103
|
-
def
|
104
|
-
define_singleton_method(:
|
105
|
-
|
121
|
+
def _update_before_action_names(names)
|
122
|
+
define_singleton_method(:__before_action_names) do ||
|
123
|
+
names
|
106
124
|
end
|
107
|
-
|
108
125
|
end
|
109
126
|
end
|
110
127
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-action-check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuta Hinokuma
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -69,6 +69,8 @@ files:
|
|
69
69
|
- Rakefile
|
70
70
|
- bin/console
|
71
71
|
- bin/setup
|
72
|
+
- img/action_after_branch.dot
|
73
|
+
- img/action_after_branch.png
|
72
74
|
- lib/rspec/actioncheck.rb
|
73
75
|
- lib/rspec/actioncheck/helpers.rb
|
74
76
|
- lib/rspec/actioncheck/proxy.rb
|