Class: BarkingIguana::Compound::ServerSpec

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Benchmark, Logging::Helper
Defined in:
lib/barking_iguana/compound/server_spec.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stage) ⇒ ServerSpec

Returns a new instance of ServerSpec.



7
8
9
# File 'lib/barking_iguana/compound/server_spec.rb', line 7

def initialize stage
  self.stage = stage
end

Instance Attribute Details

#stageObject

Returns the value of attribute stage.



5
6
7
# File 'lib/barking_iguana/compound/server_spec.rb', line 5

def stage
  @stage
end

Instance Method Details

#env_for(host) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/barking_iguana/compound/server_spec.rb', line 27

def env_for host
  {
    TARGET_HOST: host.ip_address,
    TARGET_SSH_USER: host.ssh_username,
    TARGET_SSH_KEY: host.ssh_key
  }
end

#host_testsObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/barking_iguana/compound/server_spec.rb', line 35

def host_tests
  hosts.inject({}) do |a,e|
    name = e.name
    glob = "#{root_dir}/#{name}/**/*_spec.rb"
    logger.debug { "Host glob for #{name.inspect} = #{glob.inspect}" }
    tests = Dir.glob glob
    logger.debug { "Host tests for #{name.inspect} = #{tests.inspect}" }
    if !tests.empty?
      if e.state != 'running'
        raise "There are tests for #{name} in #{stage.stage_directory}, but the host is #{e.state}"
      end
      a[e] = tests
    end
    a
  end
end

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/barking_iguana/compound/server_spec.rb', line 14

def run
  logger.debug { "Host tests: #{host_tests.inspect}" }
  host_tests.each do |host, test_files|
    command = "bundle exec ruby -S rspec -r #{spec_helper} #{test_files.join(' ')}"
    c = Mixlib::ShellOut.new command, live_stream: logger, cwd: control_repo_dir, env: env_for(host)
    benchmark command do
      c.run_command
    end
    logger.info { "#{host.name} tests exited with status #{c.exitstatus}" }
    c.error!
  end
end

#spec_helperObject



52
53
54
# File 'lib/barking_iguana/compound/server_spec.rb', line 52

def spec_helper
  File.expand_path '../../../../resources/server_spec_helper.rb', __FILE__
end