DB::DriverSpecs(DBAnyType)
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", &)
SourceInstance methods
after
Sourcebefore
Sourcebinding_syntax
Sourcecreate_table_1column_syntax
Sourcecreate_table_2columns_syntax
Sourcedrop_table_if_exists_syntax
Sourceinsert_1column_syntax
Sourceinsert_2columns_syntax
Sourceit(description = "assert", prepared = :default, file = __FILE__, line = __LINE__, end_line = __END_LINE__, &block : DB::Database -> )
Sourceits
Sourcesample_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).
select_1column_syntax
Sourceselect_2columns_syntax
Sourceselect_count_syntax
Sourceselect_scalar_syntax
Source