Class: Soaspec::TemplateReader

Inherits:
Object
  • Object
show all
Defined in:
lib/soaspec/template_reader.rb

Overview

Handles reading templates for tests

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#template_nameObject

Name of file where template is stored



7
8
9
# File 'lib/soaspec/template_reader.rb', line 7

def template_name
  @template_name
end

Instance Method Details

#file_locationString

Returns Path to where template file is stored.

Returns:

  • (String)

    Path to where template file is stored



10
11
12
# File 'lib/soaspec/template_reader.rb', line 10

def file_location
  File.join(*Soaspec.template_folder, template_name)
end

#render_body(template_name, binding) ⇒ String

Returns Body of template after determining test_values.

Parameters:

  • template_name (String)

    File where template is stored

Returns:

  • (String)

    Body of template after determining test_values



16
17
18
19
20
21
22
23
24
25
# File 'lib/soaspec/template_reader.rb', line 16

def render_body(template_name, binding)
  self.template_name = template_name
  unless File.exist? file_location
    raise "Cannot see file at #{file_location}. "\
          "Global folder is '#{Soaspec.template_folder}' and filename is '#{template_name}'"
  end
  request_body = File.read file_location
  raise "Template at #{file_location} not parsed correctly" if request_body.strip.empty?
  ERB.new(request_body).result(binding)
end