josephwilk (owner)

Revisions

gist: 27054 Download_button fork
public
Public Clone URL: git://gist.github.com/27054.git
Embed All Files: show embed
bag_of_matcher.rb #
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
require 'set'
 
module BagOfMatchers
 
  class Bag
    def initialize(list)
      @list = Set.new(list)
    end
    
    def matches?(list)
      @compare_list = Set.new(list)
      @list == @compare_list
    end
    
    def failure_message
      "expected #{@list.inspect} to be a bag of #{@compare_list.inspect}, but it is not"
    end
    
    def negative_failure_message
      "expected #{@list.inspect} not to be a bag of #{@compare_list.inspect}, but it is"
    end
  end
    
  def be_bag_of(list)
    Bag.new(list)
  end
  
end