From 3ab6ae0c601d1b4459efd8bb39650fee370aa5b8 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Fri, 12 Mar 2010 16:38:36 -0800 Subject: Organize the matchers a bit more --- spec/support/matchers.rb | 3 ++- spec/support/matchers/be_like.rb | 2 +- spec/support/matchers/disambiguate_attributes.rb | 2 +- spec/support/matchers/hash_the_same_as.rb | 2 +- spec/support/matchers/have_rows.rb | 18 ++++++++++++++++++ 5 files changed, 23 insertions(+), 4 deletions(-) create mode 100644 spec/support/matchers/have_rows.rb (limited to 'spec/support') diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb index 6f50d6cbc7..8cef5d947e 100644 --- a/spec/support/matchers.rb +++ b/spec/support/matchers.rb @@ -1,3 +1,4 @@ require "support/matchers/be_like" require "support/matchers/disambiguate_attributes" -require "support/matchers/hash_the_same_as" \ No newline at end of file +require "support/matchers/hash_the_same_as" +require "support/matchers/have_rows" \ No newline at end of file diff --git a/spec/support/matchers/be_like.rb b/spec/support/matchers/be_like.rb index c9d4d4b979..0608abbbb4 100644 --- a/spec/support/matchers/be_like.rb +++ b/spec/support/matchers/be_like.rb @@ -1,4 +1,4 @@ -module BeLikeMatcher +module Matchers class BeLike def initialize(expected) @expected = expected diff --git a/spec/support/matchers/disambiguate_attributes.rb b/spec/support/matchers/disambiguate_attributes.rb index bc4a5215d4..cec5924ca1 100644 --- a/spec/support/matchers/disambiguate_attributes.rb +++ b/spec/support/matchers/disambiguate_attributes.rb @@ -1,4 +1,4 @@ -module DisambiguateAttributesMatcher +module Matchers class DisambiguateAttributes def initialize(attributes) @attributes = attributes diff --git a/spec/support/matchers/hash_the_same_as.rb b/spec/support/matchers/hash_the_same_as.rb index 03e955a0cb..ed00d37f28 100644 --- a/spec/support/matchers/hash_the_same_as.rb +++ b/spec/support/matchers/hash_the_same_as.rb @@ -1,4 +1,4 @@ -module HashTheSameAsMatcher +module Matchers class HashTheSameAs def initialize(expected) @expected = expected diff --git a/spec/support/matchers/have_rows.rb b/spec/support/matchers/have_rows.rb new file mode 100644 index 0000000000..7d9c6a20c9 --- /dev/null +++ b/spec/support/matchers/have_rows.rb @@ -0,0 +1,18 @@ +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 \ No newline at end of file -- cgit v1.2.3