Module: Rspec::HtmlMessages::TemplateRenderer

Includes:
ActionView::Helpers::OutputSafetyHelper, ActionView::Helpers::TagHelper, ActionView::Helpers::TextHelper
Included in:
Rspec::HtmlMessages
Defined in:
lib/rspec/html_messages/template_renderer.rb

Instance Method Summary collapse

Instance Method Details

#render_template(template_name, locals = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rspec/html_messages/template_renderer.rb', line 12

def render_template(template_name, locals = {})
  template_path = template_path_for(template_name)
  erb = ERB.new(File.read(template_path))

  # Create a binding with access to helper methods and locals
  binding_with_locals = binding
  locals.each do |key, value|
    binding_with_locals.local_variable_set(key, value)
  end

  erb.result(binding_with_locals)
end