Class: VagrantSpec::SpecHelper

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/vagrant_spec/spec_helper.rb

Overview

Generates a spec_helper.rb for integration testing

env [Vagrant::Environment]

Instance Method Summary collapse

Methods included from Utils

#lib_root, #project_root, #template_dir

Constructor Details

#initialize(env) ⇒ SpecHelper



14
15
16
17
# File 'lib/vagrant_spec/spec_helper.rb', line 14

def initialize(env)
  @env = env
  @directory = VagrantSpec::Config.load(env).spec.directory
end

Instance Method Details

#create_directoryObject

return [String]



28
29
30
# File 'lib/vagrant_spec/spec_helper.rb', line 28

def create_directory
  Dir.mkdir @directory unless Dir.exist? @directory
end

#generateObject

Generate the spec_helper.rb



20
21
22
23
24
25
# File 'lib/vagrant_spec/spec_helper.rb', line 20

def generate
  create_directory
  return if File.exist? spec_helper_path
  sh = ERB.new(IO.read(spec_helper_template), 0, '<>').result binding
  IO.write(spec_helper_path, sh)
end

#spec_helper_pathObject

return [String]



33
34
35
# File 'lib/vagrant_spec/spec_helper.rb', line 33

def spec_helper_path
  File.join(@directory, 'spec_helper.rb')
end

#spec_helper_templateObject

return [String]



38
39
40
# File 'lib/vagrant_spec/spec_helper.rb', line 38

def spec_helper_template
  File.join(template_dir, 'spec_helper.erb')
end