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)

Parameters:
  • next_state_name (String) -- name of new state
def become(next_state_name)
  @current_state = next_state_name
end

def initialize(name)

Other tags:
    Private: -
def initialize(name)
  @name = name
  @current_state = nil
end

def is(state_name)

Returns:
  • (State) - state which, when activated, will change the {StateMachine} into the state with the specified +state_name+.

Parameters:
  • state_name (String) -- name of new state
def is(state_name)
  State.new(self, state_name)
end

def is_not(state_name)

Provides a mechanism to determine whether the {StateMachine} is not in the state specified by +state_name+ at some point in the future.
def is_not(state_name)
  StatePredicate.new(self, state_name)
end

def mocha_inspect

Other tags:
    Private: -
def mocha_inspect
  if @current_state
    "#{@name} is #{@current_state.mocha_inspect}"
  else
    "#{@name} has no current state"
  end
end

def starts_as(initial_state_name)

Returns:
  • (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