class Mocha::StateMachine
An invocation can be constrained to occur when a state {#is}, or {#is_not}, active.
A state machine that is used to constrain the order of invocations.
def become(next_state_name)
-
next_state_name
(String
) -- name of new state
def become(next_state_name) @current_state = next_state_name end
def initialize(name)
- Private: -
def initialize(name) @name = name @current_state = nil end
def is(state_name)
-
(State)
- state which, when activated, will change the {StateMachine} into the state with the specified +desired_state_name+. -
(StatePredicate)
- state predicate which, when queried, will indicate whether the {StateMachine} is in the state specified by +expected_state_name+ -
(StatePredicate, State)
- (a) state predicate which, when queried, will indicate whether the {StateMachine} is in the given state; or (b) state which, when activated, will change the {StateMachine} into the given state.
Parameters:
-
desired_state_name
(String
) -- name of desired new state. -
expected_state_name
(String
) -- name of expected state. -
state_name
(String
) -- name of expected/desired state.
Overloads:
-
def is(desired_state_name)
-
def is(expected_state_name)
def is(state_name) State.new(self, state_name, 'is') { |current, given| current == given } end
def is_not(unexpected_state_name) # rubocop:disable Naming/PredicateName
-
(StatePredicate)
- state predicate which, when queried, will indicate whether the {StateMachine} is *not* in the state specified by +unexpected_state_name+.
Parameters:
-
unexpected_state_name
(String
) -- name of unexpected state.
def is_not(unexpected_state_name) # rubocop:disable Naming/PredicateName StatePredicate.new(self, unexpected_state_name, 'is not') { |current, given| current != given } end
def mocha_inspect
- Private: -
def mocha_inspect %(#{@name} #{@current_state ? "is #{@current_state.mocha_inspect}" : 'has no current state'}) end
def starts_as(initial_state_name)
-
(StateMachine)
- state machine, thereby allowing invocations of other {StateMachine} methods to be chained.
Parameters:
-
initial_state_name
(String
) -- name of initial state
def starts_as(initial_state_name) become(initial_state_name) self end