Sha256: f5491a3025c4e76494048588db57ff21f2830f51240e3d7cc3cd5cf80d9c715b

Contents?: true

Size: 1.64 KB

Versions: 6

Compression:

Stored size: 1.64 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'

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

6 entries across 6 versions & 1 rubygems

Version Path
aptible-cli-0.18.0 spec/spec_helper.rb
aptible-cli-0.17.2 spec/spec_helper.rb
aptible-cli-0.17.1 spec/spec_helper.rb
aptible-cli-0.17.0 spec/spec_helper.rb
aptible-cli-0.16.9 spec/spec_helper.rb
aptible-cli-0.16.8 spec/spec_helper.rb