|
| 1 | +require 'rubygems' |
| 2 | + |
| 3 | +require 'bundler' |
| 4 | +Bundler.setup :default, :test |
| 5 | +ENV["DATABASE_URL"] ||= "postgres:///queue_classic_test" |
| 6 | + |
| 7 | +require "minitest/autorun" |
| 8 | + |
| 9 | +class QCTest < Minitest::Test |
| 10 | + |
| 11 | + def setup |
| 12 | + init_db |
| 13 | + QC::Later::Setup.create |
| 14 | + end |
| 15 | + |
| 16 | + def teardown |
| 17 | + QC::Later::Setup.drop |
| 18 | + QC.delete_all |
| 19 | + end |
| 20 | + |
| 21 | + def init_db |
| 22 | + c = QC::ConnAdapter.new |
| 23 | + c.execute("SET client_min_messages TO 'warning'") |
| 24 | + QC::Setup.drop(c.connection) |
| 25 | + QC::Setup.create(c.connection) |
| 26 | + # c.execute(File.read('./test/helper.sql')) |
| 27 | + c.disconnect |
| 28 | + end |
| 29 | + |
| 30 | + def capture_stderr_output |
| 31 | + original_stderr = $stderr |
| 32 | + $stderr = StringIO.new |
| 33 | + yield |
| 34 | + $stderr.string |
| 35 | + ensure |
| 36 | + $stderr = original_stderr |
| 37 | + end |
| 38 | + |
| 39 | + def capture_debug_output |
| 40 | + original_debug = ENV['DEBUG'] |
| 41 | + original_stdout = $stdout |
| 42 | + |
| 43 | + ENV['DEBUG'] = "true" |
| 44 | + $stdout = StringIO.new |
| 45 | + yield |
| 46 | + $stdout.string |
| 47 | + ensure |
| 48 | + ENV['DEBUG'] = original_debug |
| 49 | + $stdout = original_stdout |
| 50 | + end |
| 51 | + |
| 52 | + def with_env(temporary_environment) |
| 53 | + original_environment = {} |
| 54 | + temporary_environment.each do |name, value| |
| 55 | + original_environment[name] = ENV[name] |
| 56 | + ENV[name] = value |
| 57 | + end |
| 58 | + yield |
| 59 | + ensure |
| 60 | + original_environment.each { |name, value| ENV[name] = value } |
| 61 | + end |
| 62 | + |
| 63 | + def execute(s) |
| 64 | + QC.default_conn_adapter.execute(s) |
| 65 | + end |
| 66 | + |
| 67 | + def num_jobs |
| 68 | + execute("SELECT COUNT(*) FROM #{QC::Later::TABLE_NAME}")["count"].to_i |
| 69 | + end |
| 70 | +end |
0 commit comments