Class: Mocha::StateMachine

### Home Classes Methods

### In Files

- lib/mocha/state_machine.rb

### Parent

Object

### Namespace

- CLASS Mocha::StateMachine::State
- CLASS Mocha::StateMachine::StatePredicate

### Methods

- ::new
- #become
- #is
- #is_not
- #mocha_inspect
- #starts_as

### Class/Module Index

Quicksearch

- Mocha
- Mocha::API
- Mocha::AnyInstanceMethod
- Mocha::AnyInstanceReceiver
- Mocha::ArgumentIterator
- Mocha::ArrayMethods
- Mocha::BacktraceFilter
- Mocha::Cardinality
- Mocha::Central
- Mocha::ChangeStateSideEffect
- Mocha::ClassMethod
- Mocha::ClassMethods
- Mocha::ClassMethods::AnyInstance
- Mocha::Configuration
- Mocha::DateMethods
- Mocha::Debug
- Mocha::DefaultName
- Mocha::DefaultReceiver
- Mocha::Deprecation
- Mocha::Detection
- Mocha::Detection::MiniTest
- Mocha::Detection::TestUnit
- Mocha::ExceptionRaiser
- Mocha::Expectation
- Mocha::ExpectationError
- Mocha::ExpectationErrorFactory
- Mocha::ExpectationList
- Mocha::HashMethods
- Mocha::Hooks
- Mocha::ImpersonatingAnyInstanceName
- Mocha::ImpersonatingName
- Mocha::InStateOrderingConstraint
- Mocha::InstanceMethod
- Mocha::Integration
- Mocha::Integration::AssertionCounter
- Mocha::Integration::MiniTest
- Mocha::Integration::MiniTest::Adapter
- Mocha::Integration::MiniTest::Nothing
- Mocha::Integration::MiniTest::Version13
- Mocha::Integration::MiniTest::Version13::RunMethodPatch
- Mocha::Integration::MiniTest::Version140
- Mocha::Integration::MiniTest::Version140::RunMethodPatch
- Mocha::Integration::MiniTest::Version141
- Mocha::Integration::MiniTest::Version141::RunMethodPatch
- Mocha::Integration::MiniTest::Version142To172
- Mocha::Integration::MiniTest::Version142To172::RunMethodPatch
- Mocha::Integration::MiniTest::Version200
- Mocha::Integration::MiniTest::Version200::RunMethodPatch
- Mocha::Integration::MiniTest::Version201To222
- Mocha::Integration::MiniTest::Version201To222::RunMethodPatch
- Mocha::Integration::MiniTest::Version2110To2111
- Mocha::Integration::MiniTest::Version2110To2111::RunMethodPatch
- Mocha::Integration::MiniTest::Version2112To320
- Mocha::Integration::MiniTest::Version2112To320::RunMethodPatch
- Mocha::Integration::MiniTest::Version230To2101
- Mocha::Integration::MiniTest::Version230To2101::RunMethodPatch
- Mocha::Integration::MonkeyPatcher
- Mocha::Integration::TestUnit
- Mocha::Integration::TestUnit::Adapter
- Mocha::Integration::TestUnit::GemVersion200
- Mocha::Integration::TestUnit::GemVersion200::RunMethodPatch
- Mocha::Integration::TestUnit::GemVersion201To202
- Mocha::Integration::TestUnit::GemVersion201To202::RunMethodPatch
- Mocha::Integration::TestUnit::GemVersion203To220
- Mocha::Integration::TestUnit::GemVersion203To220::RunMethodPatch
- Mocha::Integration::TestUnit::GemVersion230To250
- Mocha::Integration::TestUnit::GemVersion230To250::RunMethodPatch
- Mocha::Integration::TestUnit::Nothing
- Mocha::Integration::TestUnit::RubyVersion185AndBelow
- Mocha::Integration::TestUnit::RubyVersion185AndBelow::RunMethodPatch
- Mocha::Integration::TestUnit::RubyVersion186AndAbove
- Mocha::Integration::TestUnit::RubyVersion186AndAbove::RunMethodPatch
- Mocha::Logger
- Mocha::MethodMatcher
- Mocha::Mock
- Mocha::Mockery
- Mocha::ModuleMethod
- Mocha::ModuleMethods
- Mocha::MultipleYields
- Mocha::Name
- Mocha::NoYields
- Mocha::ObjectMethods
- Mocha::ObjectReceiver
- Mocha::ParameterMatchers
- Mocha::ParameterMatchers::AllOf
- Mocha::ParameterMatchers::AnyOf
- Mocha::ParameterMatchers::AnyParameters
- Mocha::ParameterMatchers::Anything
- Mocha::ParameterMatchers::Base
- Mocha::ParameterMatchers::Equals
- Mocha::ParameterMatchers::HasEntries
- Mocha::ParameterMatchers::HasEntry
- Mocha::ParameterMatchers::HasKey
- Mocha::ParameterMatchers::HasValue
- Mocha::ParameterMatchers::Includes
- Mocha::ParameterMatchers::InstanceOf
- Mocha::ParameterMatchers::IsA
- Mocha::ParameterMatchers::KindOf
- Mocha::ParameterMatchers::Not
- Mocha::ParameterMatchers::Optionally
- Mocha::ParameterMatchers::QueryStringMatches
- Mocha::ParameterMatchers::RegexpMatches
- Mocha::ParameterMatchers::RespondsWith
- Mocha::ParameterMatchers::YamlEquivalent
- Mocha::ParametersMatcher
- Mocha::PrettyParameters
- Mocha::ReturnValues
- Mocha::Sequence
- Mocha::Sequence::InSequenceOrderingConstraint
- Mocha::SingleReturnValue
- Mocha::SingleYield
- Mocha::StateMachine
- Mocha::StateMachine::State
- Mocha::StateMachine::StatePredicate
- Mocha::StringMethods
- Mocha::StubbingError
- Mocha::Thrower
- Mocha::TimeMethods
- Mocha::UnexpectedInvocation
- Mocha::YieldParameters
- Array
- Date
- Hash
- Object
- String
- Time

No matching classes.

# 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

current_state[RW]

@private

name[R]

@private

### Public Class Methods

new(name) click to toggle source

@private

    # File lib/mocha/state_machine.rb, line 59
    def initialize(name)
      @name = name
      @current_state = nil
    end

### Public Instance Methods

become(next_state_name) click to toggle source

Put the {StateMachine} into the `next_state_name`.

@param [String] next_state_name name of new state

    # File lib/mocha/state_machine.rb, line 76
    def become(next_state_name)
      @current_state = next_state_name
    end

is(state_name) click to toggle source

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 86
    def is(state_name)
      State.new(self, state_name)
    end

is_not(state_name) click to toggle source

Provides a mechanism to determine whether the {StateMachine} is not in the state specified by `state_name` at some point in the future.

    # File lib/mocha/state_machine.rb, line 91
    def is_not(state_name)
      StatePredicate.new(self, state_name)
    end

mocha_inspect() click to toggle source

@private

    # File lib/mocha/state_machine.rb, line 96
    def mocha_inspect
      if @current_state
        "#{@name} is #{@current_state.mocha_inspect}"
      else
        "#{@name} has no current state"
      end
    end

starts_as(initial_state_name) click to toggle source

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 68
    def starts_as(initial_state_name)
      become(initial_state_name)
      self
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.