Sha256: 258f894832ea4e7859cd80924e3d6c294ef74823eeb0c6a0b2ba66993e4575e8

Contents?: true

Size: 1.7 KB

Versions: 18

Compression:

Stored size: 1.7 KB

Contents

$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))

Bundler.require :development

# Load shared spec files
Dir["#{File.dirname(__FILE__)}/shared/**/*.rb"].each do |file|
  require file
end

# Require library up front
require 'aptible/cli'

def fmt_time(time)
  time.strftime('%Y-%m-%d %H:%M:%S %z')
end

class SpecRenderer < Aptible::CLI::Renderer::Base
  def initialize
    @nodes = []
  end

  def render(node)
    # For now, we don't support rendering twice, and we probably never need to.
    raise 'Rendered twice!' unless @nodes.empty?
    @nodes << node
    nil
  end

  def text
    Aptible::CLI::Renderer::Text.new.render(@nodes.first)
  end

  def json
    JSON.parse(Aptible::CLI::Renderer::Json.new.render(@nodes.first))
  end

  def text?
    true
  end

  def json?
    true
  end
end

module SpecHarness
  def reset_spec_harness
    @stream = StringIO.new
    @renderer = SpecRenderer.new

    logger = Logger.new(@stream)

    allow(Aptible::CLI).to receive(:logger).and_return(logger)
    allow(Aptible::CLI::Renderer).to receive(:current).and_return(@renderer)
  end

  def captured_output_text
    @renderer.text
  end

  def captured_output_json
    @renderer.json
  end

  def captured_logs
    pos = @stream.pos

    begin
      @stream.rewind
      @stream.read
    ensure
      @stream.pos = pos
    end
  end
end

RSpec.configure do |config|
  config.before(:each) { reset_spec_harness }

  config.include(SpecHarness)

  # We make the CLI believe it's running in a toolbelt context to avoid running
  # the toolbelt nag every time it initializes.
  config.around(:each) do |example|
    ClimateControl.modify(APTIBLE_TOOLBELT: '1') { example.run }
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
aptible-cli-0.24.2 spec/spec_helper.rb
aptible-cli-0.24.1 spec/spec_helper.rb
aptible-cli-0.24.0 spec/spec_helper.rb
aptible-cli-0.23.0 spec/spec_helper.rb
aptible-cli-0.22.0 spec/spec_helper.rb
aptible-cli-0.21.0 spec/spec_helper.rb
aptible-cli-0.20.0 spec/spec_helper.rb
aptible-cli-0.19.9 spec/spec_helper.rb
aptible-cli-0.19.7 spec/spec_helper.rb
aptible-cli-0.19.6 spec/spec_helper.rb
aptible-cli-0.19.4 spec/spec_helper.rb
aptible-cli-0.19.3 spec/spec_helper.rb
aptible-cli-0.19.2 spec/spec_helper.rb
aptible-cli-0.19.1 spec/spec_helper.rb
aptible-cli-0.19.0 spec/spec_helper.rb
aptible-cli-0.18.3 spec/spec_helper.rb
aptible-cli-0.18.2 spec/spec_helper.rb
aptible-cli-0.18.1 spec/spec_helper.rb