class

DB::DriverSpecs(DBAnyType)

Inherits Reference / Object

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.

Class methods

run(description = "as a db", &)
Source

Instance methods

after
Source
before
Source
binding_syntax
Source
connection_string(connection_string : String)
Source
create_table_1column_syntax
Source
create_table_2columns_syntax
Source
drop_table_if_exists_syntax
Source
encode_null(encode_null : String)
Source
insert_1column_syntax
Source
insert_2columns_syntax
Source
it(description = "assert", prepared = :default, file = __FILE__, line = __LINE__, end_line = __END_LINE__, &block : DB::Database -> )
Source
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).

Source
select_1column_syntax
Source
select_2columns_syntax
Source
select_count_syntax
Source
select_scalar_syntax
Source
support_prepared(support_prepared : Bool)

Allow specs that uses prepared statements (default true)

Source
support_unprepared(support_unprepared : Bool)

Allow specs that uses unprepared statements (default true)

Source

Nested types