Class: Statecraft::RSpec::HaveInitialState

Inherits:
Object
  • Object
show all
Defined in:
lib/statecraft/rspec/have_initial_state.rb

Overview

expect(OrderFlow).to have_initial_state(:pending)

Instance Method Summary collapse

Constructor Details

#initialize(state_name) ⇒ HaveInitialState

Returns a new instance of HaveInitialState.



7
8
9
# File 'lib/statecraft/rspec/have_initial_state.rb', line 7

def initialize(state_name)
  @state_name = state_name.to_sym
end

Instance Method Details

#descriptionObject



25
26
27
# File 'lib/statecraft/rspec/have_initial_state.rb', line 25

def description
  "have the initial state #{@state_name.inspect}"
end

#failure_messageObject



16
17
18
19
# File 'lib/statecraft/rspec/have_initial_state.rb', line 16

def failure_message
  "expected the initial state of #{@machine_class.name} to be #{@state_name.inspect}, " \
    "but it is #{@machine_class.initial_state.inspect}"
end

#failure_message_when_negatedObject



21
22
23
# File 'lib/statecraft/rspec/have_initial_state.rb', line 21

def failure_message_when_negated
  "expected the initial state of #{@machine_class.name} not to be #{@state_name.inspect}, but it is"
end

#matches?(machine_class) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
# File 'lib/statecraft/rspec/have_initial_state.rb', line 11

def matches?(machine_class)
  @machine_class = machine_class
  machine_class.initial_state == @state_name
end