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