module Cassie::Testing

This class provides helper methods for testing.

Public Class Methods

cleanup!() { || ... } click to toggle source

Wrap test cases as a block in this method. After the test case finishes, all tables that had data inserted into them will be truncated so that the data state will be clean for the next test case.

# File lib/cassie/testing.rb, line 25
def cleanup!
  yield
ensure
  if Thread.current[:cassie_inserted].present?
    Cassie.instance.batch do
      Thread.current[:cassie_inserted].each do |table|
        keyspace, table = table.split(".", 2)
        schema = Cassie::Schema.find(keyspace)
        schema&.truncate!(table)
      end
    end
    Thread.current[:cassie_inserted] = nil
  end
end
prepare!() click to toggle source

Prepare the test environment. This method must be called before running the test suite.

# File lib/cassie/testing.rb, line 13
def prepare!
  Cassie.send(:include, Cassie::Testing) unless Cassie.include?(Cassie::Testing)
  Cassie::Schema.all.each do |schema|
    schema.tables.each do |table|
      schema.truncate!(table)
    end
  end
end