1 ENV["RAILS_ENV"] = "test"
2 unless ENV["NO_COVERAGE_TEST"]
5 require 'simplecov-rcov'
6 class SimpleCov::Formatter::MergedFormatter
8 SimpleCov::Formatter::HTMLFormatter.new.format(result)
9 SimpleCov::Formatter::RcovFormatter.new.format(result)
12 SimpleCov.formatter = SimpleCov::Formatter::MergedFormatter
15 add_filter 'initializers/secret_token'
18 $stderr.puts "SimpleCov unavailable (#{e}). Proceeding without."
22 require File.expand_path('../../config/environment', __FILE__)
23 require 'rails/test_help'
25 $ARV_API_SERVER_DIR = File.expand_path('../../../../services/api', __FILE__)
26 SERVER_PID_PATH = 'tmp/pids/server.pid'
28 class ActiveSupport::TestCase
29 # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in
32 # Note: You'll currently still have to declare fixtures explicitly
33 # in integration tests -- they do not yet inherit this setting
35 def use_token token_name
36 auth = api_fixture('api_client_authorizations')[token_name.to_s]
37 Thread.current[:arvados_api_token] = auth['api_token']
41 Thread.current[:arvados_api_token] = nil
46 module ApiFixtureLoader
47 def self.included(base)
48 base.extend(ClassMethods)
54 # Returns the data structure from the named API server test fixture.
55 @@api_fixtures[name] ||= \
57 path = File.join($ARV_API_SERVER_DIR, 'test', 'fixtures', "#{name}.yml")
58 YAML.load(IO.read(path))
63 self.class.api_fixture name
67 class ActiveSupport::TestCase
68 include ApiFixtureLoader
69 def session_for api_client_auth_name
71 arvados_api_token: api_fixture('api_client_authorizations')[api_client_auth_name.to_s]['api_token']
76 class ApiServerBackedTestRunner < MiniTest::Unit
78 Bundler.with_clean_env do
79 if not system({'RAILS_ENV' => 'test'}, *cmd)
80 raise RuntimeError, "#{cmd[0]} returned exit code #{$?.exitstatus}"
86 Capybara.javascript_driver = :poltergeist
87 server_pid = Dir.chdir($ARV_API_SERVER_DIR) do |apidir|
88 ENV["NO_COVERAGE_TEST"] = "1"
89 _system('bundle', 'exec', 'rake', 'db:test:load')
90 _system('bundle', 'exec', 'rake', 'db:fixtures:load')
91 _system('bundle', 'exec', 'rails', 'server', '-d')
92 timeout = Time.now.tv_sec + 10
94 while (not good_pid) and (Time.now.tv_sec < timeout)
97 server_pid = IO.read(SERVER_PID_PATH).to_i
98 good_pid = (server_pid > 0) and (Process.kill(0, server_pid) rescue false)
104 raise RuntimeError, "could not find API server Rails pid"
111 Process.kill('TERM', server_pid)
116 MiniTest::Unit.runner = ApiServerBackedTestRunner.new