class EndStateMatchers::TransitionMatcher

Attributes

concluders[R]
end_state[R]
event[R]
failure_messages[R]
finalizers[R]
guards[R]
machine[R]
required_params[R]
start_state[R]

Public Class Methods

new(transition) click to toggle source
# File lib/end_state_matchers.rb, line 9
def initialize(transition)
  @start_state, @end_state = transition.first
  @event = nil
  @guards = []
  @concluders = []
  @required_params = []
  @failure_messages = []
end

Public Instance Methods

description() click to toggle source
# File lib/end_state_matchers.rb, line 27
def description
  "have transition #{start_state} => #{end_state}"
end
failure_message() click to toggle source
# File lib/end_state_matchers.rb, line 23
def failure_message
  failure_messages.join("\n")
end
matches?(actual) click to toggle source
# File lib/end_state_matchers.rb, line 18
def matches?(actual)
  @machine = actual
  verify
end
with_concluder(*concluders)
Also aliased as: with_finalizer
Alias for: with_concluders
with_concluders(*concluders) click to toggle source
# File lib/end_state_matchers.rb, line 41
def with_concluders(*concluders)
  @concluders += Array(concluders).flatten
  self
end
Also aliased as: with_concluder, with_finalizers
with_event(event) click to toggle source
# File lib/end_state_matchers.rb, line 31
def with_event(event)
  @event = event
  self
end
with_finalizer(*concluders)

Backward compatibility Finalizer is deprecated

Alias for: with_concluder
with_finalizers(*concluders)
Alias for: with_concluders
with_guard(*guards)
Alias for: with_guards
with_guards(*guards) click to toggle source
# File lib/end_state_matchers.rb, line 36
def with_guards(*guards)
  @guards += Array(guards).flatten
  self
end
Also aliased as: with_guard
with_required_param(*params)
with_required_params(*params) click to toggle source
# File lib/end_state_matchers.rb, line 46
def with_required_params(*params)
  @required_params += Array(params).flatten
  self
end
Also aliased as: with_required_param

Private Instance Methods

add_failure(suffix) click to toggle source
# File lib/end_state_matchers.rb, line 83
def add_failure(suffix)
  failure_messages << "expected transition #{start_state} => #{end_state} #{suffix}"
end
has_concluder?(concluder) click to toggle source
# File lib/end_state_matchers.rb, line 75
def has_concluder?(concluder)
  transition_configuration.concluders.include?(concluder)
end
has_event?(event) click to toggle source
# File lib/end_state_matchers.rb, line 67
def has_event?(event)
  machine.transition_configurations.get_end_state(start_state, event) == end_state
end
has_guard?(guard) click to toggle source
# File lib/end_state_matchers.rb, line 71
def has_guard?(guard)
  transition_configuration.guards.include?(guard)
end
has_required_param?(param) click to toggle source
# File lib/end_state_matchers.rb, line 79
def has_required_param?(param)
  transition_configuration.required_params.include?(param)
end
transition_configuration() click to toggle source
# File lib/end_state_matchers.rb, line 63
def transition_configuration
  @tc = machine.transition_configurations.get_configuration(start_state, end_state)
end
verify() click to toggle source
# File lib/end_state_matchers.rb, line 87
def verify
  if transition_configuration.nil?
    add_failure('to be defined')
  else
    verify_event if event
    verify_guards
    verify_concluders
    verify_required_params
  end

  failure_messages.empty?
end
verify_concluders() click to toggle source
# File lib/end_state_matchers.rb, line 110
def verify_concluders
  concluders.map do |concluder|
    add_failure("to have concluder #{concluder.name}") unless has_concluder?(concluder)
  end
end
verify_event() click to toggle source
# File lib/end_state_matchers.rb, line 100
def verify_event
  add_failure("to have event name: #{event}") unless has_event?(event)
end
verify_guards() click to toggle source
# File lib/end_state_matchers.rb, line 104
def verify_guards
  guards.map do |guard|
    add_failure("to have guard #{guard.name}") unless has_guard?(guard)
  end
end
verify_required_params() click to toggle source
# File lib/end_state_matchers.rb, line 116
def verify_required_params
  required_params.each do |param|
    add_failure("to have required param #{param}") unless has_required_param?(param)
  end
end