-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Don't hide underlying test failure in ActiveRecord::TestCase#assert_sql #44397
Conversation
Instead of wrapping in |
Yeah, I can definitely simplify this - just the result of staring at this code too long. I'm a bit confused as to the use of |
Yes. |
Ah gotcha - the case I was actually originally having issues wasn't necessarily an expectation failure, just a normal exception. Is there a reason the assertions are stuffed into the def assert_sql(*patterns_to_match, &block)
capture_sql(&block)
failed_patterns = []
patterns_to_match.each do |pattern|
failed_patterns << pattern unless SQLCounter.log_all.any? { |sql| pattern === sql }
end
assert failed_patterns.empty?, "Query pattern(s) #{failed_patterns.map(&:inspect).join(', ')} not found.#{SQLCounter.log.size == 0 ? '' : "\nQueries:\n#{SQLCounter.log.join("\n")}"}"
end |
Yes.
It was likely for the same reason |
Fix: rails#44397 Ref: rails#37313 Ref: rails#42459 This avoid mistakes such as: ```ruby assert_raise Something do assert_queries(1) do raise Something end end ``` Co-Authored-By: Alex Coomans <alexc@squareup.com>
Fixed in #44484. I gave you co-authorship for bringing up the issue. Thanks! |
@byroot Thanks! |
Fix: rails/rails#44397 Ref: rails/rails#37313 Ref: rails/rails#42459 This avoid mistakes such as: ```ruby assert_raise Something do assert_queries(1) do raise Something end end ``` Co-Authored-By: Alex Coomans <alexc@squareup.com>
If a test case raises an error that prevents a query from being executed, the
ensure
block will override that failure which hampers debugging efforts when writing test cases.