aboutsummaryrefslogtreecommitdiffstats
path: root/spec/support
diff options
context:
space:
mode:
authorCarl Lerche <carllerche@mac.com>2010-03-12 16:38:36 -0800
committerCarl Lerche <carllerche@mac.com>2010-03-12 16:38:36 -0800
commit3ab6ae0c601d1b4459efd8bb39650fee370aa5b8 (patch)
tree7ec7bb6ab71094cca2b61190728efb2e0c2e1497 /spec/support
parent0e6888232a19c8c59416490d3da6079e590fab77 (diff)
downloadrails-3ab6ae0c601d1b4459efd8bb39650fee370aa5b8.tar.gz
rails-3ab6ae0c601d1b4459efd8bb39650fee370aa5b8.tar.bz2
rails-3ab6ae0c601d1b4459efd8bb39650fee370aa5b8.zip
Organize the matchers a bit more
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/matchers.rb3
-rw-r--r--spec/support/matchers/be_like.rb2
-rw-r--r--spec/support/matchers/disambiguate_attributes.rb2
-rw-r--r--spec/support/matchers/hash_the_same_as.rb2
-rw-r--r--spec/support/matchers/have_rows.rb18
5 files changed, 23 insertions, 4 deletions
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