Skip to content

Commit

Permalink
Prepare to make StatePredicate into superclass by passing description
Browse files Browse the repository at this point in the history
  • Loading branch information
nitishr authored and floehopper committed Jan 20, 2020
1 parent fed0eee commit 90b0e61
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions lib/mocha/state_machine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ class StateMachine
# Provides a mechanism to change the state of a {StateMachine} at some point in the future.
class State
# @private
def initialize(state_machine, state)
def initialize(state_machine, state, description)
@state_machine = state_machine
@state = state
@description = description
end

# @private
Expand All @@ -22,16 +23,17 @@ def active?

# @private
def mocha_inspect
"#{@state_machine.name} is #{@state.mocha_inspect}"
"#{@state_machine.name} #{@description} #{@state.mocha_inspect}"
end
end

# Provides the ability to determine whether a {StateMachine} is in a specified state at some point in the future.
class StatePredicate
# @private
def initialize(state_machine, state)
def initialize(state_machine, state, description)
@state_machine = state_machine
@state = state
@description = description
end

# @private
Expand All @@ -41,7 +43,7 @@ def active?

# @private
def mocha_inspect
"#{@state_machine.name} is not #{@state.mocha_inspect}"
"#{@state_machine.name} #{@description} #{@state.mocha_inspect}"
end
end

Expand Down Expand Up @@ -80,13 +82,13 @@ def become(next_state_name)
# @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+.
def is(state_name)
State.new(self, state_name)
State.new(self, state_name, 'is')
end

# 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) # rubocop:disable Naming/PredicateName
StatePredicate.new(self, state_name)
StatePredicate.new(self, state_name, 'is not')
end

# @private
Expand Down

0 comments on commit 90b0e61

Please sign in to comment.