Change connection setup for tests.

Change connection setup for tests.

Remove extra setup in builder_test.rb which makes a pg connection.

Make two new methods pg_connection and sqlite3_connection to consolidate that common logic and make way for JRuby support which will be able to make similar but different connection implementation(s).

diff --git a/test/mini_sql/builder_tests.rb b/test/mini_sql/builder_tests.rb
index 8a18535..3c09e49 100644
--- a/test/mini_sql/builder_tests.rb
+++ b/test/mini_sql/builder_tests.rb
@@ -1,9 +1,4 @@
 module MiniSql::BuilderTests
-  def setup
-    pg_conn = PG.connect(dbname: 'test_mini_sql')
-    @connection = MiniSql::Connection.get(pg_conn)
-  end
-
   def test_where
     builder = @connection.build("select 1 as one /*where*/")
     builder.where("1 = :zero")
diff --git a/test/mini_sql/inline_param_encoder_test.rb b/test/mini_sql/inline_param_encoder_test.rb
index 526aefb..dd872ea 100644
--- a/test/mini_sql/inline_param_encoder_test.rb
+++ b/test/mini_sql/inline_param_encoder_test.rb
@@ -4,8 +4,7 @@ module MiniSql
   class TestInlineParamEncoder < MiniTest::Test
 
     def setup
-      pg_conn = PG.connect(dbname: 'test_mini_sql')
-      @connection = MiniSql::Connection.get(pg_conn)
+      @connection = pg_connection
       @encoder = InlineParamEncoder.new(@connection)
     end
 
diff --git a/test/mini_sql/postgres/builder_test.rb b/test/mini_sql/postgres/builder_test.rb
index 3939e2a..9e963af 100644
--- a/test/mini_sql/postgres/builder_test.rb
+++ b/test/mini_sql/postgres/builder_test.rb
@@ -2,8 +2,7 @@ require 'test_helper'
 
 class MiniSql::Postgres::TestBuilder < MiniTest::Test
   def setup
-    pg_conn = PG.connect(dbname: 'test_mini_sql')
-    @connection = MiniSql::Connection.get(pg_conn)
+    @connection = pg_connection
   end
 
   include MiniSql::BuilderTests
diff --git a/test/mini_sql/postgres/connection_test.rb b/test/mini_sql/postgres/connection_test.rb
index 779c3d1..0d0c1e8 100644
--- a/test/mini_sql/postgres/connection_test.rb
+++ b/test/mini_sql/postgres/connection_test.rb
@@ -2,8 +2,7 @@ require 'test_helper'
 
 class MiniSql::Postgres::TestConnection < MiniTest::Test
   def setup
-    pg_conn = PG.connect(dbname: 'test_mini_sql')
-    @connection = MiniSql::Connection.get(pg_conn)
+    @connection = pg_connection
   end
 
   include MiniSql::ConnectionTests
diff --git a/test/mini_sql/sqlite/builder_test.rb b/test/mini_sql/sqlite/builder_test.rb
index 6197017..3222677 100644
--- a/test/mini_sql/sqlite/builder_test.rb
+++ b/test/mini_sql/sqlite/builder_test.rb
@@ -2,8 +2,7 @@ require 'test_helper'
 
 class MiniSql::Sqlite::TestBuilder < MiniTest::Test
   def setup
-    @sqlite_conn = SQLite3::Database.new(':memory:')
-    @connection = MiniSql::Connection.get(@sqlite_conn)
+    @connection = sqlite3_connection
   end
 
   include MiniSql::BuilderTests
diff --git a/test/mini_sql/sqlite/connection_test.rb b/test/mini_sql/sqlite/connection_test.rb
index 488a7fc..efa1be5 100644
--- a/test/mini_sql/sqlite/connection_test.rb
+++ b/test/mini_sql/sqlite/connection_test.rb
@@ -3,8 +3,7 @@ require 'tempfile'
 
 class MiniSql::Sqlite::TestConnection < MiniTest::Test
   def setup
-    @sqlite_conn = SQLite3::Database.new(':memory:')
-    @connection = MiniSql::Connection.get(@sqlite_conn)
+    @connection = sqlite3_connection
   end
 
   include MiniSql::ConnectionTests
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 39238d0..ea634d5 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -8,5 +8,15 @@ require "pg"
 require "sqlite3"
 require "time"
 
+def pg_connection
+   pg_conn = PG.connect(dbname: 'test_mini_sql')
+   MiniSql::Connection.get(pg_conn)
+end
+
+def sqlite3_connection
+   @sqlite_conn = SQLite3::Database.new(':memory:')
+   MiniSql::Connection.get(@sqlite_conn)
+end
+
 require_relative "mini_sql/connection_tests"
 require_relative "mini_sql/builder_tests"

GitHub sha: 68c157e2