aboutsummaryrefslogtreecommitdiffstats
path: root/spec/support/matchers
diff options
context:
space:
mode:
authorCarl Lerche <carllerche@mac.com>2010-03-11 17:08:55 -0800
committerCarl Lerche <carllerche@mac.com>2010-03-11 17:10:40 -0800
commit8db90ba95d4a240fde68127e806162b3e600c383 (patch)
tree9b4ecaeb523e53c1f86cf3cb654e71de945c4e83 /spec/support/matchers
parente3461239adfa972de8f25a2bc6b48b4a8aa62c9c (diff)
downloadrails-8db90ba95d4a240fde68127e806162b3e600c383.tar.gz
rails-8db90ba95d4a240fde68127e806162b3e600c383.tar.bz2
rails-8db90ba95d4a240fde68127e806162b3e600c383.zip
Move all spec support files into spec/support
Diffstat (limited to 'spec/support/matchers')
-rw-r--r--spec/support/matchers/be_like.rb24
-rw-r--r--spec/support/matchers/disambiguate_attributes.rb28
-rw-r--r--spec/support/matchers/hash_the_same_as.rb26
3 files changed, 78 insertions, 0 deletions
diff --git a/spec/support/matchers/be_like.rb b/spec/support/matchers/be_like.rb
new file mode 100644
index 0000000000..c9d4d4b979
--- /dev/null
+++ b/spec/support/matchers/be_like.rb
@@ -0,0 +1,24 @@
+module BeLikeMatcher
+ class BeLike
+ def initialize(expected)
+ @expected = expected
+ end
+
+ def matches?(actual)
+ @actual = actual
+ @expected.gsub(/\s+/, ' ').strip == @actual.gsub(/\s+/, ' ').strip
+ end
+
+ def failure_message
+ "expected\n#{@actual}\nto be like\n#{@expected}"
+ end
+
+ def negative_failure_message
+ "expected\n#{@actual}\nto be unlike\n#{@expected}"
+ end
+ end
+
+ def be_like(expected)
+ BeLike.new(expected)
+ end
+end
diff --git a/spec/support/matchers/disambiguate_attributes.rb b/spec/support/matchers/disambiguate_attributes.rb
new file mode 100644
index 0000000000..bc4a5215d4
--- /dev/null
+++ b/spec/support/matchers/disambiguate_attributes.rb
@@ -0,0 +1,28 @@
+module DisambiguateAttributesMatcher
+ class DisambiguateAttributes
+ def initialize(attributes)
+ @attributes = attributes
+ end
+
+ def matches?(actual)
+ @actual = actual
+ attribute1, attribute2 = @attributes
+ @actual[attribute1].descends_from?(attribute1) &&
+ !@actual[attribute1].descends_from?(attribute2) &&
+ @actual[attribute2].descends_from?(attribute2)
+ end
+
+ def failure_message
+ ""
+ # "expected #{@actual} to disambiguate its attributes"
+ end
+
+ def negative_failure_message
+ "expected #{@actual} to not disambiguate its attributes"
+ end
+ end
+
+ def disambiguate_attributes(*attributes)
+ DisambiguateAttributes.new(attributes)
+ end
+end
diff --git a/spec/support/matchers/hash_the_same_as.rb b/spec/support/matchers/hash_the_same_as.rb
new file mode 100644
index 0000000000..03e955a0cb
--- /dev/null
+++ b/spec/support/matchers/hash_the_same_as.rb
@@ -0,0 +1,26 @@
+module HashTheSameAsMatcher
+ class HashTheSameAs
+ def initialize(expected)
+ @expected = expected
+ end
+
+ def matches?(actual)
+ @actual = actual
+ hash = {}
+ hash[@expected] = :some_arbitrary_value
+ hash[@actual] == :some_arbitrary_value
+ end
+
+ def failure_message
+ "expected #{@actual} to hash the same as #{@expected}; they must be `eql?` and have the same `#hash` value"
+ end
+
+ def negative_failure_message
+ "expected #{@actual} to hash differently than #{@expected}; they must not be `eql?` or have a differing `#hash` values"
+ end
+ end
+
+ def hash_the_same_as(expected)
+ HashTheSameAs.new(expected)
+ end
+end