File: order_group.rb

package info (click to toggle)
ruby-rspec-mocks 2.14.5-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 868 kB
  • ctags: 725
  • sloc: ruby: 8,227; makefile: 4
file content (40 lines) | stat: -rw-r--r-- 735 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module RSpec
  module Mocks
    # @private
    class OrderGroup
      def initialize
        @ordering = Array.new
      end

      # @private
      def register(expectation)
        @ordering << expectation
      end

      # @private
      def ready_for?(expectation)
        @ordering.first == expectation
      end

      # @private
      def consume
        @ordering.shift
      end

      # @private
      def handle_order_constraint(expectation)
        return unless @ordering.include?(expectation)
        return consume if ready_for?(expectation)
        expectation.raise_out_of_order_error
      end

      def clear
        @ordering.clear
      end

      def empty?
        @ordering.empty?
      end
    end
  end
end