caxlsx / caxlsx_rails

A Rails plugin to provide templates for the axlsx gem
MIT License
742 stars 84 forks source link

Example code for testing given in README produces `NameError` #182

Closed esquinas closed 3 months ago

esquinas commented 3 months ago

In the README documentation, in section First, create a shared context we are given this example shared context code for testing:

RSpec.shared_context 'axlsx' do

  # all xlsx specs describe must be normalized
  # "folder/view_name.xlsx.axlsx"
  # allow to infer the template path
  template_name = description

  let(:template_path) do
    ['app', 'views', template_name]
  end

  # This helper will be used in tests
  def render_template(locals = {})
    axlsx_binding = Kernel.binding
    locals.each do |key, value|
      axlsx_binding.local_variable_set key, value
    end
    # define a default workbook and a default sheet useful when testing partial in isolation
    wb = Axlsx::Package.new.workbook
    axlsx_binding.local_variable_set(:wb, wb)
    axlsx_binding.local_variable_set(:sheet, wb.add_worksheet)

    # mimics an ActionView::Template class, presenting a 'source' method
    # to retrieve the content of the template
    filename = Rails.root.join(*template_path).to_s
    source = Struct.new(:source).new(File.read(filename))
    axlsx_binding.eval(ActionView::Template::Handlers::AxlsxBuilder.new.call(source), filename)
    axlsx_binding.local_variable_get(:wb)
  end
end

This produces a NameError in version 0.6.4 because Ruby cannot find a class named ActionView::Template::Handlers::AxlsxBuilder anymore.

I will probably provide a PR to fix this.

straydogstudio commented 3 months ago

PR merged