|
4 | 4 |
|
5 | 5 | require 'simplecov' and SimpleCov.start { add_filter "/test|test_/" } if ENV["COVERAGE"]
|
6 | 6 |
|
| 7 | +# Register `at_exit` handler for integration tests shutdown. |
| 8 | +# MUST be called before requiring `test/unit`. |
| 9 | +at_exit { Elasticsearch::Test::IntegrationTestCase.__run_at_exit_hooks } |
| 10 | + |
7 | 11 | require 'test/unit'
|
8 | 12 | require 'shoulda-context'
|
9 | 13 | require 'mocha/setup'
|
10 |
| -require 'ansi/code' |
11 | 14 | require 'turn' unless ENV["TM_FILEPATH"] || ENV["NOTURN"] || RUBY_1_8
|
12 | 15 |
|
| 16 | +require 'ansi' |
| 17 | +require 'oj' |
| 18 | + |
| 19 | +require 'active_record' |
13 | 20 | require 'active_model'
|
14 | 21 | require 'elasticsearch/model'
|
15 | 22 |
|
| 23 | +require 'elasticsearch/extensions/test/cluster' |
| 24 | +require 'elasticsearch/extensions/test/startup_shutdown' |
| 25 | + |
16 | 26 | module Elasticsearch
|
17 | 27 | module Test
|
18 | 28 | class IntegrationTestCase < ::Test::Unit::TestCase
|
| 29 | + extend Elasticsearch::Extensions::Test::StartupShutdown |
| 30 | + |
| 31 | + startup { Elasticsearch::TestCluster.start if ENV['SERVER'] and not Elasticsearch::TestCluster.running? } |
| 32 | + shutdown { Elasticsearch::Extensions::Test::Cluster.stop if ENV['SERVER'] && started? } |
| 33 | + context "IntegrationTest" do; should "noop on Ruby 1.8" do; end; end if RUBY_1_8 |
| 34 | + |
| 35 | + def setup |
| 36 | + ActiveRecord::Base.establish_connection( :adapter => 'sqlite3', :database => ":memory:" ) |
| 37 | + logger = ::Logger.new(STDERR) |
| 38 | + logger.formatter = lambda { |s, d, p, m| "#{m.ansi(:faint, :cyan)}\n" } |
| 39 | + ActiveRecord::Base.logger = logger unless ENV['QUIET'] |
| 40 | + |
| 41 | + ActiveRecord::LogSubscriber.colorize_logging = false |
| 42 | + ActiveRecord::Migration.verbose = false |
| 43 | + |
| 44 | + tracer = ::Logger.new(STDERR) |
| 45 | + tracer.formatter = lambda { |s, d, p, m| "#{m.gsub(/^.*$/) { |n| ' ' + n }.ansi(:faint)}\n" } |
| 46 | + |
| 47 | + Elasticsearch::Model.client = Elasticsearch::Client.new host: 'localhost:9250', |
| 48 | + tracer: (ENV['QUIET'] ? nil : tracer) |
| 49 | + end |
19 | 50 | end
|
20 | 51 | end
|
21 | 52 | end
|
0 commit comments