Skip to content

Commit

Permalink
Assign context to supporting matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
jferris committed Jun 7, 2010
1 parent 08efc47 commit 3fe8331
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/shoulda/assertions.rb
Expand Up @@ -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]
Expand All @@ -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]
Expand Down
12 changes: 12 additions & 0 deletions test/other/helpers_test.rb
Expand Up @@ -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!
Expand Down

0 comments on commit 3fe8331

Please sign in to comment.