Sha256: a7692a3ba7deeb3ed3326f6152185f6743c87b30b333cf08a1c42861333eb2fb

Contents?: true

Size: 1.29 KB

Versions: 15

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

require 'spec_helper'
require 'open3'

def wait_for_container(app_name)
  start_time = Time.now
  until `docker-compose ps -q --filter health=healthy #{app_name}`.strip != ''
    elapsed = Time.now - start_time
    raise "Timeout waiting for container #{app_name} to be ready" if elapsed > 10

    $stderr.write '.' if elapsed > 3
    sleep 0.25
  end
end

def run_cmd(*cmd, &failed)
  out, status = Open3.capture2e(*cmd)
  return [ out, status ] if status.success?

  warn <<~WARNING
    Command failed:
    #{cmd}
    <<< Output:
    #{out}
    >>> End of output
  WARNING
  failed&.call
  raise 'Command failed'
end

shared_context 'Rails app pg database' do
  before(:all) do
    raise 'you must set @fixure_dir' unless @fixture_dir

    print_pg_logs = lambda do
      logs, = run_cmd 'docker-compose logs pg'
      puts "docker-compose logs for pg:"
      puts
      puts logs
    end

    Dir.chdir @fixture_dir do 
      run_cmd 'docker-compose down -v'
      cmd = 'docker-compose up -d pg'
      run_cmd cmd
      wait_for_container 'pg'

      cmd = 'docker-compose run --rm app ./create_app'
      run_cmd cmd, &print_pg_logs
    end
  end

  after(:all) do
    if ENV['NOKILL'] != 'true'
      cmd = 'docker-compose down -v'
      run_cmd cmd, chdir: @fixture_dir
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
appmap-0.37.0 spec/rails_spec_helper.rb
appmap-0.36.0 spec/rails_spec_helper.rb
appmap-0.35.2 spec/rails_spec_helper.rb
appmap-0.35.1 spec/rails_spec_helper.rb
appmap-0.35.0 spec/rails_spec_helper.rb
appmap-0.34.5 spec/rails_spec_helper.rb
appmap-0.34.4 spec/rails_spec_helper.rb
appmap-0.34.2 spec/rails_spec_helper.rb
appmap-0.34.1 spec/rails_spec_helper.rb
appmap-0.34.0 spec/rails_spec_helper.rb
appmap-0.33.0 spec/rails_spec_helper.rb
appmap-0.32.0 spec/rails_spec_helper.rb
appmap-0.31.0 spec/rails_spec_helper.rb
appmap-0.28.1 spec/rails_spec_helper.rb
appmap-0.28.0 spec/rails_spec_helper.rb