Sha256: 0644c528e27419ed993bb8557d3ae8c0c6abdcb6258c643896bbc2b08a191428

Contents?: true

Size: 1.67 KB

Versions: 6

Compression:

Stored size: 1.67 KB

Contents

require File.join(File.dirname(__FILE__), "../_lib")

module MoSQL
  class Test::Functional < MoSQL::Test
    attr_reader :sequel, :mongo

    def sql_test_uri
      ENV['MONGOSQL_TEST_SQL'] || 'postgres:///test'
    end
    def mongo_test_uri
      ENV['MONGOSQL_TEST_MONGO'] || 'mongodb://localhost'
    end
    def mongo_test_dbname
      ENV['MONGOSQL_TEST_MONGO_DB'] || 'test'
    end

    def connect_sql
      begin
        conn = Sequel.connect(sql_test_uri)
        conn.test_connection
        conn
      rescue Sequel::DatabaseConnectionError
        $stderr.puts <<EOF

*********************************************************************
Unable to connect to PostgreSQL database at `#{sql_test_uri}'. Either
configure a PostgresSQL database running locally without
authentication with a 'test' database, or set \$MONGOSQL_TEST_SQL in
the environment.
*********************************************************************

EOF
        exit(1)
      end
    end

    def connect_mongo
      begin
        Mongo::Connection.from_uri(mongo_test_uri)
      rescue Mongo::ConnectionFailure, Mongo::ConnectionError
        $stderr.puts <<EOF

*********************************************************************
Unable to connect to MongoDB database at `#{mongo_test_uri}'. Either
configure a MongoDB database running on localhost without
authentication with a 'test' database, or set \$MONGOSQL_TEST_MONGO in
the environment.
*********************************************************************

EOF
        exit(1)
      end
    end

    def mongo_db
      mongo.db(mongo_test_dbname)
    end

    def setup
      @sequel = connect_sql
      @mongo  = connect_mongo
      super
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
mosql-0.3.1 test/functional/_lib.rb
mosql-0.3.0 test/functional/_lib.rb
mosql-0.2.0 test/functional/_lib.rb
mosql-0.1.2 test/functional/_lib.rb
mosql-0.1.1 test/functional/_lib.rb
mosql-0.1.0 test/functional/_lib.rb