Class: Statecraft::RSpec::AllowTransitionTo
- Inherits:
-
Object
- Object
- Statecraft::RSpec::AllowTransitionTo
- Defined in:
- lib/statecraft/rspec/allow_transition_to.rb
Overview
expect(record).to allow_transition_to(:paid).via(:pay) expect(record).to allow_transition_to(:archived).directly
The available_transitions prediction for one target: not only whether the record can go there, but HOW — via lists the events whose guards pass, directly asserts the guard-free direct way.
Instance Method Summary collapse
- #description ⇒ Object
- #directly ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize(target_state) ⇒ AllowTransitionTo
constructor
A new instance of AllowTransitionTo.
- #matches?(record) ⇒ Boolean
- #via(*event_names) ⇒ Object
- #with_metadata(metadata) ⇒ Object
Constructor Details
#initialize(target_state) ⇒ AllowTransitionTo
Returns a new instance of AllowTransitionTo.
12 13 14 15 16 17 |
# File 'lib/statecraft/rspec/allow_transition_to.rb', line 12 def initialize(target_state) @target_state = target_state.to_sym @expected_via = [] @directly = false @metadata = {} end |
Instance Method Details
#description ⇒ Object
59 60 61 |
# File 'lib/statecraft/rspec/allow_transition_to.rb', line 59 def description "allow a transition to #{@target_state.inspect}" end |
#directly ⇒ Object
24 25 26 27 |
# File 'lib/statecraft/rspec/allow_transition_to.rb', line 24 def directly @directly = true self end |
#failure_message ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/statecraft/rspec/allow_transition_to.rb', line 43 def unless @availability return ["expected #{StateReport.standing(@record)} to reach #{@target_state.inspect}, but it cannot", StateReport.reachable(@record, @metadata), StateReport.declared_shape_of(@record)].join("\n ") end "expected the way to #{@target_state.inspect} to include #{missing_ways.map(&:inspect).join(", ")}, " \ "but it is reachable via #{@availability.via.inspect}" end |
#failure_message_when_negated ⇒ Object
54 55 56 57 |
# File 'lib/statecraft/rspec/allow_transition_to.rb', line 54 def "expected #{StateReport.standing(@record)} not to reach #{@target_state.inspect}, " \ "but it is reachable via #{@availability.via.inspect}" end |
#matches?(record) ⇒ Boolean
34 35 36 37 38 39 40 41 |
# File 'lib/statecraft/rspec/allow_transition_to.rb', line 34 def matches?(record) @record = record @availability = record.available_transitions(metadata: @metadata) .find { |availability| availability.to == @target_state } return false unless @availability missing_ways.empty? end |
#via(*event_names) ⇒ Object
19 20 21 22 |
# File 'lib/statecraft/rspec/allow_transition_to.rb', line 19 def via(*event_names) @expected_via = event_names.map(&:to_sym) self end |
#with_metadata(metadata) ⇒ Object
29 30 31 32 |
# File 'lib/statecraft/rspec/allow_transition_to.rb', line 29 def () @metadata = self end |