state_machines-yard 0.0.1 → 0.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 +5 -5
- data/.github/workflows/ci.yml +24 -0
- data/.github/workflows/release.yml +16 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +1 -1
- data/README.md +8 -1
- data/Rakefile +11 -0
- data/lib/state_machines/yard/handlers/base.rb +6 -4
- data/lib/state_machines/yard/handlers/event.rb +9 -4
- data/lib/state_machines/yard/handlers/machine.rb +46 -29
- data/lib/state_machines/yard/handlers/state.rb +9 -4
- data/lib/state_machines/yard/handlers/transition.rb +6 -3
- data/lib/state_machines/yard/handlers.rb +3 -7
- data/lib/state_machines/yard/version.rb +1 -1
- data/lib/state_machines/yard.rb +9 -4
- data/state_machines-yard.gemspec +8 -8
- data/test/handlers/base_test.rb +76 -0
- data/test/handlers/event_test.rb +84 -0
- data/test/handlers/machine_test.rb +72 -0
- data/test/handlers/state_test.rb +66 -0
- data/test/handlers/transition_test.rb +108 -0
- data/test/integration_test.rb +152 -0
- data/test/templates_test.rb +72 -0
- data/test/test_helper.rb +37 -0
- metadata +60 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f44c4181dbd4a72f83b7a3c39b41c12a70decb9cc9479f942322eead08cab927
|
4
|
+
data.tar.gz: 6c992389d5a3ab8cda9e879871ceccc9fd071283278b292e69e8bd54b0e80f00
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31dbd1176ec57de4d9fb5221008d7bc651f7508a47fe407b401f536ac738f7788b2b5555bfbf4c1d0913838bb5f3ca5b7762ef022b4ed40b3955bc9c567692b4
|
7
|
+
data.tar.gz: 1a298b682b5ff8a3c1074e49f54bdf41b8b06e5f2122825fcc4465d052e1efed9455228b95162ca53dad431cdc13ecad8c3691056bd3257c25982802c14d2193
|
@@ -0,0 +1,24 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: [ master ]
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
build:
|
11
|
+
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@v4
|
16
|
+
- name: Set up Ruby
|
17
|
+
uses: ruby/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: '3.0'
|
20
|
+
bundler-cache: true
|
21
|
+
- name: Install graphviz
|
22
|
+
run: sudo apt-get update && sudo apt-get install -y graphviz
|
23
|
+
- name: Run tests
|
24
|
+
run: bundle exec rake
|
@@ -0,0 +1,16 @@
|
|
1
|
+
name: Release Please
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
release-please:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
steps:
|
12
|
+
- uses: actions/checkout@v4
|
13
|
+
- uses: googleapis/release-please-action@v3
|
14
|
+
with:
|
15
|
+
release-type: ruby
|
16
|
+
package-name: state_machines-yard
|
data/CHANGELOG.md
ADDED
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -16,10 +16,17 @@ Or install it yourself as:
|
|
16
16
|
|
17
17
|
$ gem install state_machines-yard
|
18
18
|
|
19
|
+
## Testing
|
20
|
+
|
21
|
+
A comprehensive test suite is included for the gem. To run all tests:
|
22
|
+
|
23
|
+
```
|
24
|
+
rake test
|
25
|
+
```
|
19
26
|
|
20
27
|
## Contributing
|
21
28
|
|
22
|
-
1. Fork it ( https://github.com/
|
29
|
+
1. Fork it ( https://github.com/state-machines/state_machines-yard/fork )
|
23
30
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
24
31
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
25
32
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/Rakefile
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
module
|
2
|
-
module
|
1
|
+
module StateMachines
|
2
|
+
module Yard
|
3
3
|
module Handlers
|
4
4
|
# Handles and processes nodes
|
5
|
-
class Base <
|
5
|
+
class Base < YARD::Handlers::Ruby::Base
|
6
6
|
|
7
7
|
private
|
8
8
|
|
@@ -21,7 +21,9 @@ module StateMachine
|
|
21
21
|
# Extracts the values from the node as either strings or symbols.
|
22
22
|
# If the node isn't an array, it'll be converted to an array.
|
23
23
|
def extract_node_names(ast, convert_to_array = true)
|
24
|
-
if
|
24
|
+
if ast.is_a?(Array)
|
25
|
+
ast.map { |child| extract_node_name(child) }
|
26
|
+
elsif ast.nil? || ast.type == :array
|
25
27
|
ast.children.map { |child| extract_node_name(child) }
|
26
28
|
else
|
27
29
|
node_name = extract_node_name(ast)
|
@@ -1,9 +1,12 @@
|
|
1
|
-
module
|
2
|
-
module
|
1
|
+
module StateMachines
|
2
|
+
module Yard
|
3
3
|
module Handlers
|
4
4
|
# Handles and processes #event
|
5
5
|
class Event < Base
|
6
6
|
handles method_call(:event)
|
7
|
+
|
8
|
+
# Store the handled method name for testing
|
9
|
+
@handles_method = :event
|
7
10
|
|
8
11
|
def process
|
9
12
|
if owner.is_a?(StateMachines::Machine)
|
@@ -13,8 +16,10 @@ module StateMachine
|
|
13
16
|
|
14
17
|
names.each do |name|
|
15
18
|
owner.event(name) do
|
16
|
-
# Parse the block
|
17
|
-
|
19
|
+
# Parse the block only if it exists
|
20
|
+
if statement.block
|
21
|
+
handler.parse_block(statement.block.last, owner: self)
|
22
|
+
end
|
18
23
|
end
|
19
24
|
end
|
20
25
|
end
|
@@ -1,10 +1,13 @@
|
|
1
|
-
module
|
2
|
-
module
|
1
|
+
module StateMachines
|
2
|
+
module Yard
|
3
3
|
module Handlers
|
4
4
|
# Handles and processes #state_machine
|
5
5
|
class Machine < Base
|
6
6
|
handles method_call(:state_machine)
|
7
7
|
namespace_only
|
8
|
+
|
9
|
+
# Store the handled method name for testing
|
10
|
+
@handles_method = :state_machine
|
8
11
|
|
9
12
|
# The generated state machine
|
10
13
|
attr_reader :machine
|
@@ -85,7 +88,7 @@ module StateMachine
|
|
85
88
|
namespace.inheritance_tree.each do |ancestor|
|
86
89
|
begin
|
87
90
|
ensure_loaded!(ancestor)
|
88
|
-
rescue
|
91
|
+
rescue YARD::Handlers::NamespaceMissingError
|
89
92
|
# Ignore: just means that we can't access an ancestor
|
90
93
|
end
|
91
94
|
end
|
@@ -103,7 +106,7 @@ module StateMachine
|
|
103
106
|
# Gets members of this class's superclasses have already been loaded
|
104
107
|
# by YARD
|
105
108
|
def loaded_superclasses
|
106
|
-
namespace.inheritance_tree.select { |ancestor| ancestor.is_a?(
|
109
|
+
namespace.inheritance_tree.select { |ancestor| ancestor.is_a?(YARD::CodeObjects::ClassObject) }
|
107
110
|
end
|
108
111
|
|
109
112
|
# Gets a list of all attributes for the current class, including those
|
@@ -132,10 +135,11 @@ module StateMachine
|
|
132
135
|
|
133
136
|
# Defines auto-generated macro methods for the given machine
|
134
137
|
def define_macro_methods
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
138
|
+
# Don't exit early for inherited machine since we need to register instance methods
|
139
|
+
# even for inherited machines
|
140
|
+
|
141
|
+
# Human state name lookup (class method)
|
142
|
+
register(m = YARD::CodeObjects::MethodObject.new(namespace, "human_#{machine.attribute(:name)}", :class))
|
139
143
|
m.docstring = [
|
140
144
|
'Gets the humanized name for the given state.',
|
141
145
|
"@param [#{state_type}] state The state to look up",
|
@@ -143,14 +147,17 @@ module StateMachine
|
|
143
147
|
]
|
144
148
|
m.parameters = ['state']
|
145
149
|
|
146
|
-
# Human event name lookup
|
147
|
-
register(m =
|
150
|
+
# Human event name lookup (class method)
|
151
|
+
register(m = YARD::CodeObjects::MethodObject.new(namespace, "human_#{machine.attribute(:event_name)}", :class))
|
148
152
|
m.docstring = [
|
149
153
|
'Gets the humanized name for the given event.',
|
150
154
|
"@param [#{event_type}] event The event to look up",
|
151
155
|
'@return [String] The human event name'
|
152
156
|
]
|
153
157
|
m.parameters = ['event']
|
158
|
+
|
159
|
+
# Skip the rest if this is an inherited machine
|
160
|
+
return if inherited_machine
|
154
161
|
|
155
162
|
# Only register attributes when the accessor isn't explicitly defined
|
156
163
|
# by the class / superclass *and* isn't defined by inference from the
|
@@ -160,7 +167,7 @@ module StateMachine
|
|
160
167
|
namespace.attributes[:instance][attribute] = {}
|
161
168
|
|
162
169
|
# Machine attribute getter
|
163
|
-
register(m =
|
170
|
+
register(m = YARD::CodeObjects::MethodObject.new(namespace, attribute))
|
164
171
|
namespace.attributes[:instance][attribute][:read] = m
|
165
172
|
m.docstring = [
|
166
173
|
'Gets the current attribute value for the machine',
|
@@ -168,7 +175,7 @@ module StateMachine
|
|
168
175
|
]
|
169
176
|
|
170
177
|
# Machine attribute setter
|
171
|
-
register(m =
|
178
|
+
register(m = YARD::CodeObjects::MethodObject.new(namespace, "#{attribute}="))
|
172
179
|
namespace.attributes[:instance][attribute][:write] = m
|
173
180
|
m.docstring = [
|
174
181
|
'Sets the current value for the machine',
|
@@ -182,7 +189,7 @@ module StateMachine
|
|
182
189
|
namespace.attributes[:instance][attribute] = {}
|
183
190
|
|
184
191
|
# Machine event attribute getter
|
185
|
-
register(m =
|
192
|
+
register(m = YARD::CodeObjects::MethodObject.new(namespace, attribute))
|
186
193
|
namespace.attributes[:instance][attribute][:read] = m
|
187
194
|
m.docstring = [
|
188
195
|
'Gets the current event attribute value for the machine',
|
@@ -190,7 +197,7 @@ module StateMachine
|
|
190
197
|
]
|
191
198
|
|
192
199
|
# Machine event attribute setter
|
193
|
-
register(m =
|
200
|
+
register(m = YARD::CodeObjects::MethodObject.new(namespace, "#{attribute}="))
|
194
201
|
namespace.attributes[:instance][attribute][:write] = m
|
195
202
|
m.docstring = [
|
196
203
|
'Sets the current value for the machine',
|
@@ -199,8 +206,10 @@ module StateMachine
|
|
199
206
|
m.parameters = ["new_#{attribute}"]
|
200
207
|
end
|
201
208
|
|
209
|
+
# These instance methods are always defined, even for inherited machines
|
210
|
+
|
202
211
|
# Presence query
|
203
|
-
register(m =
|
212
|
+
register(m = YARD::CodeObjects::MethodObject.new(namespace, "#{machine.name}?"))
|
204
213
|
m.docstring = [
|
205
214
|
'Checks the given state name against the current state.',
|
206
215
|
"@param [#{state_type}] state_name The name of the state to check",
|
@@ -210,21 +219,29 @@ module StateMachine
|
|
210
219
|
m.parameters = ['state_name']
|
211
220
|
|
212
221
|
# Internal state name
|
213
|
-
register(m =
|
222
|
+
register(m = YARD::CodeObjects::MethodObject.new(namespace, machine.attribute(:name)))
|
214
223
|
m.docstring = [
|
215
224
|
'Gets the internal name of the state for the current value.',
|
216
225
|
"@return [#{state_type}] The internal name of the state"
|
217
226
|
]
|
218
227
|
|
219
|
-
# Human state name
|
220
|
-
|
228
|
+
# Human state name instance method - this is always defined regardless of inheritance
|
229
|
+
# Ensure the name is correct - we explicitly check the attribute name to make sure it's generated correctly
|
230
|
+
human_method_name = "human_#{machine.attribute(:name)}"
|
231
|
+
register(m = YARD::CodeObjects::MethodObject.new(namespace, human_method_name))
|
221
232
|
m.docstring = [
|
222
233
|
'Gets the human-readable name of the state for the current value.',
|
223
234
|
'@return [String] The human-readable state name'
|
224
235
|
]
|
236
|
+
|
237
|
+
# Debug output for testing - we want to make sure we're registering the method correctly
|
238
|
+
# puts "Registered instance method: #{namespace}##{human_method_name} (#{m})"
|
239
|
+
|
240
|
+
# The below methods should only be defined for non-inherited machines
|
241
|
+
return if inherited_machine
|
225
242
|
|
226
243
|
# Available events
|
227
|
-
register(m =
|
244
|
+
register(m = YARD::CodeObjects::MethodObject.new(namespace, machine.attribute(:events)))
|
228
245
|
m.docstring = [
|
229
246
|
"Gets the list of events that can be fired on the current #{machine.name} (uses the *unqualified* event names)",
|
230
247
|
'@param [Hash] requirements The transition requirements to test against',
|
@@ -237,7 +254,7 @@ module StateMachine
|
|
237
254
|
m.parameters = [['requirements', '{}']]
|
238
255
|
|
239
256
|
# Available transitions
|
240
|
-
register(m =
|
257
|
+
register(m = YARD::CodeObjects::MethodObject.new(namespace, machine.attribute(:transitions)))
|
241
258
|
m.docstring = [
|
242
259
|
"Gets the list of transitions that can be made for the current #{machine.name}",
|
243
260
|
'@param [Hash] requirements The transition requirements to test against',
|
@@ -250,7 +267,7 @@ module StateMachine
|
|
250
267
|
m.parameters = [['requirements', '{}']]
|
251
268
|
|
252
269
|
# Available transition paths
|
253
|
-
register(m =
|
270
|
+
register(m = YARD::CodeObjects::MethodObject.new(namespace, machine.attribute(:paths)))
|
254
271
|
m.docstring = [
|
255
272
|
"Gets the list of sequences of transitions that can be run for the current #{machine.name}",
|
256
273
|
'@param [Hash] requirements The transition requirements to test against',
|
@@ -263,7 +280,7 @@ module StateMachine
|
|
263
280
|
m.parameters = [['requirements', '{}']]
|
264
281
|
|
265
282
|
# Generic event fire
|
266
|
-
register(m =
|
283
|
+
register(m = YARD::CodeObjects::MethodObject.new(namespace, "fire_#{machine.attribute(:event)}"))
|
267
284
|
m.docstring = [
|
268
285
|
"Fires an arbitrary #{machine.name} event with the given argument list",
|
269
286
|
"@param [#{event_type}] event The name of the event to fire",
|
@@ -279,11 +296,11 @@ module StateMachine
|
|
279
296
|
next if inherited_machine && inherited_machine.events[event.name]
|
280
297
|
|
281
298
|
# Event query
|
282
|
-
register(m =
|
299
|
+
register(m = YARD::CodeObjects::MethodObject.new(namespace, "can_#{event.qualified_name}?"))
|
283
300
|
m.docstring = [
|
284
301
|
"Checks whether #{event.name.inspect} can be fired.",
|
285
302
|
'@param [Hash] requirements The transition requirements to test against',
|
286
|
-
"@option requirements [#{state_type}] :from
|
303
|
+
"@option requirements [#{state_type}] :from One or more initial states",
|
287
304
|
"@option requirements [#{state_type}] :to One or more target states",
|
288
305
|
'@option requirements [Boolean] :guard Whether to guard transitions with conditionals',
|
289
306
|
"@return [Boolean] +true+ if #{event.name.inspect} can be fired, otherwise +false+"
|
@@ -291,11 +308,11 @@ module StateMachine
|
|
291
308
|
m.parameters = [['requirements', '{}']]
|
292
309
|
|
293
310
|
# Event transition
|
294
|
-
register(m =
|
311
|
+
register(m = YARD::CodeObjects::MethodObject.new(namespace, "#{event.qualified_name}_transition"))
|
295
312
|
m.docstring = [
|
296
313
|
"Gets the next transition that would be performed if #{event.name.inspect} were to be fired.",
|
297
314
|
'@param [Hash] requirements The transition requirements to test against',
|
298
|
-
"@option requirements [#{state_type}] :from
|
315
|
+
"@option requirements [#{state_type}] :from One or more initial states",
|
299
316
|
"@option requirements [#{state_type}] :to One or more target states",
|
300
317
|
'@option requirements [Boolean] :guard Whether to guard transitions with conditionals',
|
301
318
|
'@return [StateMachines::Transition] The transition that would be performed or +nil+'
|
@@ -303,7 +320,7 @@ module StateMachine
|
|
303
320
|
m.parameters = [['requirements', '{}']]
|
304
321
|
|
305
322
|
# Fire event
|
306
|
-
register(m =
|
323
|
+
register(m = YARD::CodeObjects::MethodObject.new(namespace, event.qualified_name))
|
307
324
|
m.docstring = [
|
308
325
|
"Fires the #{event.name.inspect} event.",
|
309
326
|
'@param [Array] args Optional arguments to include in transition callbacks',
|
@@ -312,7 +329,7 @@ module StateMachine
|
|
312
329
|
m.parameters = ['*args']
|
313
330
|
|
314
331
|
# Fire event (raises exception)
|
315
|
-
register(m =
|
332
|
+
register(m = YARD::CodeObjects::MethodObject.new(namespace, "#{event.qualified_name}!"))
|
316
333
|
m.docstring = [
|
317
334
|
"Fires the #{event.name.inspect} event, raising an exception if it fails.",
|
318
335
|
'@param [Array] args Optional arguments to include in transition callbacks',
|
@@ -329,7 +346,7 @@ module StateMachine
|
|
329
346
|
next if inherited_machine && inherited_machine.states[state.name] || !state.name
|
330
347
|
|
331
348
|
# State query
|
332
|
-
register(m =
|
349
|
+
register(m = YARD::CodeObjects::MethodObject.new(namespace, "#{state.qualified_name}?"))
|
333
350
|
m.docstring = [
|
334
351
|
"Checks whether #{state.name.inspect} is the current state.",
|
335
352
|
'@return [Boolean] +true+ if this is the current state, otherwise +false+'
|
@@ -1,9 +1,12 @@
|
|
1
|
-
module
|
2
|
-
module
|
1
|
+
module StateMachines
|
2
|
+
module Yard
|
3
3
|
module Handlers
|
4
4
|
# Handles and processes #state
|
5
5
|
class State < Base
|
6
6
|
handles method_call(:state)
|
7
|
+
|
8
|
+
# Store the handled method name for testing
|
9
|
+
@handles_method = :state
|
7
10
|
|
8
11
|
def process
|
9
12
|
if owner.is_a?(StateMachines::Machine)
|
@@ -13,8 +16,10 @@ module StateMachine
|
|
13
16
|
|
14
17
|
names.each do |name|
|
15
18
|
owner.state(name) do
|
16
|
-
# Parse the block
|
17
|
-
|
19
|
+
# Parse the block only if it exists
|
20
|
+
if statement.block
|
21
|
+
handler.parse_block(statement.block.last, owner: self)
|
22
|
+
end
|
18
23
|
end
|
19
24
|
end
|
20
25
|
end
|
@@ -1,9 +1,12 @@
|
|
1
|
-
module
|
2
|
-
module
|
1
|
+
module StateMachines
|
2
|
+
module Yard
|
3
3
|
module Handlers
|
4
4
|
# Handles and processes #transition
|
5
5
|
class Transition < Base
|
6
6
|
handles method_call(:transition)
|
7
|
+
|
8
|
+
# Store the handled method name for testing
|
9
|
+
@handles_method = :transition
|
7
10
|
|
8
11
|
def process
|
9
12
|
if [StateMachines::Machine, StateMachines::Event, StateMachines::State].include?(owner.class)
|
@@ -13,7 +16,7 @@ module StateMachine
|
|
13
16
|
ast = statement.parameters.first
|
14
17
|
ast.children.each do |assoc|
|
15
18
|
# Skip conditionals
|
16
|
-
next if %w(if unless).include?(assoc[0].jump(:ident).source)
|
19
|
+
next if %w(if :if unless :unless).include?(assoc[0].jump(:ident).source)
|
17
20
|
|
18
21
|
options[extract_requirement(assoc[0])] = extract_requirement(assoc[1])
|
19
22
|
end
|
@@ -1,12 +1,8 @@
|
|
1
|
-
module
|
2
|
-
module
|
1
|
+
module StateMachines
|
2
|
+
module Yard
|
3
3
|
# YARD custom handlers for integrating the state_machine DSL with the
|
4
4
|
# YARD documentation system
|
5
5
|
module Handlers
|
6
6
|
end
|
7
7
|
end
|
8
|
-
end
|
9
|
-
|
10
|
-
Dir["#{File.dirname(__FILE__)}/handlers/*.rb"].sort.each do |path|
|
11
|
-
require "state_machines/yard/handlers/#{File.basename(path)}"
|
12
|
-
end
|
8
|
+
end
|
data/lib/state_machines/yard.rb
CHANGED
@@ -1,10 +1,15 @@
|
|
1
|
-
require '
|
1
|
+
require 'yard'
|
2
|
+
require_relative 'yard/version'
|
2
3
|
module StateMachines
|
3
4
|
# YARD plugin for automated documentation
|
4
5
|
module Yard
|
5
6
|
end
|
6
7
|
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
require_relative 'yard/handlers'
|
10
|
+
require_relative 'yard/handlers/base'
|
11
|
+
require_relative 'yard/handlers/event'
|
12
|
+
require_relative 'yard/handlers/machine'
|
13
|
+
require_relative 'yard/handlers/state'
|
14
|
+
require_relative 'yard/handlers/transition'
|
15
|
+
require_relative 'yard/templates'
|
data/state_machines-yard.gemspec
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'state_machines/yard/version'
|
1
|
+
require_relative 'lib/state_machines/yard/version'
|
5
2
|
|
6
3
|
Gem::Specification.new do |spec|
|
7
4
|
spec.name = 'state_machines-yard'
|
@@ -10,16 +7,19 @@ Gem::Specification.new do |spec|
|
|
10
7
|
spec.email = ['terminale@gmail.com']
|
11
8
|
spec.summary = %q(State machines YARD plugin)
|
12
9
|
spec.description = %q(State machines YARD plugin for automated documentation)
|
13
|
-
spec.homepage = 'https://github.com/
|
10
|
+
spec.homepage = 'https://github.com/state-machines/state_machines-yard'
|
14
11
|
spec.license = 'MIT'
|
15
12
|
|
16
|
-
spec.required_ruby_version = '>=
|
13
|
+
spec.required_ruby_version = '>= 3.0'
|
17
14
|
|
18
15
|
spec.files = `git ls-files -z`.split("\x0")
|
19
16
|
spec.require_paths = ['lib']
|
20
17
|
|
21
18
|
spec.add_dependency 'yard'
|
22
19
|
spec.add_dependency 'state_machines-graphviz'
|
23
|
-
spec.
|
24
|
-
spec.add_development_dependency '
|
20
|
+
spec.add_dependency 'rdoc'
|
21
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
22
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
23
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
24
|
+
spec.add_development_dependency 'nokogiri'
|
25
25
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class BaseHandlerTest < Minitest::Test
|
4
|
+
include TestHelpers
|
5
|
+
|
6
|
+
def setup
|
7
|
+
setup_yard
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
cleanup_yard
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_extract_node_name_with_symbol
|
15
|
+
code = <<-RUBY
|
16
|
+
class TestClass
|
17
|
+
state_machine :status do
|
18
|
+
# Test using a symbol
|
19
|
+
state :parked
|
20
|
+
end
|
21
|
+
end
|
22
|
+
RUBY
|
23
|
+
|
24
|
+
parse_code(code)
|
25
|
+
|
26
|
+
# We can't directly test the extract_node_name method since it's private
|
27
|
+
# But we can test that symbol nodes were correctly processed
|
28
|
+
test_class = YARD::Registry.at('TestClass')
|
29
|
+
refute_nil test_class, "TestClass should be registered"
|
30
|
+
|
31
|
+
parked_method = YARD::Registry.at('TestClass#parked?')
|
32
|
+
refute_nil parked_method, "parked? method should be registered"
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_extract_node_name_with_string
|
36
|
+
code = <<-RUBY
|
37
|
+
class TestClass
|
38
|
+
state_machine :status do
|
39
|
+
# Test using a string
|
40
|
+
state "moving"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
RUBY
|
44
|
+
|
45
|
+
parse_code(code)
|
46
|
+
|
47
|
+
# Test that string nodes were correctly processed
|
48
|
+
test_class = YARD::Registry.at('TestClass')
|
49
|
+
refute_nil test_class, "TestClass should be registered"
|
50
|
+
|
51
|
+
moving_method = YARD::Registry.at('TestClass#moving?')
|
52
|
+
refute_nil moving_method, "moving? method should be registered"
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_extract_node_names_with_array
|
56
|
+
code = <<-RUBY
|
57
|
+
class TestClass
|
58
|
+
state_machine :status do
|
59
|
+
# Test using an array
|
60
|
+
state :parked, :idling, :moving
|
61
|
+
end
|
62
|
+
end
|
63
|
+
RUBY
|
64
|
+
|
65
|
+
parse_code(code)
|
66
|
+
|
67
|
+
# Test that array nodes were correctly processed
|
68
|
+
test_class = YARD::Registry.at('TestClass')
|
69
|
+
refute_nil test_class, "TestClass should be registered"
|
70
|
+
|
71
|
+
%w(parked idling moving).each do |state|
|
72
|
+
method = YARD::Registry.at("TestClass##{state}?")
|
73
|
+
refute_nil method, "#{state}? method should be registered"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|