Sha256: d79a7e90de6581e7967c897047e9642a11afe81ba48d385b719dbd01a7135fe1

Contents?: true

Size: 1.79 KB

Versions: 3

Compression:

Stored size: 1.79 KB

Contents

# This file provides a require-able entry point for putting at the top of your
# tests, or in a shared helper.

require 'rspec-system'
require 'yaml'
require 'pp'
require 'tempfile'

RSpec.configure do |c|
  include RSpecSystem::Log
  c.include RSpecSystem::Helpers

  # This provides a path to save vagrant files
  c.add_setting :system_tmp
  # Block to execute for environment setup
  c.add_setting :system_setup_block

  def nodeset
    Pathname.new(File.join(File.basename(__FILE__), '..', '.nodeset.yml'))
  end

  def rspec_system_config
    YAML.load_file('.nodeset.yml')
  end

  # Grab the type of virtual environment we wish to run these tests in
  def rspec_virtual_env
    ENV["RSPEC_VIRTUAL_ENV"] || 'vagrant'
  end

  def rspec_system_node_set
    setname = ENV['RSPEC_SET'] || rspec_system_config['default_set']
    config = rspec_system_config['sets'][setname]
    RSpecSystem::NodeSet.create(setname, config, rspec_virtual_env)
  end

  def start_nodes
    ns = rspec_system_node_set

    log.info "START RSPEC-SYSTEM SETUP"
    log.info "Setname is: " + ns.setname
    log.info "Configuration is: " + ns.config.pretty_inspect
    log.info "Virtual Environment type is: #{ns.env_type}"
    log.info "Default node is: #{ns.default_node.name}"

    ns.setup
  end

  def stop_nodes
    log.info 'FINALIZE RSPEC-SYSTEM SETUP'
    rspec_system_node_set.teardown
  end

  def call_custom_setup_block
    # Run test specific setup routines
    if pr = RSpec.configuration.system_setup_block then
      log.info "Running custom setup block"
      pr.call
      log.info "Finished running custom setup block"
    end
  end

  # Default the system_tmp dir to something random
  c.system_tmp = Dir.tmpdir

  c.before :suite do
    start_nodes
    call_custom_setup_block
  end

  c.after :suite do
    stop_nodes
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rspec-system-0.2.0 lib/rspec-system/spec_helper.rb
rspec-system-0.1.5 lib/rspec-system/spec_helper.rb
rspec-system-0.1.4 lib/rspec-system/spec_helper.rb