Class: HTMLRender::RenderTest::DirectoryRenderTest

Inherits:
Object
  • Object
show all
Defined in:
lib/html_render/render_test.rb

Overview

Tests, across browsers, that some HTML renders correctly.

A DirectoryRenderTest works within a particular directory in the filesystem, and it expects the following files:

  • html.html

  • canonical.png (what we want it to look like)

  • valid/SERVER.png for each SYSTEM (i.e., “ff3”, “winxp-ie6”, etc.)

  • runs/20080331014523/SERVER.png (at the time “run” was called)

Calling run() with a hash of servers (see HtmlRender::RenderBatches::HTTPRenderBatch) will batch-render for each server, potentially throwing a HtmlRender::Renderers::HTTPRenderer::ServerError if the render fails. It will return an HtmlRender::RenderTest::Result.

Direct Known Subclasses

Rails::RenderTest

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test_path, run_path) {|_self| ... } ⇒ DirectoryRenderTest

Returns a new instance of DirectoryRenderTest.

Yields:

  • (_self)

Yield Parameters:



133
134
135
136
137
138
# File 'lib/html_render/render_test.rb', line 133

def initialize(test_path, run_path, &block)
  @test_path = test_path
  @run_path = run_path

  yield(self) if block_given?
end

Instance Attribute Details

#run_pathObject (readonly)

Returns the value of attribute run_path.



131
132
133
# File 'lib/html_render/render_test.rb', line 131

def run_path
  @run_path
end

#test_pathObject (readonly)

Returns the value of attribute test_path.



131
132
133
# File 'lib/html_render/render_test.rb', line 131

def test_path
  @test_path
end

Instance Method Details

#htmlObject



140
141
142
143
144
# File 'lib/html_render/render_test.rb', line 140

def html
  @html ||= File.open(html_path) do |f|
    f.read
  end
end

#last_resultObject

Returns the results of the last test. If the “valid” results changed since the last time run() was called, then last_result.pass? may return a different value than before (since it will compare the previously-generated actual .png’s with the newer expected .png’s).



164
165
166
# File 'lib/html_render/render_test.rb', line 164

def last_result
  DirectoryResult.new(run_path, valid_path, canonical_path)
end

#run(servers_hash) ⇒ Object



146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/html_render/render_test.rb', line 146

def run(servers_hash)
  clear_run_directory

  begin
    batch = HTMLRender::RenderBatches::HTTPRenderBatch.new(servers_hash)
    batch.render_html_to_directory(html, run_path)
  rescue Exception => e
    clear_run_directory
    raise e
  end

  last_result
end