aboutsummaryrefslogblamecommitdiffstats
path: root/spec/support/matchers/have_rows.rb
blob: e476d25f4fa0fe57052d8885ee7dce573dfd9ca3 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
















                                                                                      
   
module Matchers
  def have_rows(expected)
    simple_matcher "have rows" do |given, matcher|
      found, got, expected = [], [], expected.map { |r| r.tuple }
      given.each do |row|
        got << row.tuple
        found << expected.find { |r| row.tuple == r }
      end

      matcher.failure_message = "Expected to get:\n" \
        "#{expected.map {|r| "  #{r.inspect}" }.join("\n")}\n" \
        "instead, got:\n" \
        "#{got.map {|r| "  #{r.inspect}" }.join("\n")}"

      found.compact.length == expected.length && got.compact.length == expected.length
    end
  end
end