Sha256: d5de567484b497947876fcb9726a0b0ee977f0719e5901b148bd4ddf522c0d84

Contents?: true

Size: 1.39 KB

Versions: 6

Compression:

Stored size: 1.39 KB

Contents

require 'rspec/expectations'
require 'cucumber/chef'
require 'cucumber/chef/helpers'
require 'cucumber/chef/steps'
require 'cucumber/chef/version'

class CustomWorld
  include Cucumber::Chef
  include Cucumber::Chef::Helpers
end

World do
  CustomWorld.new
end

$servers = Hash.new(nil)

Before do
  knife_rb = Cucumber::Chef.locate(:file, ".chef", "knife.rb")
  Chef::Config.from_file(knife_rb)

  $servers_bin ||= (Cucumber::Chef.locate(:file, ENV['HOME'], "servers.bin") rescue File.expand_path(File.join(ENV['HOME'], "servers.bin")))

  # cleanup previous lxc containers if asked
  if (ENV['DESTROY'] == "1")
    log("servers", "are being destroyed")
    servers.each do |name|
      server_destroy(name)
    end
    File.exists?($servers_bin) && File.delete($servers_bin)
  else
    log("servers", "are being preserved")
  end

  if File.exists?($servers_bin)
    $servers = Marshal.load(IO.read($servers_bin))
  end

  chef_set_client_config(:chef_server_url => "http://192.168.255.254:4000",
                         :validation_client_name => "chef-validator")
end

After do |scenario|
  @connection.close if @connection

  File.open($servers_bin, 'w') do |f|
    f.puts(Marshal.dump($servers))
  end

  Kernel.exit if scenario.failed?

  # cleanup non-persistent lxc containers on exit
  $servers.select{ |name, attributes| !attributes[:persist] }.each do |name, attributes|
    server_destroy(name)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
cucumber-chef-2.0.4 lib/cucumber/chef/templates/cucumber/env.rb
cucumber-chef-2.0.3 lib/cucumber/chef/templates/cucumber/env.rb
cucumber-chef-2.0.3.pre lib/cucumber/chef/templates/cucumber/env.rb
cucumber-chef-2.0.2.pre lib/cucumber/chef/templates/cucumber/env.rb
cucumber-chef-2.0.1.pre lib/cucumber/chef/templates/cucumber/env.rb
cucumber-chef-2.0.0.pre lib/cucumber/chef/templates/cucumber/env.rb