Module: HTMLRender::RenderTest::Rails::Common

Defined in:
lib/html_render/render_test/rails.rb

Class Method Summary collapse

Class Method Details

.create_test_case_from_path(relative_path, options) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/html_render/render_test/rails.rb', line 104

def create_test_case_from_path(relative_path, options)
  clazz = options[:base_class] || RenderTest
  base_path = options[:test_prefix]
  servers = options[:servers]

  test_path = absolute_test_path(relative_path, base_path)
  run_path = absolute_run_path(relative_path, base_path)

  setup_filename = File.join(test_path, 'setup.rb')
  setup_code = File.open(setup_filename) { |f| f.read }

  template_path = File.dirname(relative_path)
  template_dirname = File.dirname(template_path)
  template_basename = File.basename(template_path)
  rails_template_basename = template_basename.sub(/^_/, '')
  rails_template_path = File.join(template_dirname, rails_template_basename)

  FileUtils.mkdir_p(run_path)

  clazz.new(test_path, run_path) do |test_case|
    test_case.instance_eval("      def template_path\n        \#{rails_template_path.inspect}\n      end\n    EOT\n\n    test_case.instance_eval(setup_code, setup_filename, 1)\n  end\nend\n", __FILE__, __LINE__)