diff --git a/ext/jasmine-webkit-specrunner/Page.cpp b/ext/jasmine-webkit-specrunner/Page.cpp index f532c9c..caba8e5 100644 --- a/ext/jasmine-webkit-specrunner/Page.cpp +++ b/ext/jasmine-webkit-specrunner/Page.cpp @@ -4,26 +4,27 @@ #include "Page.h" - Page::Page() : QWebPage(), confirmResult(true) {} +Page::Page() : QWebPage(), confirmResult(true) {} - void Page::javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &sourceID) { - emit consoleLog(message, lineNumber, sourceID); - } +void Page::javaScriptConsoleMessage(const QString &message, int lineNumber, const QString &sourceID) { + emit consoleLog(message, lineNumber, sourceID); +} - bool Page::javaScriptConfirm(QWebFrame*, const QString&) { - if (confirmResult) { - emit internalLog("TODO", "jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm for now. Returning true."); - return true; - } else { - confirmResult = true; - return false; - } +bool Page::javaScriptConfirm(QWebFrame*, const QString&) { + if (confirmResult) { + emit internalLog("TODO", "jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm for now. Returning true."); + return true; + } else { + confirmResult = true; + return false; } +} - void Page::javaScriptAlert(QWebFrame*, const QString &msg) { - emit internalLog("alert", msg); - } +void Page::javaScriptAlert(QWebFrame*, const QString &msg) { + emit internalLog("alert", msg); +} + +void Page::oneFalseConfirm() { + confirmResult = false; +} - void Page::oneFalseConfirm() { - confirmResult = false; - } diff --git a/jasmine/prolog.coffee b/jasmine/prolog.coffee index e69de29..ee21d7c 100644 --- a/jasmine/prolog.coffee +++ b/jasmine/prolog.coffee @@ -0,0 +1,55 @@ +if window.JHW + window.console = + log: (data) -> + if typeof(jQuery) != 'undefined' && data instanceof jQuery + JHW.log(style_html($("
").append(data).html(), { indent_size: 2 })) + else + useJsDump = true + + try + if typeof data.toJSON == 'function' + JHW.log("JSON: #{JSON.stringify(data, null, 2)}") + useJsDump = false + catch e + + if useJsDump + dump = jsDump.doParse(data) + if dump.indexOf("\n") == -1 + JHW.log(dump) + else + JHW.log("jsDump: #{dump}") + pp: (data) -> + JHW.log(if jasmine then jasmine.pp(data) else console.log(data)) + peek: (data) -> + console.log(data) + data + + window.onbeforeunload = (e) -> + JHW.leavePageAttempt() + + JHW.stderr.puts('The code tried to leave the test page. Check for unhandled form submits and link clicks.') + + if e = e || window.event + e.returnValue = "leaving" + + return "leaving" + + window.confirm = (message) -> + JHW.stderr.puts("jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm. Returning true.") + true + + window.alert = (message) -> + JHW.stderr.puts(message) + + JHW.error = (message, sourceUrl, lineNumber) -> + + + for handle in [ 'stdout', 'stderr', 'report' ] + JHW[handle] = + print: (content) -> JHW.print(handle, content) + puts: (content) -> JHW.print(handle, content + "\n") + + JHW.log = (msg) -> + JHW.usedConsole() + JHW.stdout.puts(msg) + diff --git a/lib/jasmine/headless.rb b/lib/jasmine/headless.rb index eb2f5fb..b35ff93 100644 --- a/lib/jasmine/headless.rb +++ b/lib/jasmine/headless.rb @@ -16,7 +16,7 @@ module Jasmine::Headless class << self def root - @root ||= Pathname.new(File.expand_path('../../..', __FILE__)) + @root ||= Pathname(File.expand_path('../../..', __FILE__)) end end end diff --git a/skel/template.html.erb b/skel/template.html.erb index ef8c453..cc5ecb1 100644 --- a/skel/template.html.erb +++ b/skel/template.html.erb @@ -3,62 +3,7 @@