class SpecHelperGenerator
Generate the spec_helpr.rb file
Public Class Methods
new(root_path = nil)
click to toggle source
# File lib/serverspec_launcher/generators/spec_helper_generator.rb, line 6 def initialize(root_path = nil) path = root_path ? "#{root_path}/" : '' @template_path = File.expand_path('../../../../templates', __FILE__) @spec_helper = "#{path}spec/spec_helper.rb" end
Public Instance Methods
create_spec_dir()
click to toggle source
# File lib/serverspec_launcher/generators/spec_helper_generator.rb, line 16 def create_spec_dir Dir.mkdir File.dirname(@spec_helper) unless File.exist?(File.dirname(@spec_helper)) end
generate()
click to toggle source
# File lib/serverspec_launcher/generators/spec_helper_generator.rb, line 20 def generate if File.exist?(@spec_helper) str = File.read(@spec_helper) new_str = if str.include? "require 'serverspec_launcher/spec_helper'" str else str.sub(/((require .*\n)+)/, "\\1require 'serverspec_launcher/spec_helper'\n") end File.open(@spec_helper, 'w') { |file| file.write new_str } else create_spec_dir renderer = ERB.new rakefile_template File.open(@spec_helper, 'w') { |file| file.write renderer.result } end end
rakefile_template()
click to toggle source
# File lib/serverspec_launcher/generators/spec_helper_generator.rb, line 12 def rakefile_template File.read "#{@template_path}/spec_helper.rb.erb" end