Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Handle deprecation of assert_block safely #24

Merged
merged 1 commit into from

2 participants

@rsl

MiniTest 4.6.0 and higher no longer has assert_block as a method [opting for assert(yield, message)] https://github.com/seattlerb/minitest/blob/master/History.txt#L134-L140

This enables users with older MiniTest to still use assert_block if it's there and the newer format if it's not.

Not sure how to write a test for this as it is a dependency-based issue.

@rmm5t rmm5t merged commit 7a5b224 into from
@rsl

super fast. thanks.

@rmm5t
Admin

Thanks! I merged this in to give you credit for bringing it to our attention, but what's stopping us from just avoiding the assert_block method altogether? Is there a reason we can't just use assert and avoid the safe_assert_block?

@rsl

hrm. i actually didn't think to do that at all. i think in the back of my head assert was modified to take assert_block's place. makes sense that assert out of the box would do that. feel stupid for not having thought of it. ;)

@rsl

i assumed no one used plain assert because it used to not work. so i wanted to make sure those users were supported but yeah... yeah. ;)

@rmm5t
Admin

I tried a quick transition to just using assert but the test suite fails because it expects a different format of failed test output for that assertion. If it's something you're interested in investigating, much appreciated. Otherwise, I'll come back to it at some later date, probably.

@rsl

poking it now.

@rsl

there's a lot of places that can/do define assert there. stdlib's test/unit. rubygem test-unit. minitest. all of which have some differences in versions. looks like it might be bugger trying to unify that in a single call to assert.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 27, 2013
  1. @rsl
This page is out of date. Refresh to see the latest.
Showing with 12 additions and 4 deletions.
  1. +12 −4 lib/shoulda/context/assertions.rb
View
16 lib/shoulda/context/assertions.rb
@@ -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
@@ -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
Something went wrong with that request. Please try again.