Sha256: 4996a5f19e645f3e7e277c603599f94792cd0110a23d0bb4792e7b0d9d66aa17

Contents?: true

Size: 1.35 KB

Versions: 2

Compression:

Stored size: 1.35 KB

Contents

# Loading serverspec first causes a weird error - stack level too deep
# Requiring rspec first fixes that *shrug*
require 'rspec'
require 'serverspec'

module AmiSpec
  class ServerSpec
    def initialize(options)
      instance = options.fetch(:instance)
      public_ip = options.fetch(:aws_public_ip)

      @debug = options.fetch(:debug)
      @ip = public_ip ? instance.public_ip_address : instance.private_ip_address
      @role = instance.tags.find{ |tag| tag.key == 'AmiSpec' }.value
      @spec = options.fetch(:specs)
      @user = options.fetch(:ssh_user)
      @key_file = options.fetch(:key_file)
    end

    def run
      puts "Running tests for #{@role}"

      $LOAD_PATH.unshift(@spec) unless $LOAD_PATH.include?(@spec)
      require File.join(@spec, 'spec_helper')

      set :backend, :ssh
      set :host, @ip
      set :ssh_options, :user => @user, :keys => [@key_file], :paranoid => false

      RSpec.configuration.fail_fast = true if @debug

      RSpec::Core::Runner.disable_autorun!
      result = RSpec::Core::Runner.run(Dir.glob("#{@spec}/#{@role}/*_spec.rb"))

      # We can't use Rspec.clear_examples here because it also clears the shared_examples.
      # As shared examples are loaded in via the spec_helper, we cannot reload them.
      RSpec.world.example_groups.clear

      Specinfra::Backend::Ssh.clear

      result.zero?
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ami_spec-0.3.0 lib/ami_spec/server_spec.rb
ami_spec-0.2.0 lib/ami_spec/server_spec.rb