public
Fork of dchelimsky/rspec
Description: Behaviour Driven Development framework for Ruby
Homepage: http://rspec.info
Clone URL: git://github.com/pat-maddox/rspec.git
rspec / lib / spec / matchers / unordered.rb
100644 33 lines (26 sloc) 0.556 kb
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
module Spec
  module Matchers
 
    class Bag
      def initialize(*items)
        @items = items
      end
 
      def ==(array)
        (@items && array).size == @items.size
      end
 
      def inspect
        @items.inspect
      end
    end
 
    def unordered(*args)
      Bag.new(*args)
    end
 
    def self.included(klass)
      Array.class_eval do
        old_equality = instance_method(:==)
 
        define_method(:==) do |other|
          other.is_a?(Bag) ? (other == self) : old_equality.bind(self)[other]
        end
      end
    end
  end
end