class SC::Builder::Test

Builds an HTML files. This will setup an HtmlContext and then invokes the render engines for each source before finally rendering the layout.

Public Class Methods

new(entry) click to toggle source
Calls superclass method SC::Builder::Html::new
# File lib/sproutcore/builders/test.rb, line 16
def initialize(entry)
  super(entry)
  @layout = @target.config[:test_layout] || 'lib/test.rhtml'
end

Public Instance Methods

expand_required_targets(target, opts = {}) click to toggle source

Always include any required test targets as well when loading unit tests.

# File lib/sproutcore/builders/test.rb, line 23
def expand_required_targets(target, opts = {})
  opts[:test] = true
  super(target, opts)
end

Protected Instance Methods

default_content_for_key() click to toggle source
# File lib/sproutcore/builders/test.rb, line 44
def default_content_for_key; :body; end
render_entry(entry) click to toggle source
# File lib/sproutcore/builders/test.rb, line 30
def render_entry(entry)
  entry.stage!

  case entry[:ext]
  when 'js'
    render_jstest(entry)
  when 'rhtml'
    entry.target.buildfile.invoke 'render:erubis',
      :entry    => entry,
      :src_path => entry[:staging_path],
      :context  => self
  end
end
render_jstest(entry) click to toggle source

Renders an individual test into a script tag. Also places the test into its own closure so that globals defined by one test will not conflict with any others.

# File lib/sproutcore/builders/test.rb, line 49
def render_jstest(entry)
  lines = readlines(entry[:staging_path])
  pathname = entry[:staging_path].gsub(/^.+\/staging\//,'').gsub(/"/, '\"')
  lines.unshift %[<script type="text/javascript">\nif (typeof SC !== "undefined") {\n  SC.mode = "TEST_MODE";\n  SC.filename = "#{pathname}"; \n}\n(function() {\n]
  lines.push    %[\n})();\n</script>\n]
  @content_for_final = (@content_for_final || '') + lines.join("")
end