class DB::DriverSpecs(DBAnyType)

Overview

Helper class to ensure behaviour of custom drivers

require "db/spec"

DB::DriverSpecs(DB::Any).run do
  # How to connect to database
  connection_string "scheme://database_url"

  # Clean up database if needed using before/after callbacks
  before do
    # ...
  end

  after do
    # ...
  end

  # Sample values that will be stored, retrieved across many specs
  sample_value "hello", "varchar(25)", "'hello'"

  it "custom spec with a db initialized" do |db|
    # assert something using *db*
  end

  # Configure the appropiate syntax for different commands needed to run the specs
  binding_syntax do |index|
    "?"
  end

  create_table_1column_syntax do |table_name, col1|
    "create table #{table_name} (#{col1.name} #{col1.sql_type} #{col1.null ? "NULL" : "NOT NULL"})"
  end
end

The following methods needs to be called to configure the appropiate syntax for different commands and allow all the specs to run: #binding_syntax, #create_table_1column_syntax, #create_table_2columns_syntax, #select_1column_syntax, #select_2columns_syntax, #select_count_syntax, #select_scalar_syntax, #insert_1column_syntax, #insert_2columns_syntax, #drop_table_if_exists_syntax.

Defined in:

spec.cr

Class Method Summary

Instance Method Summary

Class Method Detail

def self.run(description = "as a db", &) #

[View source]

Instance Method Detail

def after(&after : -> Nil) #

[View source]
def before(&before : -> Nil) #

[View source]
def binding_syntax(&binding_syntax : Proc(Int32, String)) #

[View source]
def connection_string(connection_string : String) #

[View source]
def create_table_1column_syntax(&create_table_1column_syntax : Proc(String, ColumnDef, String)) #

[View source]
def create_table_2columns_syntax(&create_table_2columns_syntax : Proc(String, ColumnDef, ColumnDef, String)) #

[View source]
def drop_table_if_exists_syntax(&drop_table_if_exists_syntax : Proc(String, String)) #

[View source]
def encode_null(encode_null : String) #

[View source]
def insert_1column_syntax(&insert_1column_syntax : Proc(String, ColumnDef, String, String)) #

[View source]
def insert_2columns_syntax(&insert_2columns_syntax : Proc(String, ColumnDef, String, ColumnDef, String, String)) #

[View source]
def it(description = "assert", prepared = :default, file = __FILE__, line = __LINE__, end_line = __END_LINE__, &block : DB::Database -> ) #

[View source]
def its #

[View source]
def sample_value(value, sql_type, value_encoded, *, type_safe_value = true) #

Use value as sample value that should be stored in columns of type sql_type. value_encoded is driver specific expression that should generate that value in the database. type_safe_value indicates whether value_encoded is expected to generate the value even without been stored in a table (default true).


[View source]
def select_1column_syntax(&select_1column_syntax : Proc(String, ColumnDef, String)) #

[View source]
def select_2columns_syntax(&select_2columns_syntax : Proc(String, ColumnDef, ColumnDef, String)) #

[View source]
def select_count_syntax(&select_count_syntax : Proc(String, String)) #

[View source]
def select_scalar_syntax(&select_scalar_syntax : Proc(String, String?, String)) #

[View source]
def support_prepared(support_prepared : Bool) #

Allow specs that uses prepared statements (default true)


[View source]
def support_unprepared(support_unprepared : Bool) #

Allow specs that uses unprepared statements (default true)


[View source]