Skip to content

Instantly share code, notes, and snippets.

@kir
Created October 22, 2011 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kir/1305807 to your computer and use it in GitHub Desktop.
Save kir/1305807 to your computer and use it in GitHub Desktop.
assert_no_database test helper (Rails 3)
module AssertNoDatabase
def assert_no_database
@query_count = 0
@query_sql = []
_subscribe_to_sql
yield
assert_equal 0, @query_count, "Unexpected SQL queries:\n " << @query_sql.join("\n ")
end
def _subscribe_to_sql
@subscribed_to_sql ||= begin
ActiveSupport::Notifications.subscribe(/^sql\./) do |*args|
@query_count += 1
@query_sql << args.last[:sql]
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment