Sha256: 12f1ca0817cb5f55b9db5466c15a1e2052c56209fce040b582b5f66e30f8ad56

Contents?: true

Size: 941 Bytes

Versions: 17

Compression:

Stored size: 941 Bytes

Contents

require 'erb'

module Soaspec
  # Handles reading templates for tests
  class TemplateReader
    # Name of file where template is stored
    attr_accessor :template_name

    # @return [String] Path to where template file is stored
    def file_location
      File.join(*Soaspec.template_folder, template_name)
    end

    # @param [String] template_name File where template is stored
    # @return [String] Body of template after determining test_values
    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
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
soaspec-0.2.8 lib/soaspec/template_reader.rb
soaspec-0.2.7 lib/soaspec/template_reader.rb
soaspec-0.2.5 lib/soaspec/template_reader.rb
soaspec-0.2.4 lib/soaspec/template_reader.rb
soaspec-0.2.3 lib/soaspec/template_reader.rb
soaspec-0.2.2 lib/soaspec/template_reader.rb
soaspec-0.2.1 lib/soaspec/template_reader.rb
soaspec-0.2.0 lib/soaspec/template_reader.rb
soaspec-0.1.18 lib/soaspec/template_reader.rb
soaspec-0.1.17 lib/soaspec/template_reader.rb
soaspec-0.1.16 lib/soaspec/template_reader.rb
soaspec-0.1.15 lib/soaspec/template_reader.rb
soaspec-0.1.14 lib/soaspec/template_reader.rb
soaspec-0.1.13 lib/soaspec/template_reader.rb
soaspec-0.1.12 lib/soaspec/template_reader.rb
soaspec-0.1.11 lib/soaspec/template_reader.rb
soaspec-0.1.10 lib/soaspec/template_reader.rb