Class: AmiSpec::ServerSpec

Inherits:
Object
  • Object
show all
Defined in:
lib/ami_spec/server_spec.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ServerSpec

Returns a new instance of ServerSpec.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ami_spec/server_spec.rb', line 8

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)
  @buildkite = options.fetch(:buildkite)
  @user_data_file = options.fetch(:user_data_file)
  @iam_instance_profile_arn = options.fetch(:user_data_file)
end

Instance Method Details

#runObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ami_spec/server_spec.rb', line 23

def run
  if @buildkite
    puts "--- Running tests for #{@role}"
  else
    puts "Running tests for #{@role}"
  end

  $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

  puts "^^^ +++" if @buildkite && !result.zero?
  result.zero?
end