Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle deprecation of assert_block safely #24

Merged
merged 1 commit into from
May 27, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions lib/shoulda/context/assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ def assert_accepts(matcher, target, options = {})
end

if matcher.matches?(target)
assert_block { true }
safe_assert_block { true }
if options[:message]
message = matcher.respond_to?(:failure_message_for_should_not) ? matcher.failure_message_for_should_not : matcher.negative_failure_message
assert_match options[:message], message
end
else
message = matcher.respond_to?(:failure_message_for_should) ? matcher.failure_message_for_should : matcher.failure_message
assert_block(message) { false }
safe_assert_block(message) { false }
end
end

Expand All @@ -73,14 +73,22 @@ def assert_rejects(matcher, target, options = {})
not_match = matcher.respond_to?(:does_not_match?) ? matcher.does_not_match?(target) : !matcher.matches?(target)

if not_match
assert_block { true }
safe_assert_block { true }
if options[:message]
message = matcher.respond_to?(:failure_message_for_should) ? matcher.failure_message_for_should : matcher.failure_message
assert_match options[:message], message
end
else
message = matcher.respond_to?(:failure_message_for_should_not) ? matcher.failure_message_for_should_not : matcher.negative_failure_message
assert_block(message) { false }
safe_assert_block(message) { false }
end
end

def safe_assert_block(message = nil, &block)
if respond_to?(:assert_block)
assert_block message, &block
else
assert yield, message
end
end
end
Expand Down