Class: Statecraft::RSpec::HaveEdge
- Inherits:
-
Object
- Object
- Statecraft::RSpec::HaveEdge
- Defined in:
- lib/statecraft/rspec/have_edge.rb
Overview
expect(OrderFlow).to have_edge(:pending, :cancelled).via(:cancel)
The class-level shape question of transitions_from: no guards are consulted, exactly like the method itself. via asserts that the named events ride the edge; a bare edge simply has none.
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(from_state, to_state) ⇒ HaveEdge
constructor
A new instance of HaveEdge.
- #matches?(machine_class) ⇒ Boolean
- #via(*event_names) ⇒ Object
Constructor Details
#initialize(from_state, to_state) ⇒ HaveEdge
Returns a new instance of HaveEdge.
11 12 13 14 15 |
# File 'lib/statecraft/rspec/have_edge.rb', line 11 def initialize(from_state, to_state) @from_state = from_state.to_sym @to_state = to_state.to_sym @expected_events = [] end |
Instance Method Details
#description ⇒ Object
45 46 47 |
# File 'lib/statecraft/rspec/have_edge.rb', line 45 def description "have an edge #{@from_state.inspect} -> #{@to_state.inspect}" end |
#failure_message ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/statecraft/rspec/have_edge.rb', line 29 def unless @edge return ["expected #{@machine_class.name} to declare an edge #{@from_state.inspect} -> #{@to_state.inspect}", StateReport.declared_shape(@machine_class, @from_state)].join("\n ") end missing = (@expected_events - @edge[:events]).map(&:inspect).join(", ") "expected the edge #{@from_state.inspect} -> #{@to_state.inspect} to carry #{missing}, " \ "but its events are #{@edge[:events].inspect}" end |
#failure_message_when_negated ⇒ Object
40 41 42 43 |
# File 'lib/statecraft/rspec/have_edge.rb', line 40 def "expected #{@machine_class.name} not to declare the edge #{@from_state.inspect} -> #{@to_state.inspect}, " \ "but it does (events: #{@edge[:events].inspect})" end |
#matches?(machine_class) ⇒ Boolean
22 23 24 25 26 27 |
# File 'lib/statecraft/rspec/have_edge.rb', line 22 def matches?(machine_class) @machine_class = machine_class @edge = machine_class.transitions_from(@from_state) .find { |descriptor| descriptor[:to] == @to_state } @edge && (@expected_events - @edge[:events]).empty? end |
#via(*event_names) ⇒ Object
17 18 19 20 |
# File 'lib/statecraft/rspec/have_edge.rb', line 17 def via(*event_names) @expected_events = event_names.map(&:to_sym) self end |