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 +4 -4
- data/lib/state_machines/test_helper.rb +10 -15
- data/lib/state_machines/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4f3fa05a4995ba6d3ff323c8cbf7303a061bf082237353066c01b023129d4c7f
|
|
4
|
+
data.tar.gz: c56a60d5f74f1da251670ff4f5c782d68837a6db2f2f4c200d744adebe620b7f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
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
|
|
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
|
-
|
|
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(
|
|
478
|
-
_sm_assert(
|
|
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 ===
|