class DB::DriverSpecs(DBAnyType)
- DB::DriverSpecs(DBAnyType)
- Reference
- Object
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.crClass Method Summary
Instance Method Summary
- #after(&after : -> Nil)
- #before(&before : -> Nil)
- #binding_syntax(&binding_syntax : Proc(Int32, String))
- #connection_string(connection_string : String)
- #create_table_1column_syntax(&create_table_1column_syntax : Proc(String, ColumnDef, String))
- #create_table_2columns_syntax(&create_table_2columns_syntax : Proc(String, ColumnDef, ColumnDef, String))
- #drop_table_if_exists_syntax(&drop_table_if_exists_syntax : Proc(String, String))
- #encode_null(encode_null : String)
- #insert_1column_syntax(&insert_1column_syntax : Proc(String, ColumnDef, String, String))
- #insert_2columns_syntax(&insert_2columns_syntax : Proc(String, ColumnDef, String, ColumnDef, String, String))
- #it(description = "assert", prepared = :default, file = __FILE__, line = __LINE__, end_line = __END_LINE__, &block : DB::Database -> )
- #its
-
#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.
- #select_1column_syntax(&select_1column_syntax : Proc(String, ColumnDef, String))
- #select_2columns_syntax(&select_2columns_syntax : Proc(String, ColumnDef, ColumnDef, String))
- #select_count_syntax(&select_count_syntax : Proc(String, String))
- #select_scalar_syntax(&select_scalar_syntax : Proc(String, String | Nil, String))
-
#support_prepared(support_prepared : Bool)
Allow specs that uses prepared statements (default
true
) -
#support_unprepared(support_unprepared : Bool)
Allow specs that uses unprepared statements (default
true
)
Class Method Detail
Instance Method Detail
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
).
Allow specs that uses prepared statements (default true
)
Allow specs that uses unprepared statements (default true
)