Class: ExampleSpecGenerator
- Inherits:
-
Object
- Object
- ExampleSpecGenerator
- Defined in:
- lib/serverspec_launcher/generators/example_spec_generator.rb
Overview
Generates the propetires.yml to be used in tests
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(root_path = nil) ⇒ ExampleSpecGenerator
constructor
A new instance of ExampleSpecGenerator.
- #template ⇒ Object
Constructor Details
#initialize(root_path = nil) ⇒ ExampleSpecGenerator
Returns a new instance of ExampleSpecGenerator.
6 7 8 9 10 |
# File 'lib/serverspec_launcher/generators/example_spec_generator.rb', line 6 def initialize(root_path = nil) @path = root_path ? "#{root_path}/" : '' @template_path = File.('../../../../templates', __FILE__) @spec_file = "#{@path}spec/example_spec.rb" end |
Instance Method Details
#generate ⇒ Object
16 17 18 19 20 |
# File 'lib/serverspec_launcher/generators/example_spec_generator.rb', line 16 def generate renderer = ERB.new template Dir.mkdir "#{@path}spec" unless Dir.exists? "#{@path}spec" File.open(@spec_file, 'w') { |file| file.write renderer.result } unless File.exists? @spec_file end |
#template ⇒ Object
12 13 14 |
# File 'lib/serverspec_launcher/generators/example_spec_generator.rb', line 12 def template File.read "#{@template_path}/example_spec.rb.erb" end |