Add spec for DB.connect

Update to crystal-db ~> 0.4.0
This commit is contained in:
Brian J. Cardiff 2017-03-07 16:52:31 -03:00
parent bbed6256a6
commit b43a12fc92
4 changed files with 21 additions and 3 deletions

View file

@ -57,4 +57,15 @@ describe Connection do
end
end
end
it "opens a connection without the pool" do
with_cnn do |cnn|
cnn.should be_a(SQLite3::Connection)
cnn.exec "create table person (name string, age integer)"
cnn.exec "insert into person values (\"foo\", 10)"
cnn.scalar("select count(*) from person").should eq(1)
end
end
end

View file

@ -12,6 +12,13 @@ ensure
File.delete(DB_FILENAME)
end
def with_cnn(&block : DB::Connection ->)
File.delete(DB_FILENAME) rescue nil
DB.connect "sqlite3:#{DB_FILENAME}", &block
ensure
File.delete(DB_FILENAME)
end
def with_db(name, &block : DB::Database ->)
File.delete(name) rescue nil
DB.open "sqlite3:#{name}", &block