class Mocha::StateMachine
A state machine that is used to constrain the order of invocations. An invocation can be constrained to occur when a state {#is}, or {#is_not}, active.
Attributes
@private
@private
Public Class Methods
@private
# File lib/mocha/state_machine.rb, line 55 def initialize(name) @name = name @current_state = nil end
Public Instance Methods
Put the {StateMachine} into the next_state_name
.
@param [String] next_state_name name of new state
# File lib/mocha/state_machine.rb, line 72 def become(next_state_name) @current_state = next_state_name end
Provides a mechanism to change the {StateMachine} into the state specified
by state_name
at some point in the future.
Or provides a mechanism to determine whether the {StateMachine} is in the
state specified by state_name
at some point in the future.
@param [String] state_name name of new state @return [State] state which,
when activated, will change the {StateMachine} into the state with the
specified state_name
.
# File lib/mocha/state_machine.rb, line 82 def is(state_name) State.new(self, state_name) end
Provides a mechanism to determine whether the {StateMachine} is not in the
state specified by state_name
at some point in the future.
rubocop:disable Naming/PredicateName
# File lib/mocha/state_machine.rb, line 88 def is_not(state_name) StatePredicate.new(self, state_name) end
@private
# File lib/mocha/state_machine.rb, line 94 def mocha_inspect if @current_state "#{@name} is #{@current_state.mocha_inspect}" else "#{@name} has no current state" end end
Put the {StateMachine} into the state specified by
initial_state_name
.
@param [String] initial_state_name name of initial state @return [StateMachine] state machine, thereby allowing invocations of other {StateMachine} methods to be chained.
# File lib/mocha/state_machine.rb, line 64 def starts_as(initial_state_name) become(initial_state_name) self end