Class: StateMachinesRspec::Matchers::Events::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/matchers/events/matcher.rb

Direct Known Subclasses

HandleEventMatcher, RejectEventMatcher

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(events) ⇒ Matcher

Returns a new instance of Matcher.



9
10
11
12
# File 'lib/matchers/events/matcher.rb', line 9

def initialize(events)
  @options = events.extract_options!
  @events = events
end

Instance Attribute Details

#failure_messageObject (readonly)

Returns the value of attribute failure_message.



7
8
9
# File 'lib/matchers/events/matcher.rb', line 7

def failure_message
  @failure_message
end

Instance Method Details

#descriptionObject



29
30
31
32
33
# File 'lib/matchers/events/matcher.rb', line 29

def description
  message = @events.map{ |event| event.inspect }.join(', ')
  message << " when #{state_name.inspect}" if state_name
  message
end

#matches?(subject) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
# File 'lib/matchers/events/matcher.rb', line 14

def matches?(subject)
  @subject = subject
  @introspector = StateMachinesIntrospector.new(@subject,
                                               @options.fetch(:on, nil))
  enter_when_state
  return false if undefined_events?
  return false unless matches_events?(@events)
  @failure_message.nil?
end

#matches_events?(events) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


24
25
26
27
# File 'lib/matchers/events/matcher.rb', line 24

def matches_events?(events)
  raise NotImplementedError,
    "subclasses of #{self.class} must override matches_events?"
end