diff options
author | Gabe da Silveira <gabe@websaviour.com> | 2008-06-03 17:50:42 -0300 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2008-07-14 23:22:39 +0100 |
commit | cd9b24286a90111a08002e0da753198c5fb2432a (patch) | |
tree | 3edbdc4ddfaa8ea9ba5819e1a31afcd4f3b5ab1f /activerecord/lib | |
parent | 2d6562d51b96af518c1eb2947d6d34d5dd5bad12 (diff) | |
download | rails-cd9b24286a90111a08002e0da753198c5fb2432a.tar.gz rails-cd9b24286a90111a08002e0da753198c5fb2432a.tar.bz2 rails-cd9b24286a90111a08002e0da753198c5fb2432a.zip |
Add assert_sql helper method to check for specific SQL output in Active Record test suite. [#325 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/test_case.rb | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/test_case.rb b/activerecord/lib/active_record/test_case.rb index 7dee962c8a..ca5591ae35 100644 --- a/activerecord/lib/active_record/test_case.rb +++ b/activerecord/lib/active_record/test_case.rb @@ -22,11 +22,22 @@ module ActiveRecord end end + def assert_sql(*patterns_to_match) + $queries_executed = [] + yield + ensure + failed_patterns = [] + patterns_to_match.each do |pattern| + failed_patterns << pattern unless $queries_executed.any?{ |sql| pattern === sql } + end + assert failed_patterns.empty?, "Query pattern(s) #{failed_patterns.map(&:inspect).join(', ')} not found." + end + def assert_queries(num = 1) - $query_count = 0 + $queries_executed = [] yield ensure - assert_equal num, $query_count, "#{$query_count} instead of #{num} queries were executed." + assert_equal num, $queries_executed.size, "#{$queries_executed.size} instead of #{num} queries were executed." end def assert_no_queries(&block) |