Sha256: 770909744c6013cd9041596da18c20cdc4c0c03e5ef49fcdf536301fed033109

Contents?: true

Size: 1.59 KB

Versions: 2

Compression:

Stored size: 1.59 KB

Contents

require 'ey_merkin'
require "rest_client"

module Spec
  module Helpers
    def ey(cmd = nil, options = {})
      require "open3"
      hide_err = options.delete(:hide_err)
      ENV['DEBUG'] = options.delete(:debug)

      args = options.map { |k,v| "--#{k} #{v}"}.join(" ")
      eybin = File.expand_path('../bundled_ey', __FILE__)

      @in, @out, @err = Open3.popen3("#{eybin} #{cmd} #{args}")

      yield @in if block_given?
      @err = @err.read_available_bytes
      @out = @out.read_available_bytes
      @ssh_commands = @out.split(/\n/).find_all do |line|
        line =~ /^ssh/
      end.map do |line|
        line.sub(/^.*?\"/, '').sub(/\"$/, '')
      end

      puts @err unless @err.empty? || hide_err
      @out
    end

    def api_scenario(scenario)
      response = ::RestClient.put(EY.fake_awsm + '/scenario', {"scenario" => scenario}, {})
      raise "Setting scenario failed: #{response.inspect}" unless response.code == 200
    end

    def read_yaml(file="ey.yml")
      YAML.load_file(File.expand_path(file))
    end

    def write_yaml(data, file = "ey.yml")
      File.open(file, "w"){|f| YAML.dump(data, f) }
    end
  end
end

module EY
  class << self
    def fake_awsm
      @fake_awsm ||= begin
        unless system("ruby -c spec/support/fake_awsm.ru > /dev/null")
          raise SyntaxError, "There is a syntax error in fake_awsm.ru! fix it!"
        end
        config_ru = File.join(EY_ROOT, "spec/support/fake_awsm.ru")
        @server = EY::Merkin.start_server(config_ru)
        "http://localhost:#{@server.port}"
      end
    end
    alias_method :start_fake_awsm, :fake_awsm
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
engineyard-0.2.11 spec/support/helpers.rb
engineyard-0.2.10 spec/support/helpers.rb