Skip to content

Commit

Permalink
Allow specs to run against a different database host
Browse files Browse the repository at this point in the history
  • Loading branch information
bcardiff committed Feb 5, 2018
1 parent d7a0900 commit 4fb35a7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ before_install:
- while ! echo exit | nc localhost 3306; do sleep 5; done # wait mysql to start accepting connections
- sleep 15
script:
- crystal spec
- DATABASE_HOST=localhost crystal spec
- crystal tool format --check
6 changes: 3 additions & 3 deletions spec/driver_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe Driver do
it "should connect with credentials" do
with_db do |db|
db.scalar("SELECT DATABASE()").should be_nil
db.scalar("SELECT CURRENT_USER()").should match(/^root@(localhost|%)$/)
db.scalar("SELECT CURRENT_USER()").should match(/^root@/)

# ensure user is deleted
db.exec "GRANT USAGE ON *.* TO crystal_test IDENTIFIED BY 'secret'"
Expand All @@ -27,9 +27,9 @@ describe Driver do
db.exec "FLUSH PRIVILEGES"
end

DB.open "mysql://crystal_test:secret@localhost/crystal_mysql_test" do |db|
DB.open "mysql://crystal_test:secret@#{database_host}/crystal_mysql_test" do |db|
db.scalar("SELECT DATABASE()").should eq("crystal_mysql_test")
db.scalar("SELECT CURRENT_USER()").should match(/^crystal_test@(localhost|%)$/)
db.scalar("SELECT CURRENT_USER()").should match(/^crystal_test@/)
end

with_db do |db|
Expand Down
6 changes: 5 additions & 1 deletion spec/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ require "../src/mysql"
include MySql

def db_url(initial_db = nil)
"mysql://root@localhost/#{initial_db}"
"mysql://root@#{database_host}/#{initial_db}"
end

def database_host
ENV.fetch("DATABASE_HOST", "localhost")
end

0 comments on commit 4fb35a7

Please sign in to comment.