Sha256: 98a3d4be88afcbc7e33159b83a046d2cd7517d5ccad89fc06faf23271c3ba5c3

Contents?: true

Size: 964 Bytes

Versions: 6

Compression:

Stored size: 964 Bytes

Contents

require 'matchers/events/matcher'

module StateMachinesRspec
  module Matchers
    def handle_events(value, *values)
      HandleEventMatcher.new(values.unshift(value))
    end
    alias_method :handle_event, :handle_events

    class HandleEventMatcher < StateMachinesRspec::Matchers::Events::Matcher
      def matches_events?(events)
        !invalid_events?
      end

      def description
        message = super
        message << " on #{state_machine_scope.inspect}" if state_machine_scope
        "handle #{message}"
      end

      private

      def invalid_events?
        invalid_events = @introspector.invalid_events(@events)
        unless invalid_events.empty?
          @failure_message = "Expected to be able to handle events: " +
                              "#{invalid_events.join(', ')} in state: " +
                              "#{@introspector.current_state_value}"
        end

        !invalid_events.empty?
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
state_machines-rspec-0.6.0 lib/matchers/events/handle_event.rb
state_machines-rspec-0.5.0 lib/matchers/events/handle_event.rb
state_machines-rspec-0.4.0 lib/matchers/events/handle_event.rb
state_machines_rspec-0.3.2 lib/matchers/events/handle_event.rb
state_machines_rspec-0.3.1 lib/matchers/events/handle_event.rb
state_machines_rspec-0.3.0 lib/matchers/events/handle_event.rb