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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: ae4aeccc3211632b5b25f19bfa30b576adfcc4fc
4
- data.tar.gz: 797a207f6c1a883619c089148ab7d76fa4c5640c
2
+ SHA256:
3
+ metadata.gz: f44c4181dbd4a72f83b7a3c39b41c12a70decb9cc9479f942322eead08cab927
4
+ data.tar.gz: 6c992389d5a3ab8cda9e879871ceccc9fd071283278b292e69e8bd54b0e80f00
5
5
  SHA512:
6
- metadata.gz: 3bd4c0b651acab5ea3469ec81e33a78209ebbec1f81c84adc89159fa42cba8b97178570d662223388855c7cbe8493c65a84c9cc0d9ffcdedbcd4d063939065d2
7
- data.tar.gz: f027b5799f58e0a5a43d1910013ee1d55d8d0eb0af5ae75ea57c39b7e90e5ba19139c6f486bb5b092841ebabae7b811d31344dc32fdd2e4cba840288b5fba72b
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
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0 (2025-03-18)
4
+
5
+
6
+ ### Features
7
+
8
+ * add tests ([37d6f34](https://github.com/state-machines/state_machines-yard/commit/37d6f3482d98222dfbb4940cf1f2ba846d95ca5f))
data/Gemfile CHANGED
@@ -1,2 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
  gemspec
3
+
4
+ gem 'ruby-graphviz', github: 'seuros/ruby-graphviz'
data/LICENSE.txt CHANGED
@@ -1,5 +1,5 @@
1
1
  Copyright (c) 2006-2012 Aaron Pfeifer
2
- Copyright (c) 2014 Abdelkader Boudih
2
+ Copyright (c) 2014-2025 Abdelkader Boudih
3
3
 
4
4
  MIT License
5
5
 
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/seuros/state_machines-yard/fork )
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 +1,12 @@
1
1
  require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.pattern = 'test/**/*_test.rb'
7
+ t.verbose = true
8
+ t.warning = false
9
+ end
10
+
11
+ desc 'Run tests'
12
+ task default: :test
@@ -1,8 +1,8 @@
1
- module StateMachine
2
- module YARD
1
+ module StateMachines
2
+ module Yard
3
3
  module Handlers
4
4
  # Handles and processes nodes
5
- class Base < ::YARD::Handlers::Ruby::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 [nil, :array].include?(ast.type)
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 StateMachine
2
- module YARD
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
- handler.parse_block(statement.last.last, owner: self)
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 StateMachine
2
- module YARD
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 ::YARD::Handlers::NamespaceMissingError
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?(::YARD::CodeObjects::ClassObject) }
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
- return if inherited_machine
136
-
137
- # Human state name lookup
138
- register(m = ::YARD::CodeObjects::MethodObject.new(namespace, "human_#{machine.attribute(:name)}", :class))
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 = ::YARD::CodeObjects::MethodObject.new(namespace, "human_#{machine.attribute(:event_name)}", :class))
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 = ::YARD::CodeObjects::MethodObject.new(namespace, attribute))
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 = ::YARD::CodeObjects::MethodObject.new(namespace, "#{attribute}="))
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 = ::YARD::CodeObjects::MethodObject.new(namespace, attribute))
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 = ::YARD::CodeObjects::MethodObject.new(namespace, "#{attribute}="))
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 = ::YARD::CodeObjects::MethodObject.new(namespace, "#{machine.name}?"))
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 = ::YARD::CodeObjects::MethodObject.new(namespace, machine.attribute(:name)))
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
- register(m = ::YARD::CodeObjects::MethodObject.new(namespace, "human_#{machine.attribute(:name)}"))
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 = ::YARD::CodeObjects::MethodObject.new(namespace, machine.attribute(:events)))
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 = ::YARD::CodeObjects::MethodObject.new(namespace, machine.attribute(:transitions)))
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 = ::YARD::CodeObjects::MethodObject.new(namespace, machine.attribute(:paths)))
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 = ::YARD::CodeObjects::MethodObject.new(namespace, "fire_#{machine.attribute(:event)}"))
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 = ::YARD::CodeObjects::MethodObject.new(namespace, "can_#{event.qualified_name}?"))
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 (the current state) One or more initial states",
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 = ::YARD::CodeObjects::MethodObject.new(namespace, "#{event.qualified_name}_transition"))
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 (the current state) One or more initial states",
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 = ::YARD::CodeObjects::MethodObject.new(namespace, event.qualified_name))
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 = ::YARD::CodeObjects::MethodObject.new(namespace, "#{event.qualified_name}!"))
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 = ::YARD::CodeObjects::MethodObject.new(namespace, "#{state.qualified_name}?"))
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 StateMachine
2
- module YARD
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
- handler.parse_block(statement.last.last, owner: self)
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 StateMachine
2
- module YARD
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 StateMachine
2
- module YARD
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
@@ -1,5 +1,5 @@
1
1
  module StateMachines
2
2
  module Yard
3
- VERSION = '0.0.1'
3
+ VERSION = '0.1.0'
4
4
  end
5
5
  end
@@ -1,10 +1,15 @@
1
- require 'state_machines/yard/version'
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
- require 'tempfile'
9
- require 'state_machines/yard/handlers'
10
- require 'state_machines/yard/templates'
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'
@@ -1,7 +1,4 @@
1
- # coding: utf-8
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/seuros/state_machines-yard'
10
+ spec.homepage = 'https://github.com/state-machines/state_machines-yard'
14
11
  spec.license = 'MIT'
15
12
 
16
- spec.required_ruby_version = '>= 1.9.3'
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.add_development_dependency 'bundler'
24
- spec.add_development_dependency 'rake'
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