Class: Pushdown::SpecHelpers::StateTransitionMatcher
- Inherits:
-
Object
- Object
- Pushdown::SpecHelpers::StateTransitionMatcher
- Extended by:
- Loggability
- Includes:
- RSpec::Matchers
- Defined in:
- lib/pushdown/spec_helpers.rb
Overview
RSpec matcher for matching transitions of Pushdown::States
Constant Summary collapse
- DEFAULT_CALLBACK =
[ :update ]
Instance Attribute Summary collapse
-
#additional_expectations ⇒ Object
readonly
Returns the value of attribute additional_expectations.
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#expected_type ⇒ Object
readonly
Returns the value of attribute expected_type.
-
#failure_description ⇒ Object
readonly
Returns the value of attribute failure_description.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#target_state ⇒ Object
readonly
Returns the value of attribute target_state.
Instance Method Summary collapse
-
#failure_message ⇒ Object
RSpec matcher API – return a message describing an expectation failure.
-
#failure_message_when_negated ⇒ Object
RSpec matcher API – return a message describing an expectation being met when the matcher was used in a negated context.
-
#initialize ⇒ StateTransitionMatcher
constructor
Create a new matcher that expects a transition to occur.
-
#matches?(state) ⇒ Boolean
RSpec matcher API – returns
trueif all expectations are met after calling #update on the specifiedstate. -
#on_an_event(event, *args) ⇒ Object
(also: #on_event)
Specify that the operation that should cause the transition is the #on_event callback.
-
#on_update ⇒ Object
Specify that the operation that should cause the transition is the #update callback.
-
#to_state(state_name) ⇒ Object
(also: #to)
Add an additional expectation that the state that is transitioned to be of the given
state_name. -
#via_transition_type(transition_type) ⇒ Object
(also: #via)
Add an additional expectation that the transition that occurs be of the specified
transition_type.
Constructor Details
#initialize ⇒ StateTransitionMatcher
Create a new matcher that expects a transition to occur.
26 27 28 29 30 31 32 33 34 |
# File 'lib/pushdown/spec_helpers.rb', line 26 def initialize @expected_type = nil @target_state = nil @callback = nil @additional_expectations = [] @state = nil @result = nil @failure_description = nil end |
Instance Attribute Details
#additional_expectations ⇒ Object (readonly)
Returns the value of attribute additional_expectations.
37 38 39 |
# File 'lib/pushdown/spec_helpers.rb', line 37 def additional_expectations @additional_expectations end |
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
37 38 39 |
# File 'lib/pushdown/spec_helpers.rb', line 37 def callback @callback end |
#expected_type ⇒ Object (readonly)
Returns the value of attribute expected_type.
37 38 39 |
# File 'lib/pushdown/spec_helpers.rb', line 37 def expected_type @expected_type end |
#failure_description ⇒ Object (readonly)
Returns the value of attribute failure_description.
37 38 39 |
# File 'lib/pushdown/spec_helpers.rb', line 37 def failure_description @failure_description end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
37 38 39 |
# File 'lib/pushdown/spec_helpers.rb', line 37 def result @result end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
37 38 39 |
# File 'lib/pushdown/spec_helpers.rb', line 37 def state @state end |
#target_state ⇒ Object (readonly)
Returns the value of attribute target_state.
37 38 39 |
# File 'lib/pushdown/spec_helpers.rb', line 37 def target_state @target_state end |
Instance Method Details
#failure_message ⇒ Object
RSpec matcher API – return a message describing an expectation failure.
60 61 62 |
# File 'lib/pushdown/spec_helpers.rb', line 60 def return "%p: %s" % [ self.state, self.describe_failure ] end |
#failure_message_when_negated ⇒ Object
RSpec matcher API – return a message describing an expectation being met when the matcher was used in a negated context.
67 68 69 |
# File 'lib/pushdown/spec_helpers.rb', line 67 def return "%p: %s" % [ self.state, self.describe_negated_failure ] end |
#matches?(state) ⇒ Boolean
RSpec matcher API – returns true if all expectations are met after calling #update on the specified state.
48 49 50 51 52 53 54 55 56 |
# File 'lib/pushdown/spec_helpers.rb', line 48 def matches?( state ) @state = state return self.update_ran_without_error? && self.update_returned_transition? && self.correct_transition_type? && self.correct_target_state? && self.matches_additional_expectations? end |
#on_an_event(event, *args) ⇒ Object Also known as: on_event
Specify that the operation that should cause the transition is the #on_event callback.
106 107 108 109 110 |
# File 'lib/pushdown/spec_helpers.rb', line 106 def on_an_event( event, *args ) raise ScriptError, "can't specify more than one callback" if self.callback @callback = [ :on_event, event, *args ] return self end |
#on_update ⇒ Object
Specify that the operation that should cause the transition is the #update callback. This is the default.
98 99 100 101 102 |
# File 'lib/pushdown/spec_helpers.rb', line 98 def on_update raise ScriptError, "can't specify more than one callback" if self.callback @callback = [ :update ] return self end |
#to_state(state_name) ⇒ Object Also known as: to
Add an additional expectation that the state that is transitioned to be of the given state_name. This only applies to transitions that take a target state type. Expecting a particular state_name in transitions which do not take a state is undefined behavior.
89 90 91 92 |
# File 'lib/pushdown/spec_helpers.rb', line 89 def to_state( state_name ) @target_state = state_name return self end |
#via_transition_type(transition_type) ⇒ Object Also known as: via
Add an additional expectation that the transition that occurs be of the specified transition_type.
78 79 80 81 |
# File 'lib/pushdown/spec_helpers.rb', line 78 def via_transition_type( transition_type ) @expected_type = transition_type return self end |