state_machines 0.301.1 → 0.301.2

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
2
  SHA256:
3
- metadata.gz: 1fbe5b87d0377b8ca773d88116b21283e73f4001c75eb814a0d76c6206825c39
4
- data.tar.gz: dbd93191206e8be918c6ca0563209c9f29bcbc21082e4150f31c2160c1a0cd1a
3
+ metadata.gz: 4f3fa05a4995ba6d3ff323c8cbf7303a061bf082237353066c01b023129d4c7f
4
+ data.tar.gz: c56a60d5f74f1da251670ff4f5c782d68837a6db2f2f4c200d744adebe620b7f
5
5
  SHA512:
6
- metadata.gz: 5b4403db39c1558e94c178ff79ef99eaf22d9a59834d7f136f06a9f752b57219716ccaf06f43e330230933c53ff8e63668514a9295b9b57042e38a20de4066cb
7
- data.tar.gz: a4e9785c78c2c0046ba15e6d04949eb46cc8112b4b5ccf9194fe971b618b94f534e58cb12099e99217c9cd3bc6d47d1f5f88f9c28af5a0f2ca0c588cf29adeef
6
+ metadata.gz: f6ef8c77f4652d1281e4b66252e0f72395efc2143180b1e91cb437ac7934ca5d9238f3e9b56c5ab3ca7ede1e3a4123fe3ffde899b02f565601b056e7477f0884
7
+ data.tar.gz: 643d203b7719acd77ec70df09bd4c46b722127bf0529e3108285ac5120ea5b0269fe195e09448664cdabcf70a86232a6496ff8f33e8e4943bc64d806b00c28d6
@@ -446,36 +446,31 @@ module StateMachines
446
446
  _sm_assert(correct_final_state, message || default_message)
447
447
  end
448
448
 
449
- # Assert that event execution is immediate (no async delay)
449
+ # Assert that event execution is immediate: the state has changed when the
450
+ # bang event returns, and it returned no async task to wait on. Decided by
451
+ # what the call did, not by how long it took, so a slow runner (a cold
452
+ # JIT) cannot fail it.
450
453
  #
451
454
  # @param object [Object] The object with state machines
452
455
  # @param event [Symbol] The event to trigger
453
456
  # @param machine_name [Symbol] The name of the state machine (defaults to :state)
454
457
  # @param message [String, nil] Custom failure message
455
458
  # @return [void]
456
- # @raise [AssertionError] If execution appears to be async
459
+ # @raise [AssertionError] If the event did not complete synchronously
457
460
  #
458
461
  # @example
459
462
  # car = Car.new
460
463
  # assert_sm_immediate_execution(car, :start)
461
464
  def assert_sm_immediate_execution(object, event, machine_name = :state, message = nil)
462
465
  initial_state = object.send(machine_name)
463
-
464
- # Record start time and execute
465
- start_time = Time.now
466
- object.send("#{event}!")
467
- execution_time = Time.now - start_time
468
-
466
+ result = object.send("#{event}!")
469
467
  final_state = object.send(machine_name)
470
- state_changed = initial_state != final_state
471
-
472
- # Should complete very quickly (under 10ms for sync operations)
473
- is_immediate = execution_time < 0.01
474
468
 
475
- default_message = "Expected immediate sync execution of '#{event}', but took #{execution_time}s (likely async)"
469
+ deferred = defined?(::Async::Task) && result.is_a?(::Async::Task)
470
+ default_message = "Expected immediate sync execution of '#{event}', but it returned #{result.class} (async)"
476
471
 
477
- _sm_assert(state_changed, 'Event should trigger state change')
478
- _sm_assert(is_immediate, message || default_message)
472
+ _sm_assert(initial_state != final_state, message || "Event #{event} should change #{machine_name} before returning")
473
+ _sm_assert(!deferred, message || default_message)
479
474
  end
480
475
 
481
476
  # === Async Mode Assertions ===
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module StateMachines
4
- VERSION = '0.301.1'
4
+ VERSION = '0.301.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: state_machines
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.301.1
4
+ version: 0.301.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih