Permalink
Browse files

Assign context to supporting matchers

  • Loading branch information...
1 parent 08efc47 commit 3fe83318ca27ec97a4f810ac1ad0ce2784a2ab31 @jferris jferris committed Feb 12, 2010
Showing with 20 additions and 0 deletions.
  1. +8 −0 lib/shoulda/assertions.rb
  2. +12 −0 test/other/helpers_test.rb
@@ -46,6 +46,10 @@ def assert_does_not_contain(collection, x, extra_msg = "")
# Asserts that the given matcher returns true when +target+ is passed to #matches?
def assert_accepts(matcher, target, options = {})
+ if matcher.respond_to?(:in_context)
+ matcher.in_context(self)
+ end
+
if matcher.matches?(target)
assert_block { true }
if options[:message]
@@ -58,6 +62,10 @@ def assert_accepts(matcher, target, options = {})
# Asserts that the given matcher returns false when +target+ is passed to #matches?
def assert_rejects(matcher, target, options = {})
+ if matcher.respond_to?(:in_context)
+ matcher.in_context(self)
+ end
+
unless matcher.matches?(target)
assert_block { true }
if options[:message]
View
@@ -239,6 +239,18 @@ class HelpersTest < ActiveSupport::TestCase # :nodoc:
end
end
+ should "assign context to a support matching on assert_accepts" do
+ matcher = stub('matcher', :matches? => true)
+ matcher.expects(:in_context).with(self)
+ assert_accepts matcher, nil
+ end
+
+ should "assign context to a support matching on assert_rejects" do
+ matcher = stub('matcher', :matches? => false)
+ matcher.expects(:in_context).with(self)
+ assert_rejects matcher, nil
+ end
+
context "given one treat exists and one post exists" do
setup do
Treat.create!

0 comments on commit 3fe8331

Please sign in to comment.