diff --git a/Guardfile b/Guardfile index 38e4233..38c2dc6 100644 --- a/Guardfile +++ b/Guardfile @@ -3,6 +3,8 @@ # watch('file/path') { `command(s)` } # +guard 'coffeescript', :input => 'vendor/assets/coffeescripts', :output => 'vendor/assets/javascripts' + guard 'shell' do watch(%r{ext/jasmine-webkit-specrunner/.*\.(cpp|h|pro|pri)}) { |m| if !m[0]['moc_'] @@ -27,9 +29,8 @@ end def compile #system %{cd ext/jasmine-webkit-specrunner && ruby test.rb && ruby extconf.rb} - system %{cd ext/jasmine-webkit-specrunner && ruby test.rb && ruby extconf.rb} + system %{cd ext/jasmine-webkit-specrunner && ruby extconf.rb} end compile -guard 'coffeescript', :input => 'jasmine' diff --git a/bin/jasmine-headless-webkit b/bin/jasmine-headless-webkit index 711de51..5495d33 100755 --- a/bin/jasmine-headless-webkit +++ b/bin/jasmine-headless-webkit @@ -18,7 +18,6 @@ begin files_list = Jasmine::FilesList.new(:config => runner.jasmine_config) files_list.files.each { |file| puts file } else - puts "Running Jasmine specs...".color(:white) exit runner.run end rescue CoffeeScript::CompilationError diff --git a/dev-bin/hooks/pre-commit b/dev-bin/hooks/pre-commit deleted file mode 100755 index 75c11e3..0000000 --- a/dev-bin/hooks/pre-commit +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -bundle exec rake -if [ $? -ne 0 ]; then exit 1; fi - diff --git a/dev-bin/install-hooks b/dev-bin/install-hooks deleted file mode 100755 index 5a7809c..0000000 --- a/dev-bin/install-hooks +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -for i in $PWD/dev-bin/hooks/*; do - ln -sf $i .git/hooks/${i##*/} -done - diff --git a/ext/jasmine-webkit-specrunner/ConsoleOutput.cpp b/ext/jasmine-webkit-specrunner/ConsoleOutput.cpp deleted file mode 100644 index c686599..0000000 --- a/ext/jasmine-webkit-specrunner/ConsoleOutput.cpp +++ /dev/null @@ -1,149 +0,0 @@ -#include "ConsoleOutput.h" - -ConsoleOutput::ConsoleOutput() : QObject(), - showColors(false), - consoleLogUsed(false) { - outputIO = &std::cout; - } - -void ConsoleOutput::passed(const QString &specDetail) { - green(); - *outputIO << '.'; - clear(); - outputIO->flush(); - - consoleLogUsed = false; - successes.push(specDetail); -} - -void ConsoleOutput::failed(const QString &specDetail) { - red(); - *outputIO << 'F'; - clear(); - outputIO->flush(); - - consoleLogUsed = false; - failures.push(specDetail); -} - -void ConsoleOutput::green() { - if (showColors) std::cout << "\033[0;32m"; -} - -void ConsoleOutput::clear() { - if (showColors) std::cout << "\033[m"; -} - -void ConsoleOutput::red() { - if (showColors) std::cout << "\033[0;31m"; -} - -void ConsoleOutput::yellow() -{ - if (showColors) std::cout << "\033[0;33m"; -} - -void ConsoleOutput::errorLog(const QString &msg, int lineNumber, const QString &sourceID) { - red(); - *outputIO << "[error] "; - clear(); - *outputIO << qPrintable(sourceID) << ":" << lineNumber << " : " << qPrintable(msg); - *outputIO << std::endl; -} - -void ConsoleOutput::internalLog(const QString ¬e, const QString &msg) { - red(); - *outputIO << "[" << qPrintable(note) << "] "; - clear(); - *outputIO << qPrintable(msg); - *outputIO << std::endl; -} - -void ConsoleOutput::consoleLog(const QString &msg) { - if (!consoleLogUsed) { - *outputIO << std::endl; - consoleLogUsed = true; - } - - green(); - *outputIO << "[console] "; - if (msg.contains("\n")) - *outputIO << std::endl; - clear(); - *outputIO << qPrintable(msg); - *outputIO << std::endl; -} - -void ConsoleOutput::logSpecFilename(const QString &name) { - *outputIO << std::endl << std::endl; - red(); - *outputIO << qPrintable(name) << std::endl; - clear(); -} - -void ConsoleOutput::logSpecResult(const QString &result) { - QStringList lines = result.split("\n"); - QStringListIterator linesIterator(lines); - - red(); - while (linesIterator.hasNext()) { - QString line = linesIterator.next(); - if (!linesIterator.hasNext()) - yellow(); - *outputIO << " " << qPrintable(line) << std::endl; - } - - clear(); -} - -void ConsoleOutput::reportFailure(const QString &totalTests, const QString &failedTests, const QString &duration) { - red(); - *outputIO << std::endl << "FAIL: "; - formatTestResults(totalTests, failedTests, duration); - *outputIO << std::endl; - clear(); -} - -void ConsoleOutput::reportSuccess(const QString &totalTests, const QString &failedTests, const QString &duration) { - green(); - *outputIO << std::endl << "PASS: "; - formatTestResults(totalTests, failedTests, duration); - *outputIO << std::endl; - clear(); -} - -void ConsoleOutput::reportSuccessWithJSErrors(const QString &totalTests, const QString &failedTests, const QString &duration) { - yellow(); - *outputIO << std::endl << "PASS with JS errors: "; - formatTestResults(totalTests, failedTests, duration); - *outputIO << std::endl; - clear(); -} - -void ConsoleOutput::formatTestResults(const QString &totalTests, const QString &failedTests, const QString &duration) { - *outputIO << qPrintable(totalTests) << " "; - if (totalTests == "1") { - *outputIO << "test"; - } else { - *outputIO << "tests"; - } - - *outputIO << ", "; - - *outputIO << qPrintable(failedTests) << " "; - if (failedTests == "1") { - *outputIO << "failure"; - } else { - *outputIO << "failures"; - } - - *outputIO << ", "; - - *outputIO << qPrintable(duration) << " "; - if (duration == "1") { - *outputIO << "sec."; - } else { - *outputIO << "secs."; - } -} - diff --git a/ext/jasmine-webkit-specrunner/ConsoleOutput.h b/ext/jasmine-webkit-specrunner/ConsoleOutput.h deleted file mode 100644 index b15004b..0000000 --- a/ext/jasmine-webkit-specrunner/ConsoleOutput.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef JHW_CONSOLE_OUTPUT -#define JHW_CONSOLE_OUTPUT - -#include -#include -#include -#include - -class ConsoleOutput : public QObject { - public: - ConsoleOutput(); - - void passed(const QString &specDetail); - void failed(const QString &specDetail); - void errorLog(const QString &msg, int lineNumber, const QString &sourceID); - void internalLog(const QString ¬e, const QString &msg); - void consoleLog(const QString &msg); - void logSpecFilename(const QString &name); - void logSpecResult(const QString &result); - - void reportFailure(const QString &totalTests, const QString &failedTests, const QString &duration); - void reportSuccess(const QString &totalTests, const QString &failedTests, const QString &duration); - void reportSuccessWithJSErrors(const QString &totalTests, const QString &failedTests, const QString &duration); - - std::ostream *outputIO; - QStack successes; - QStack failures; - - bool showColors; - bool consoleLogUsed; - private: - void green(); - void clear(); - void red(); - void yellow(); - void formatTestResults(const QString &totalTests, const QString &failedTests, const QString &duration); -}; - -#endif diff --git a/ext/jasmine-webkit-specrunner/ConsoleOutput_test.cpp b/ext/jasmine-webkit-specrunner/ConsoleOutput_test.cpp deleted file mode 100644 index dccdd52..0000000 --- a/ext/jasmine-webkit-specrunner/ConsoleOutput_test.cpp +++ /dev/null @@ -1,129 +0,0 @@ -#include - -#include "ConsoleOutput.h" -#include "ConsoleOutput_test.h" - -using namespace std; - - ConsoleOutputTest::ConsoleOutputTest() : QObject() {} - - void ConsoleOutputTest::testPassed() { - stringstream buffer; - ConsoleOutput output; - - output.consoleLogUsed = true; - output.outputIO = &buffer; - output.passed("test"); - QVERIFY(buffer.str() == "."); - QVERIFY(output.successes.size() == 1); - QVERIFY(output.failures.size() == 0); - QVERIFY(output.consoleLogUsed == false); - } - - void ConsoleOutputTest::testFailed() { - stringstream buffer; - ConsoleOutput output; - - output.consoleLogUsed = true; - output.outputIO = &buffer; - output.failed("test"); - QVERIFY(buffer.str() == "F"); - QVERIFY(output.successes.size() == 0); - QVERIFY(output.failures.size() == 1); - QVERIFY(output.consoleLogUsed == false); - } - - void ConsoleOutputTest::testErrorLog() { - stringstream buffer; - ConsoleOutput output; - - output.outputIO = &buffer; - output.errorLog("message", 1, "source"); - QVERIFY(buffer.str() == "[error] source:1 : message\n"); - } - - void ConsoleOutputTest::testInternalLog() { - stringstream buffer; - ConsoleOutput output; - - output.outputIO = &buffer; - output.internalLog("note", "message"); - QVERIFY(buffer.str() == "[note] message\n"); - } - - void ConsoleOutputTest::testConsoleLog() { - stringstream buffer; - ConsoleOutput output; - - output.consoleLogUsed = false; - output.outputIO = &buffer; - output.consoleLog("log"); - QVERIFY(buffer.str() == "\n[console] log\n"); - } - - void ConsoleOutputTest::testConsoleLogUsed() { - stringstream buffer; - ConsoleOutput output; - - output.consoleLogUsed = true; - output.outputIO = &buffer; - output.consoleLog("log"); - QVERIFY(buffer.str() == "[console] log\n"); - } - - void ConsoleOutputTest::testLogSpecFilename() { - stringstream buffer; - ConsoleOutput output; - - output.outputIO = &buffer; - output.logSpecFilename("whatever"); - QVERIFY(buffer.str() == "\n\nwhatever\n"); - } - - void ConsoleOutputTest::testLogSpecResult() { - stringstream buffer; - ConsoleOutput output; - - output.outputIO = &buffer; - output.logSpecResult("whatever"); - QVERIFY(buffer.str() == " whatever\n"); - } - - void ConsoleOutputTest::testReportResultsFailedSingular() { - stringstream buffer; - ConsoleOutput output; - - output.outputIO = &buffer; - output.reportFailure("1", "1", "1"); - QVERIFY(buffer.str() == "\nFAIL: 1 test, 1 failure, 1 sec.\n"); - } - - void ConsoleOutputTest::testReportResultsFailedPlural() { - stringstream buffer; - ConsoleOutput output; - - output.outputIO = &buffer; - output.reportFailure("2", "2", "2"); - QVERIFY(buffer.str() == "\nFAIL: 2 tests, 2 failures, 2 secs.\n"); - } - - void ConsoleOutputTest::testReportResultsSucceeded() { - stringstream buffer; - ConsoleOutput output; - - output.outputIO = &buffer; - output.reportSuccess("2", "2", "2"); - QVERIFY(buffer.str() == "\nPASS: 2 tests, 2 failures, 2 secs.\n"); - } - - void ConsoleOutputTest::testReportResultsSucceededWithJSErrors() { - stringstream buffer; - ConsoleOutput output; - - output.outputIO = &buffer; - output.reportSuccessWithJSErrors("2", "2", "2"); - QVERIFY(buffer.str() == "\nPASS with JS errors: 2 tests, 2 failures, 2 secs.\n"); - } - -QTEST_MAIN(ConsoleOutputTest); - diff --git a/ext/jasmine-webkit-specrunner/ConsoleOutput_test.h b/ext/jasmine-webkit-specrunner/ConsoleOutput_test.h deleted file mode 100644 index 246e231..0000000 --- a/ext/jasmine-webkit-specrunner/ConsoleOutput_test.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef JHW_TEST_CONSOLE_OUTPUT -#define JHW_TEST_CONSOLE_OUTPUT - -#include -#include -#include -#include - -#include "ConsoleOutput.h" - -class ConsoleOutputTest : public QObject { - Q_OBJECT - public: - ConsoleOutputTest(); - - private slots: - void testPassed(); - void testFailed(); - void testErrorLog(); - void testInternalLog(); - void testConsoleLog(); - void testConsoleLogUsed(); - void testLogSpecFilename(); - void testLogSpecResult(); - - void testReportResultsFailedSingular(); - void testReportResultsFailedPlural(); - void testReportResultsSucceeded(); - void testReportResultsSucceededWithJSErrors(); -}; - -#endif diff --git a/ext/jasmine-webkit-specrunner/ConsoleOutput_test.pro b/ext/jasmine-webkit-specrunner/ConsoleOutput_test.pro deleted file mode 100644 index 7b09285..0000000 --- a/ext/jasmine-webkit-specrunner/ConsoleOutput_test.pro +++ /dev/null @@ -1,7 +0,0 @@ -include(common.pri) -include(test.pri) - -SOURCES += ConsoleOutput_test.cpp -HEADERS += ConsoleOutput_test.h - - diff --git a/ext/jasmine-webkit-specrunner/Page.cpp b/ext/jasmine-webkit-specrunner/Page.cpp index f532c9c..b3f6c3d 100644 --- a/ext/jasmine-webkit-specrunner/Page.cpp +++ b/ext/jasmine-webkit-specrunner/Page.cpp @@ -4,26 +4,13 @@ #include "Page.h" - Page::Page() : QWebPage(), confirmResult(true) {} +Page::Page() : QWebPage() {} - 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 handleError(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; - } - } - - void Page::javaScriptAlert(QWebFrame*, const QString &msg) { - emit internalLog("alert", msg); - } - - void Page::oneFalseConfirm() { - confirmResult = false; - } +void Page::javaScriptAlert(QWebFrame *, const QString &) {} +bool Page::javaScriptConfirm(QWebFrame *, const QString &) { + return false; +} diff --git a/ext/jasmine-webkit-specrunner/Page.h b/ext/jasmine-webkit-specrunner/Page.h index 01963c4..74c6f77 100644 --- a/ext/jasmine-webkit-specrunner/Page.h +++ b/ext/jasmine-webkit-specrunner/Page.h @@ -4,20 +4,16 @@ #include #include - class Page: public QWebPage { - Q_OBJECT - public: - Page(); - void oneFalseConfirm(); - signals: - void consoleLog(const QString &msg, int lineNumber, const QString &sourceID); - void internalLog(const QString ¬e, const QString &msg); - protected: - void javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID); - bool javaScriptConfirm(QWebFrame *frame, const QString &msg); - void javaScriptAlert(QWebFrame *frame, const QString &msg); - private: - bool confirmResult; - }; +class Page: public QWebPage { + Q_OBJECT + public: + Page(); + protected: + void javaScriptConsoleMessage(const QString & message, int lineNumber, const QString & sourceID); + void javaScriptAlert(QWebFrame *, const QString &); + bool javaScriptConfirm(QWebFrame *, const QString &); + signals: + void handleError(const QString & message, int lineNumber, const QString & sourceID); +}; #endif diff --git a/ext/jasmine-webkit-specrunner/Page_test.cpp b/ext/jasmine-webkit-specrunner/Page_test.cpp deleted file mode 100644 index 7cc213a..0000000 --- a/ext/jasmine-webkit-specrunner/Page_test.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include - -#include "Page.h" -#include "Page_test.h" - - PageTest::PageTest() : QObject(), internalLogCalled(false) { - } - - void PageTest::internalLog(const QString &, const QString &) { - internalLogCalled = true; - } - - void PageTest::consoleLog(const QString &, int, const QString &) { - consoleLogCalled = true; - } - - void PageTest::testJavaScriptConfirmWithLog() { - connect(&page, SIGNAL(internalLog(QString, QString)), this, SLOT(internalLog(QString, QString))); - internalLogCalled = false; - - page.mainFrame()->setHtml(""); - QVERIFY(internalLogCalled); - } - - void PageTest::testJavaScriptConfirmWithoutLog() { - connect(&page, SIGNAL(internalLog(QString, QString)), this, SLOT(internalLog(QString, QString))); - internalLogCalled = false; - - page.oneFalseConfirm(); - page.mainFrame()->setHtml(""); - QVERIFY(!internalLogCalled); - } - - void PageTest::testJavaScriptConsoleMessage() { - connect(&page, SIGNAL(consoleLog(QString, int, QString)), this, SLOT(consoleLog(QString, int, QString))); - consoleLogCalled = false; - - page.mainFrame()->setHtml(""); - QVERIFY(consoleLogCalled); - } - -QTEST_MAIN(PageTest); - diff --git a/ext/jasmine-webkit-specrunner/Page_test.h b/ext/jasmine-webkit-specrunner/Page_test.h deleted file mode 100644 index dcd7872..0000000 --- a/ext/jasmine-webkit-specrunner/Page_test.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef JHW_TEST_PAGE -#define JHW_TEST_PAGE - -#include - -#include "Page.h" - - class PageTest : public QObject { - Q_OBJECT - public: - PageTest(); - - private: - bool internalLogCalled; - bool consoleLogCalled; - Page page; - - private slots: - void internalLog(const QString ¬e, const QString &msg); - void consoleLog(const QString &message, int lineNumber, const QString &source); - void testJavaScriptConfirmWithLog(); - void testJavaScriptConfirmWithoutLog(); - void testJavaScriptConsoleMessage(); - }; - -#endif - diff --git a/ext/jasmine-webkit-specrunner/Page_test.pro b/ext/jasmine-webkit-specrunner/Page_test.pro deleted file mode 100644 index 9482e83..0000000 --- a/ext/jasmine-webkit-specrunner/Page_test.pro +++ /dev/null @@ -1,6 +0,0 @@ -include(common.pri) -include(test.pri) - -SOURCES += Page_test.cpp -HEADERS += Page_test.h - diff --git a/ext/jasmine-webkit-specrunner/ReportFileOutput.cpp b/ext/jasmine-webkit-specrunner/ReportFileOutput.cpp deleted file mode 100644 index b215e47..0000000 --- a/ext/jasmine-webkit-specrunner/ReportFileOutput.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include "ReportFileOutput.h" - -using namespace std; - -ReportFileOutput::ReportFileOutput() : QObject() { - reset(); -} - -void ReportFileOutput::reset() { - buffer = new stringstream(); - - outputIO = buffer; -} - -void ReportFileOutput::passed(const QString &specDetail) { - *outputIO << "PASS||" << qPrintable(specDetail) << std::endl; - successes.push(specDetail); -} - -void ReportFileOutput::failed(const QString &specDetail) { - *outputIO << "FAIL||" << qPrintable(specDetail) << std::endl; - failures.push(specDetail); -} - -void ReportFileOutput::errorLog(const QString &msg, int lineNumber, const QString &sourceID) { - *outputIO << "ERROR||" << qPrintable(msg) << "||" << qPrintable(sourceID) << ":" << lineNumber << std::endl; -} - -void ReportFileOutput::consoleLog(const QString &msg) { - *outputIO << "CONSOLE||" << qPrintable(msg) << std::endl; -} - -void ReportFileOutput::internalLog(const QString &, const QString &) {} -void ReportFileOutput::logSpecFilename(const QString &) {} -void ReportFileOutput::logSpecResult(const QString &) {} - -void ReportFileOutput::reportFailure(const QString &totalTests, const QString &failedTests, const QString &duration) { - reportTotals(totalTests, failedTests, duration, false); -} - -void ReportFileOutput::reportSuccess(const QString &totalTests, const QString &failedTests, const QString &duration) { - reportTotals(totalTests, failedTests, duration, false); -} - -void ReportFileOutput::reportSuccessWithJSErrors(const QString &totalTests, const QString &failedTests, const QString &duration) { - reportTotals(totalTests, failedTests, duration, true); -} - -void ReportFileOutput::reportTotals(const QString &totalTests, const QString &failedTests, const QString &duration, bool hasJavaScriptError) { - *outputIO << "TOTAL||" << qPrintable(totalTests) << "||" << qPrintable(failedTests) << "||" << qPrintable(duration) << "||"; - *outputIO << (hasJavaScriptError ? "T" : "F"); - *outputIO << std::endl; -} - diff --git a/ext/jasmine-webkit-specrunner/ReportFileOutput.h b/ext/jasmine-webkit-specrunner/ReportFileOutput.h deleted file mode 100644 index 30b4f02..0000000 --- a/ext/jasmine-webkit-specrunner/ReportFileOutput.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef JHW_REPORT_FILE_OUTPUT -#define JHW_REPORT_FILE_OUTPUT - -#include -#include -#include -#include - -using namespace std; - -class ReportFileOutput : public QObject { - public: - ReportFileOutput(); - - void passed(const QString &specDetail); - void failed(const QString &specDetail); - void errorLog(const QString &msg, int lineNumber, const QString &sourceID); - void internalLog(const QString ¬e, const QString &msg); - void consoleLog(const QString &msg); - void logSpecFilename(const QString &name); - void logSpecResult(const QString &result); - - void reportFailure(const QString &totalTests, const QString &failedTests, const QString &duration); - void reportSuccess(const QString &totalTests, const QString &failedTests, const QString &duration); - void reportSuccessWithJSErrors(const QString &totalTests, const QString &failedTests, const QString &duration); - - void reset(); - - stringstream *buffer; - stringstream *outputIO; - QStack successes; - QStack failures; - private: - void reportTotals(const QString &totalTests, const QString &failedTests, const QString &duration, bool hasJavaScriptError); -}; - -#endif diff --git a/ext/jasmine-webkit-specrunner/ReportFileOutput_test.cpp b/ext/jasmine-webkit-specrunner/ReportFileOutput_test.cpp deleted file mode 100644 index bc5b9e4..0000000 --- a/ext/jasmine-webkit-specrunner/ReportFileOutput_test.cpp +++ /dev/null @@ -1,88 +0,0 @@ -#include - -#include "ReportFileOutput.h" -#include "ReportFileOutput_test.h" - -using namespace std; - -ReportFileOutputTest::ReportFileOutputTest() : QObject() {} - -void ReportFileOutputTest::testPassed() { - stringstream buffer; - ReportFileOutput output; - - output.outputIO = &buffer; - output.passed("test||done||file.js:23"); - QVERIFY(buffer.str() == "PASS||test||done||file.js:23\n"); - QVERIFY(output.successes.size() == 1); - QVERIFY(output.failures.size() == 0); -} - -void ReportFileOutputTest::testFailed() { - stringstream buffer; - ReportFileOutput output; - - output.outputIO = &buffer; - output.failed("test||done||file.js:23"); - QVERIFY(buffer.str() == "FAIL||test||done||file.js:23\n"); - QVERIFY(output.successes.size() == 0); - QVERIFY(output.failures.size() == 1); -} - -void ReportFileOutputTest::testErrorLog() { - stringstream buffer; - ReportFileOutput output; - - output.outputIO = &buffer; - output.errorLog("JS Error", 23, "file.js"); - QVERIFY(buffer.str() == "ERROR||JS Error||file.js:23\n"); -} - -void ReportFileOutputTest::testConsoleLog() { - stringstream buffer; - ReportFileOutput output; - - output.outputIO = &buffer; - output.consoleLog("Console"); - QVERIFY(buffer.str() == "CONSOLE||Console\n"); -} - -void ReportFileOutputTest::testStubMethods() { - stringstream buffer; - ReportFileOutput output; - - output.outputIO = &buffer; - output.internalLog("Internal", "Log"); - output.logSpecFilename("Filename"); - output.logSpecResult("REsult"); -} - -void ReportFileOutputTest::testReportFailure() { - stringstream buffer; - ReportFileOutput output; - - output.outputIO = &buffer; - output.reportFailure("5", "2", "1.5"); - QVERIFY(buffer.str() == "TOTAL||5||2||1.5||F\n"); -} - -void ReportFileOutputTest::testReportSuccess() { - stringstream buffer; - ReportFileOutput output; - - output.outputIO = &buffer; - output.reportSuccess("5", "0", "1.5"); - QVERIFY(buffer.str() == "TOTAL||5||0||1.5||F\n"); -} - -void ReportFileOutputTest::testReportSuccessWithJSErrors() { - stringstream buffer; - ReportFileOutput output; - - output.outputIO = &buffer; - output.reportSuccessWithJSErrors("5", "0", "1.5"); - QVERIFY(buffer.str() == "TOTAL||5||0||1.5||T\n"); -} - -QTEST_MAIN(ReportFileOutputTest); - diff --git a/ext/jasmine-webkit-specrunner/ReportFileOutput_test.h b/ext/jasmine-webkit-specrunner/ReportFileOutput_test.h deleted file mode 100644 index 8b46a60..0000000 --- a/ext/jasmine-webkit-specrunner/ReportFileOutput_test.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef JHW_TEST_REPORT_FILE_OUTPUT -#define JHW_TEST_REPORT_FILE_OUTPUT - -#include -#include -#include -#include - -#include "ReportFileOutput.h" - -class ReportFileOutputTest : public QObject { - Q_OBJECT - public: - ReportFileOutputTest(); - private slots: - void testPassed(); - void testFailed(); - void testErrorLog(); - void testConsoleLog(); - void testStubMethods(); - void testReportFailure(); - void testReportSuccess(); - void testReportSuccessWithJSErrors(); -}; - -#endif diff --git a/ext/jasmine-webkit-specrunner/ReportFileOutput_test.pro b/ext/jasmine-webkit-specrunner/ReportFileOutput_test.pro deleted file mode 100644 index 12485f0..0000000 --- a/ext/jasmine-webkit-specrunner/ReportFileOutput_test.pro +++ /dev/null @@ -1,7 +0,0 @@ -include(common.pri) -include(test.pri) - -SOURCES += ReportFileOutput_test.cpp -HEADERS += ReportFileOutput_test.h - - diff --git a/ext/jasmine-webkit-specrunner/Runner.cpp b/ext/jasmine-webkit-specrunner/Runner.cpp index 6c64ad3..1179d0e 100644 --- a/ext/jasmine-webkit-specrunner/Runner.cpp +++ b/ext/jasmine-webkit-specrunner/Runner.cpp @@ -3,181 +3,153 @@ #include #include #include +#include #include #include "Runner.h" +#include "Page.h" using namespace std; Runner::Runner() : QObject() - , m_runs(0) + , runs(0) , hasErrors(false) + , _hasSpecFailure(false) , usedConsole(false) , isFinished(false) - , didFail(false) + , useColors(false) { - m_page.settings()->enablePersistentStorage(); - m_ticker.setInterval(TIMER_TICK); + page.settings()->enablePersistentStorage(); + ticker.setInterval(TIMER_TICK); - connect(&m_ticker, SIGNAL(timeout()), this, SLOT(timerEvent())); - connect(&m_page, SIGNAL(loadFinished(bool)), this, SLOT(watch(bool))); - connect(&m_page, SIGNAL(consoleLog(QString, int, QString)), this, SLOT(errorLog(QString, int, QString))); - connect(&m_page, SIGNAL(internalLog(QString, QString)), this, SLOT(internalLog(QString, QString))); - connect(m_page.mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(addJHW())); + connect(&ticker, SIGNAL(timeout()), this, SLOT(timerEvent())); + connect(&page, SIGNAL(loadFinished(bool)), this, SLOT(watch(bool))); + connect(&page, SIGNAL(handleError(const QString &, int, const QString &)), this, SLOT(handleError(const QString &, int, const QString &))); + connect(page.mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(addJHW())); } void Runner::addFile(const QString &spec) { runnerFiles.enqueue(spec); } -void Runner::go() -{ - m_ticker.stop(); - m_page.setPreferredContentsSize(QSize(1024, 600)); +void Runner::go() { + ticker.stop(); + page.setPreferredContentsSize(QSize(1024, 600)); addJHW(); - loadSpec(); - m_ticker.start(); + loadSpec(); } -void Runner::addJHW() -{ - m_page.mainFrame()->addToJavaScriptWindowObject("JHW", this); +void Runner::addJHW() { + page.mainFrame()->addToJavaScriptWindowObject("JHW", this); +} + +void Runner::handleError(const QString &message, int lineNumber, const QString &sourceID) { + QString messageEscaped = QString(message); + QString sourceIDEscaped = QString(sourceID); + + messageEscaped.replace(QString("\""), QString("\\\"")); + sourceIDEscaped.replace(QString("\""), QString("\\\"")); + + std::stringstream ss; + ss << lineNumber; + + QString command("JHW._handleError(\"" + messageEscaped + "\", " + QString(ss.str().c_str()) + ", \"" + sourceIDEscaped + "\"); false;"); + + page.mainFrame()->evaluateJavaScript(command); + + hasErrors = true; } void Runner::loadSpec() { - m_page.mainFrame()->load(runnerFiles.dequeue()); - m_ticker.start(); + if (reportFileName.isEmpty()) { + outputFile = 0; + ts = 0; + } else { + outputFile = new QFile(reportFileName); + outputFile->open(QIODevice::WriteOnly); + + ts = new QTextStream(outputFile); + } + + page.mainFrame()->load(runnerFiles.dequeue()); + ticker.start(); } -void Runner::watch(bool ok) -{ +void Runner::watch(bool ok) { if (!ok) { - std::cerr << "Can't load " << qPrintable(m_page.mainFrame()->url().toString()) << ", the file may be broken." << std::endl; + std::cerr << "Can't load " << qPrintable(page.mainFrame()->url().toString()) << ", the file may be broken." << std::endl; std::cerr << "Out of curiosity, did your tests try to submit a form and you haven't prevented that?" << std::endl; std::cerr << "Try running your tests in your browser with the Jasmine server and see what happens." << std::endl; QApplication::instance()->exit(1); return; } -} - -bool Runner::hasElement(const char *select) -{ - return !m_page.mainFrame()->findFirstElement(select).isNull(); + page.mainFrame()->evaluateJavaScript(QString("JHW._setColors(") + (useColors ? QString("true") : QString("false")) + QString("); false;")); } void Runner::setColors(bool colors) { - consoleOutput.showColors = colors; + useColors = colors; +} + +void Runner::hasUsedConsole() { + usedConsole = true; +} + +void Runner::hasError() { + hasErrors = true; +} + +void Runner::hasSpecFailure() { + _hasSpecFailure = true; } void Runner::reportFile(const QString &file) { reportFileName = file; } -bool Runner::hasError() { - return hasErrors; -} - void Runner::timerPause() { - m_ticker.stop(); + ticker.stop(); } void Runner::timerDone() { - m_ticker.start(); + ticker.start(); } -void Runner::specPassed(const QString &specDetail) { - consoleOutput.passed(specDetail); - reportFileOutput.passed(specDetail); -} - -void Runner::specFailed(const QString &specDetail) { - consoleOutput.failed(specDetail); - reportFileOutput.failed(specDetail); - - didFail = true; - failedSpecs.push(specDetail); -} - -void Runner::errorLog(const QString &msg, int lineNumber, const QString &sourceID) -{ - consoleOutput.errorLog(msg, lineNumber, sourceID); - reportFileOutput.errorLog(msg, lineNumber, sourceID); - - hasErrors = true; - m_runs = 0; - m_ticker.start(); -} - -void Runner::internalLog(const QString ¬e, const QString &msg) { - consoleOutput.internalLog(note, msg); - reportFileOutput.internalLog(note, msg); -} - -void Runner::log(const QString &msg) -{ - usedConsole = true; - consoleOutput.consoleLog(msg); - reportFileOutput.consoleLog(msg); -} - -void Runner::leavePageAttempt(const QString &msg) -{ - consoleOutput.internalLog("error", msg); - m_page.oneFalseConfirm(); - hasErrors = true; -} - -void Runner::printName(const QString &name) -{ - consoleOutput.logSpecFilename(name); -} - -void Runner::printResult(const QString &result) -{ - consoleOutput.logSpecResult(result); -} - -void Runner::finishSuite(const QString &duration, const QString &total, const QString& failed) -{ - if (didFail) { - consoleOutput.reportFailure(total, failed, duration); - reportFileOutput.reportFailure(total, failed, duration); - } else { - if (hasErrors) { - consoleOutput.reportSuccessWithJSErrors(total, failed, duration); - reportFileOutput.reportSuccessWithJSErrors(total, failed, duration); - } else { - consoleOutput.reportSuccess(total, failed, duration); - reportFileOutput.reportSuccess(total, failed, duration); - } +void Runner::print(const QString &fh, const QString &content) { + if (fh == "stdout") { + std::cout << qPrintable(content); + std::cout.flush(); } - if (!reportFileName.isEmpty()) { - QFile outputFile(reportFileName); - outputFile.open(QIODevice::WriteOnly); - - QTextStream ts(&outputFile); - - ts << reportFileOutput.outputIO->str().c_str(); - - outputFile.close(); + if (fh == "stderr") { + std::cerr << qPrintable(content); + std::cerr.flush(); } + if (fh == "report" && outputFile) { + *ts << qPrintable(content); + ts->flush(); + } +} + +void Runner::finishSuite() { isFinished = true; } -void Runner::timerEvent() -{ - ++m_runs; +void Runner::timerEvent() { + ++runs; - if (hasErrors && m_runs > 2) + if (hasErrors && runs > 2) QApplication::instance()->exit(1); if (isFinished) { + if (outputFile) { + outputFile->close(); + } + int exitCode = 0; - if (didFail || hasErrors) { + if (_hasSpecFailure || hasErrors) { exitCode = 1; } else { if (usedConsole) { @@ -203,8 +175,8 @@ void Runner::timerEvent() } } - if (m_runs > MAX_LOOPS) { - std::cout << "WARNING: too many runs and the test is still not finished!" << std::endl; + if (runs > MAX_LOOPS) { + std::cerr << "WARNING: too many runs and the test is still not finished!" << std::endl; QApplication::instance()->exit(1); } } diff --git a/ext/jasmine-webkit-specrunner/Runner.h b/ext/jasmine-webkit-specrunner/Runner.h index 96170b9..c0744a8 100644 --- a/ext/jasmine-webkit-specrunner/Runner.h +++ b/ext/jasmine-webkit-specrunner/Runner.h @@ -10,57 +10,53 @@ #include #include "Page.h" -#include "ConsoleOutput.h" -#include "ReportFileOutput.h" using namespace std; class Runner: public QObject { Q_OBJECT public: - enum { TIMER_TICK = 200, MAX_LOOPS = 25 }; + enum { TIMER_TICK = 200, MAX_LOOPS = 50 }; Runner(); void setColors(bool colors); void reportFile(const QString &file); void addFile(const QString &spec); void go(); - public slots: - void log(const QString &msg); - bool hasError(); - void leavePageAttempt(const QString &msg); + + public slots: void timerPause(); void timerDone(); - void specPassed(const QString &specDetail); - void specFailed(const QString &specDetail); - void printName(const QString &name); - void printResult(const QString &result); - void finishSuite(const QString &duration, const QString &total, const QString& failed); - private slots: - void watch(bool ok); - void errorLog(const QString &msg, int lineNumber, const QString &sourceID); - void internalLog(const QString ¬e, const QString &msg); + void hasUsedConsole(); + void hasError(); + void hasSpecFailure(); + void print(const QString &fh, const QString &content); + void finishSuite(); + + private slots: + void watch(bool ok); void addJHW(); void timerEvent(); - protected: - bool hasElement(const char *select); + void handleError(const QString & message, int lineNumber, const QString & sourceID); + private: - Page m_page; - QTimer m_ticker; - int m_runs; + Page page; + QTimer ticker; + int runs; bool hasErrors; + bool _hasSpecFailure; bool usedConsole; bool isFinished; - bool didFail; - QQueue runnerFiles; - QStack failedSpecs; + bool useColors; - ConsoleOutput consoleOutput; - ReportFileOutput reportFileOutput; + QQueue runnerFiles; QString reportFileName; void loadSpec(); + + QFile *outputFile; + QTextStream *ts; }; #endif diff --git a/ext/jasmine-webkit-specrunner/common.pri b/ext/jasmine-webkit-specrunner/common.pri index 7fdf73b..0320485 100644 --- a/ext/jasmine-webkit-specrunner/common.pri +++ b/ext/jasmine-webkit-specrunner/common.pri @@ -4,6 +4,6 @@ QMAKE_INFO_PLIST = Info.plist QMAKESPEC = macx-g++ QT += network webkit -SOURCES = Page.cpp Runner.cpp ConsoleOutput.cpp ReportFileOutput.cpp -HEADERS = Page.h Runner.h ConsoleOutput.h ReportFileOutput.h +SOURCES = Page.cpp Runner.cpp +HEADERS = Page.h Runner.h diff --git a/ext/jasmine-webkit-specrunner/specrunner.cpp b/ext/jasmine-webkit-specrunner/specrunner.cpp index b144a30..c0e969f 100644 --- a/ext/jasmine-webkit-specrunner/specrunner.cpp +++ b/ext/jasmine-webkit-specrunner/specrunner.cpp @@ -21,7 +21,6 @@ THE SOFTWARE. */ -#include "Page.h" #include "Runner.h" #if QT_VERSION < QT_VERSION_CHECK(4, 7, 0) diff --git a/ext/jasmine-webkit-specrunner/specrunner.pro b/ext/jasmine-webkit-specrunner/specrunner.pro index 820c444..1157ea4 100644 --- a/ext/jasmine-webkit-specrunner/specrunner.pro +++ b/ext/jasmine-webkit-specrunner/specrunner.pro @@ -2,3 +2,4 @@ include(common.pri) SOURCES += specrunner.cpp TARGET = jasmine-webkit-specrunner + diff --git a/ext/jasmine-webkit-specrunner/test.pri b/ext/jasmine-webkit-specrunner/test.pri deleted file mode 100644 index 4804421..0000000 --- a/ext/jasmine-webkit-specrunner/test.pri +++ /dev/null @@ -1,3 +0,0 @@ -TARGET = jhw-test -QT += testlib - diff --git a/ext/jasmine-webkit-specrunner/test.rb b/ext/jasmine-webkit-specrunner/test.rb deleted file mode 100644 index 0caf700..0000000 --- a/ext/jasmine-webkit-specrunner/test.rb +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env ruby - -require 'fileutils' - -system %{make clean} - -$: << File.expand_path("../../../lib", __FILE__) -require 'qt/qmake' - -result = 0 - -Dir['*_test.pro'].each do |test| - FileUtils.rm_f('jhw-test') - - Qt::Qmake.make!('jasmine-headless-webkit', test) - - if File.file?('jhw-test') - system %{./jhw-test} - if $?.exitstatus != 0 - result = 1 - break - end - else - result = 1 - break - end -end - -Qt::Qmake.make!('jasmine-headless-webkit', 'specrunner.pro') - -exit result diff --git a/jasmine/jasmine.headless-reporter.js b/jasmine/jasmine.headless-reporter.js deleted file mode 100644 index 1a994f2..0000000 --- a/jasmine/jasmine.headless-reporter.js +++ /dev/null @@ -1,231 +0,0 @@ -(function() { - var getSplitName, pauseAndRun; - if (!(typeof jasmine !== "undefined" && jasmine !== null)) { - throw new Error("jasmine not laoded!"); - } - if (window.JHW) { - getSplitName = function(parts) { - parts.push(String(this.description).replace(/[\n\r]/g, ' ')); - return parts; - }; - jasmine.Suite.prototype.getSuiteSplitName = function() { - return this.getSplitName(this.parentSuite ? this.parentSuite.getSuiteSplitName() : []); - }; - jasmine.Spec.prototype.getSpecSplitName = function() { - return this.getSplitName(this.suite.getSuiteSplitName()); - }; - jasmine.Suite.prototype.getSplitName = getSplitName; - jasmine.Spec.prototype.getSplitName = getSplitName; - jasmine.Spec.prototype.getJHWSpecInformation = function() { - var parts, specLineInfo; - parts = this.getSpecSplitName(); - specLineInfo = HeadlessReporterResult.findSpecLine(parts); - if (specLineInfo.file) { - parts.push("" + specLineInfo.file + ":" + specLineInfo.lineNumber); - } else { - parts.push(''); - } - return parts.join("||"); - }; - jasmine.Spec.prototype.fail = function(e) { - var expectationResult, filename, realFilename; - if (e && e.sourceURL && window.CoffeeScriptToFilename) { - filename = e.sourceURL.split('/').pop(); - if (realFilename = window.CoffeeScriptToFilename[filename]) { - e = { - name: e.name, - message: e.message, - lineNumber: "~" + String(e.line), - sourceURL: realFilename - }; - } - } - expectationResult = new jasmine.ExpectationResult({ - passed: false, - message: e ? jasmine.util.formatException(e) : 'Exception', - trace: { - stack: e.stack - } - }); - return this.results_.addResult(expectationResult); - }; - jasmine.NestedResults.isValidSpecLine = function(line) { - return line.match(/^\s*expect/) !== null || line.match(/^\s*return\s*expect/) !== null; - }; - jasmine.NestedResults.parseFunction = function(func) { - var line, lineCount, lines, _i, _len, _ref; - lines = []; - lineCount = 0; - _ref = func.split("\n"); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - line = _ref[_i]; - if (jasmine.NestedResults.isValidSpecLine(line)) { - line = line.replace(/^\s*/, '').replace(/\s*$/, '').replace(/^return\s*/, ''); - lines.push([line, lineCount]); - } - lineCount += 1; - } - return lines; - }; - jasmine.NestedResults.parseAndStore = function(func) { - if (!jasmine.NestedResults.ParsedFunctions[func]) { - jasmine.NestedResults.ParsedFunctions[func] = jasmine.NestedResults.parseFunction(func); - } - return jasmine.NestedResults.ParsedFunctions[func]; - }; - jasmine.NestedResults.ParsedFunctions = []; - if (!jasmine.WaitsBlock.prototype._execute) { - jasmine.WaitsBlock.prototype._execute = jasmine.WaitsBlock.prototype.execute; - jasmine.WaitsForBlock.prototype._execute = jasmine.WaitsForBlock.prototype.execute; - pauseAndRun = function(onComplete) { - JHW.timerPause(); - return this._execute(function() { - JHW.timerDone(); - return onComplete(); - }); - }; - jasmine.WaitsBlock.prototype.execute = pauseAndRun; - jasmine.WaitsForBlock.prototype.execute = pauseAndRun; - jasmine.NestedResults.prototype.addResult_ = jasmine.NestedResults.prototype.addResult; - jasmine.NestedResults.prototype.addResult = function(result) { - result.expectations = []; - result.expectations = jasmine.NestedResults.parseAndStore(arguments.callee.caller.caller.caller.toString()); - return this.addResult_(result); - }; - } - window.HeadlessReporterResult = (function() { - function HeadlessReporterResult(name, splitName) { - this.name = name; - this.splitName = splitName; - this.results = []; - } - HeadlessReporterResult.prototype.addResult = function(message) { - return this.results.push(message); - }; - HeadlessReporterResult.prototype.print = function() { - var bestChoice, output, result, _i, _len, _ref, _results; - output = this.name; - bestChoice = HeadlessReporterResult.findSpecLine(this.splitName); - if (bestChoice.file) { - output += " (" + bestChoice.file + ":" + bestChoice.lineNumber + ")"; - } - JHW.printName(output); - _ref = this.results; - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - result = _ref[_i]; - output = result.message; - if (result.lineNumber) { - output += " (line ~" + (bestChoice.lineNumber + result.lineNumber) + ")\n " + result.line; - } - _results.push(JHW.printResult(output)); - } - return _results; - }; - HeadlessReporterResult.findSpecLine = function(splitName) { - var bestChoice, file, index, lastLine, line, lineNumber, lines, newLineNumberInfo, _i, _len, _ref; - bestChoice = { - accuracy: 0, - file: null, - lineNumber: null - }; - _ref = HeadlessReporterResult.specLineNumbers; - for (file in _ref) { - lines = _ref[file]; - index = 0; - lineNumber = 0; - while (newLineNumberInfo = lines[splitName[index]]) { - if (newLineNumberInfo.length === 0) { - lineNumber = newLineNumberInfo[0]; - } else { - lastLine = null; - for (_i = 0, _len = newLineNumberInfo.length; _i < _len; _i++) { - line = newLineNumberInfo[_i]; - lastLine = line; - if (line > lineNumber) { - break; - } - } - lineNumber = lastLine; - } - index++; - } - if (index > bestChoice.accuracy) { - bestChoice = { - accuracy: index, - file: file, - lineNumber: lineNumber - }; - } - } - return bestChoice; - }; - return HeadlessReporterResult; - })(); - jasmine.HeadlessReporter = (function() { - function HeadlessReporter(callback) { - this.callback = callback != null ? callback : null; - this.results = []; - this.failedCount = 0; - this.length = 0; - } - HeadlessReporter.prototype.reportRunnerResults = function(runner) { - var result, _i, _len, _ref; - if (this.hasError()) { - return; - } - _ref = this.results; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - result = _ref[_i]; - result.print(); - } - if (this.callback) { - this.callback(); - } - return JHW.finishSuite((new Date() - this.startTime) / 1000.0, this.length, this.failedCount); - }; - HeadlessReporter.prototype.reportRunnerStarting = function(runner) { - return this.startTime = new Date(); - }; - HeadlessReporter.prototype.reportSpecResults = function(spec) { - var failureResult, foundLine, result, results, testCount, _i, _len, _ref; - if (this.hasError()) { - return; - } - results = spec.results(); - this.length++; - if (results.passed()) { - return JHW.specPassed(spec.getJHWSpecInformation()); - } else { - JHW.specFailed(spec.getJHWSpecInformation()); - this.failedCount++; - failureResult = new HeadlessReporterResult(spec.getFullName(), spec.getSpecSplitName()); - testCount = 1; - _ref = results.getItems(); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - result = _ref[_i]; - if (result.type === 'expect' && !result.passed_) { - if (foundLine = result.expectations[testCount - 1]) { - result.line = foundLine[0], result.lineNumber = foundLine[1]; - } - failureResult.addResult(result); - } - testCount += 1; - } - return this.results.push(failureResult); - } - }; - HeadlessReporter.prototype.reportSpecStarting = function(spec) { - if (this.hasError()) { - spec.finish(); - return spec.suite.finish(); - } - }; - HeadlessReporter.prototype.reportSuiteResults = function(suite) {}; - HeadlessReporter.prototype.hasError = function() { - return JHW.hasError(); - }; - return HeadlessReporter; - })(); - } -}).call(this); diff --git a/lib/jasmine/files_list.rb b/lib/jasmine/files_list.rb index 72757cd..828637d 100644 --- a/lib/jasmine/files_list.rb +++ b/lib/jasmine/files_list.rb @@ -6,14 +6,30 @@ module Jasmine class FilesList attr_reader :files, :spec_files, :filtered_files, :spec_outside_scope + class << self + def find_vendored_asset_paths(*names) + require 'rubygems' + + raise StandardError.new("A newer version of Rubygems is required to use vendored assets. Please upgrade.") if !Gem::Specification.respond_to?(:map) + all_spec_files.find_all do |file| + names.any? { |name| file["/#{name}.js"] } + end + end + + def all_spec_files + @all_spec_files ||= Gem::Specification.map { |spec| spec.files.find_all { |file| + file["vendor/assets/javascripts"] + }.compact.collect { |file| File.join(spec.gem_dir, file) } }.flatten + end + end + DEFAULT_FILES = [ File.join(Jasmine::Core.path, "jasmine.js"), File.join(Jasmine::Core.path, "jasmine-html.js"), - File.join(Jasmine::Core.path, "jasmine.css"), - Jasmine::Headless.root.join('jasmine/jasmine.headless-reporter.js').to_s, - Jasmine::Headless.root.join('js-lib/jsDump.js').to_s, - Jasmine::Headless.root.join('js-lib/beautify-html.js').to_s - ] + File.join(Jasmine::Core.path, "jasmine.css") + ] + %w{jasmine-extensions intense headless_reporter_result jasmine.HeadlessConsoleReporter jsDump beautify-html}.collect { |name| + Jasmine::Headless.root.join("vendor/assets/javascripts/#{name}.js").to_s + } PLEASE_WAIT_IM_WORKING_TIME = 2 @@ -72,13 +88,10 @@ module Jasmine cache = Jasmine::Headless::CoffeeScriptCache.new(file) source = cache.handle if cache.cached? - %{ - S + %{ - } + window.CSTF['#{File.split(cache.cache_file).last}'] = '#{file}'; + } else %{} end @@ -158,19 +171,6 @@ module Jasmine def expanded_dir(path) Dir[path].collect { |file| File.expand_path(file) } end - - def self.find_vendored_asset_path(name) - require 'rubygems' - - raise StandardError.new("A newer version of Rubygems is required to use vendored assets. Please upgrade.") if !Gem::Specification.respond_to?(:map) - all_spec_files.find_all { |file| file["vendor/assets/javascripts/#{name}.js"] } - end - - def self.all_spec_files - @all_spec_files ||= Gem::Specification.map { |spec| spec.files.find_all { |file| - file["vendor/assets/javascripts"] - }.compact.collect { |file| File.join(spec.gem_dir, file) } }.flatten - end end end 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/lib/jasmine/headless/version.rb b/lib/jasmine/headless/version.rb index 0988e5e..f611b97 100644 --- a/lib/jasmine/headless/version.rb +++ b/lib/jasmine/headless/version.rb @@ -1,5 +1,5 @@ module Jasmine module Headless - VERSION = "0.7.3.1" + VERSION = "0.8.0" end end diff --git a/lib/qt/qmake.rb b/lib/qt/qmake.rb index 0010cc3..b4a3116 100644 --- a/lib/qt/qmake.rb +++ b/lib/qt/qmake.rb @@ -39,11 +39,7 @@ module Qt system command(project_file) - system %{make #{make_options}} - end - - def make_options - "" + system %{make} end # diff --git a/skel/template.html.erb b/skel/template.html.erb index d44a535..05f7038 100644 --- a/skel/template.html.erb +++ b/skel/template.html.erb @@ -3,47 +3,7 @@ Jasmine Test Runner - Generated by jasmine-headless-webkit - + <%= files.join("\n") %> diff --git a/spec/javascripts/headless_reporter_result_spec.coffee b/spec/javascripts/headless_reporter_result_spec.coffee new file mode 100644 index 0000000..2c2d501 --- /dev/null +++ b/spec/javascripts/headless_reporter_result_spec.coffee @@ -0,0 +1,14 @@ +describe 'HeadlessReporterResult', -> + result = null + name = "name" + splitName = "splitName" + message = 'message' + + beforeEach -> + result = new HeadlessReporterResult(name, splitName) + + describe '#addResult', -> + it 'should add a message', -> + result.addResult(message) + + expect(result.results).toEqual([ message ]) diff --git a/spec/javascripts/jasmine.headless-reporter_spec.coffee b/spec/javascripts/jasmine.HeadlessConsoleReporter_spec.coffee similarity index 97% rename from spec/javascripts/jasmine.headless-reporter_spec.coffee rename to spec/javascripts/jasmine.HeadlessConsoleReporter_spec.coffee index f70203e..6696b95 100644 --- a/spec/javascripts/jasmine.headless-reporter_spec.coffee +++ b/spec/javascripts/jasmine.HeadlessConsoleReporter_spec.coffee @@ -12,11 +12,11 @@ describe 'HeadlessReporterResult', -> expect(HeadlessReporterResult.findSpecLine([ 'name', 'of', 'test' ]).lineNumber).toEqual(3) expect(HeadlessReporterResult.findSpecLine([ 'other', 'of', 'test' ]).lineNumber).toEqual(10) -describe 'jasmine.HeadlessReporter', -> +describe 'jasmine.HeadlessConsoleReporter', -> reporter = null beforeEach -> - reporter = new jasmine.HeadlessReporter() + reporter = new jasmine.HeadlessConsoleReporter() it 'should stop running specs if there are errors reported', -> # otherwise it gets really confusing! diff --git a/spec/javascripts/support/jasmine.yml b/spec/javascripts/support/jasmine.yml index de1a551..8d17208 100644 --- a/spec/javascripts/support/jasmine.yml +++ b/spec/javascripts/support/jasmine.yml @@ -1,4 +1,4 @@ -src_files: [ 'jasmine/*.coffee' ] +src_files: [ 'vendor/assets/coffeescripts/*.coffee' ] spec_files: [ 'spec/javascripts/*_spec.coffee' ] src_dir: . spec_dir: . diff --git a/spec/lib/jasmine/files_list_spec.rb b/spec/lib/jasmine/files_list_spec.rb index 4aefbc7..bb39811 100644 --- a/spec/lib/jasmine/files_list_spec.rb +++ b/spec/lib/jasmine/files_list_spec.rb @@ -14,9 +14,12 @@ describe Jasmine::FilesList do File.join(Jasmine::Core.path, "jasmine.js"), File.join(Jasmine::Core.path, "jasmine-html.js"), File.join(Jasmine::Core.path, "jasmine.css"), - File.expand_path('jasmine/jasmine.headless-reporter.js'), - File.expand_path('js-lib/jsDump.js'), - File.expand_path('js-lib/beautify-html.js'), + File.expand_path('vendor/assets/javascripts/jasmine-extensions.js'), + File.expand_path('vendor/assets/javascripts/intense.js'), + File.expand_path('vendor/assets/javascripts/headless_reporter_result.js'), + File.expand_path('vendor/assets/javascripts/jasmine.HeadlessConsoleReporter.js'), + File.expand_path('vendor/assets/javascripts/jsDump.js'), + File.expand_path('vendor/assets/javascripts/beautify-html.js'), ] end end diff --git a/spec/lib/qt/qmake_spec.rb b/spec/lib/qt/qmake_spec.rb index 08438ec..8b7c02f 100644 --- a/spec/lib/qt/qmake_spec.rb +++ b/spec/lib/qt/qmake_spec.rb @@ -138,11 +138,5 @@ describe Qt::Qmake do end end end - - describe '.make_options' do - subject { Qt::Qmake.make_options } - - it { should == "" } - end end diff --git a/vendor/assets/coffeescripts/headless_reporter_result.coffee b/vendor/assets/coffeescripts/headless_reporter_result.coffee new file mode 100644 index 0000000..077b571 --- /dev/null +++ b/vendor/assets/coffeescripts/headless_reporter_result.coffee @@ -0,0 +1,46 @@ +# Try to get the line number of a failed spec +class window.HeadlessReporterResult + constructor: (@name, @splitName) -> + @results = [] + + addResult: (message) -> + @results.push(message) + + print: -> + output = @name.foreground('red') + bestChoice = HeadlessReporterResult.findSpecLine(@splitName) + output += " (#{bestChoice.file}:#{bestChoice.lineNumber})".foreground('blue') if bestChoice.file + + JHW.stdout.puts "\n\n#{output}" + for result in @results + output = result.message.foreground('red') + if result.lineNumber + output += " (line ~#{bestChoice.lineNumber + result.lineNumber})".foreground('red').bright() + JHW.stdout.puts(" " + output) + + if result.line? + JHW.stdout.puts(" #{result.line}".foreground('yellow')) + + @findSpecLine: (splitName) -> + bestChoice = { accuracy: 0, file: null, lineNumber: null } + + for file, lines of HeadlessReporterResult.specLineNumbers + index = 0 + lineNumber = 0 + while newLineNumberInfo = lines[splitName[index]] + if newLineNumberInfo.length == 0 + lineNumber = newLineNumberInfo[0] + else + lastLine = null + for line in newLineNumberInfo + lastLine = line + break if line > lineNumber + + lineNumber = lastLine + + index++ + + if index > bestChoice.accuracy + bestChoice = { accuracy: index, file: file, lineNumber: lineNumber } + + bestChoice diff --git a/vendor/assets/coffeescripts/intense.coffee b/vendor/assets/coffeescripts/intense.coffee new file mode 100644 index 0000000..f24d136 --- /dev/null +++ b/vendor/assets/coffeescripts/intense.coffee @@ -0,0 +1,27 @@ +window.Intense = { + colors: + black: 0 + red: 1 + green: 2 + yellow: 3 + blue: 4 + magenta: 5 + cyan: 6 + white: 7 + methods: + foreground: (color) -> + if Intense.useColors + "\033[3#{Intense.colors[color]}m#{this}\033[0m" + else + this + bright: -> + if Intense.useColors + "\033[1m#{this}\033[0m" + else + this + useColors: true +} + +for method, code of Intense.methods + String.prototype[method] = code + diff --git a/jasmine/jasmine.headless-reporter.coffee b/vendor/assets/coffeescripts/jasmine-extensions.coffee similarity index 52% rename from jasmine/jasmine.headless-reporter.coffee rename to vendor/assets/coffeescripts/jasmine-extensions.coffee index 8db83f4..f7e8ce6 100644 --- a/jasmine/jasmine.headless-reporter.coffee +++ b/vendor/assets/coffeescripts/jasmine-extensions.coffee @@ -2,7 +2,7 @@ if !jasmine? throw new Error("jasmine not laoded!") if window.JHW -# Jasmine extensions + # Jasmine extensions getSplitName = (parts) -> parts.push(String(@description).replace(/[\n\r]/g, ' ')) parts @@ -84,92 +84,3 @@ if window.JHW result.expectations = jasmine.NestedResults.parseAndStore(arguments.callee.caller.caller.caller.toString()) this.addResult_(result) - -# Try to get the line number of a failed spec - class window.HeadlessReporterResult - constructor: (@name, @splitName) -> - @results = [] - addResult: (message) -> - @results.push(message) - print: -> - output = @name - bestChoice = HeadlessReporterResult.findSpecLine(@splitName) - output += " (#{bestChoice.file}:#{bestChoice.lineNumber})" if bestChoice.file - - JHW.printName(output) - for result in @results - output = result.message - if result.lineNumber - output += " (line ~#{bestChoice.lineNumber + result.lineNumber})\n #{result.line}" - JHW.printResult(output) - @findSpecLine: (splitName) -> - bestChoice = { accuracy: 0, file: null, lineNumber: null } - - for file, lines of HeadlessReporterResult.specLineNumbers - index = 0 - lineNumber = 0 - while newLineNumberInfo = lines[splitName[index]] - if newLineNumberInfo.length == 0 - lineNumber = newLineNumberInfo[0] - else - lastLine = null - for line in newLineNumberInfo - lastLine = line - break if line > lineNumber - - lineNumber = lastLine - - index++ - - if index > bestChoice.accuracy - bestChoice = { accuracy: index, file: file, lineNumber: lineNumber } - - bestChoice - -# The reporter itself. - class jasmine.HeadlessReporter - constructor: (@callback = null) -> - @results = [] - @failedCount = 0 - @length = 0 - reportRunnerResults: (runner) -> - return if this.hasError() - - for result in @results - result.print() - - this.callback() if @callback - JHW.finishSuite((new Date() - @startTime) / 1000.0, @length, @failedCount) - - reportRunnerStarting: (runner) -> - @startTime = new Date() - - reportSpecResults: (spec) -> - return if this.hasError() - - results = spec.results() - @length++ - if results.passed() - JHW.specPassed(spec.getJHWSpecInformation()) - else - JHW.specFailed(spec.getJHWSpecInformation()) - @failedCount++ - failureResult = new HeadlessReporterResult(spec.getFullName(), spec.getSpecSplitName()) - testCount = 1 - for result in results.getItems() - if result.type == 'expect' and !result.passed_ - if foundLine = result.expectations[testCount - 1] - [ result.line, result.lineNumber ] = foundLine - failureResult.addResult(result) - testCount += 1 - @results.push(failureResult) - - reportSpecStarting: (spec) -> - if this.hasError() - spec.finish() - spec.suite.finish() - - reportSuiteResults: (suite) -> - hasError: -> - JHW.hasError() - diff --git a/vendor/assets/coffeescripts/jasmine.HeadlessConsoleReporter.coffee b/vendor/assets/coffeescripts/jasmine.HeadlessConsoleReporter.coffee new file mode 100644 index 0000000..58638c2 --- /dev/null +++ b/vendor/assets/coffeescripts/jasmine.HeadlessConsoleReporter.coffee @@ -0,0 +1,85 @@ +if !jasmine? + throw new Error("jasmine not loaded!") + +class jasmine.HeadlessConsoleReporter + constructor: (@callback = null) -> + @results = [] + @failedCount = 0 + @length = 0 + + reportRunnerResults: (runner) -> + return if this.hasError() + + runtime = (new Date() - @startTime) / 1000.0 + + JHW.stdout.print("\n") + + resultLine = this._formatResultLine(runtime) + + if @failedCount == 0 + JHW.stdout.puts("PASS: #{resultLine}".foreground('green')) + else + JHW.stdout.puts("FAIL: #{resultLine}".foreground('red')) + JHW.hasSpecFailure() + + output = "TOTAL||#{@length}||#{@failedCount}||#{runtime}||#{if JHW._hasErrors then "T" else "F"}" + + JHW.report.puts(output) + result.print() for result in @results + + if window.JHW + window.onbeforeunload = null + + JHW.finishSuite() + + reportRunnerStarting: (runner) -> + @startTime = new Date() + JHW.stdout.puts("\nRunning Jasmine specs...".bright()) + + reportSpecResults: (spec) -> + return if this.hasError() + + results = spec.results() + + @length++ + if results.passed() + JHW.stdout.print('.'.foreground('green')) + JHW.report.puts("PASS||" + spec.getJHWSpecInformation()) + else + JHW.stdout.print('F'.foreground('red')) + JHW.report.puts("FAIL||" + spec.getJHWSpecInformation()) + + @failedCount++ + failureResult = new HeadlessReporterResult(spec.getFullName(), spec.getSpecSplitName()) + testCount = 1 + + for result in results.getItems() + if result.type == 'expect' and !result.passed_ + if foundLine = result.expectations[testCount - 1] + [ result.line, result.lineNumber ] = foundLine + failureResult.addResult(result) + testCount += 1 + @results.push(failureResult) + + reportSpecStarting: (spec) -> + if this.hasError() + spec.finish() + spec.suite.finish() + + reportSuiteResults: (suite) -> + hasError: -> + JHW._hasErrors + + _formatResultLine: (runtime) -> + line = [] + line.push(@length) + line.push((if @length == 1 then "test" else "tests") + ',') + + line.push(@failedCount) + line.push((if @failedCount == 1 then "failure" else "failures") + ',') + + line.push(runtime) + line.push((if runtime == 1.0 then "sec" else "secs") + '.') + + line.join(' ') + diff --git a/vendor/assets/coffeescripts/prolog.coffee b/vendor/assets/coffeescripts/prolog.coffee new file mode 100644 index 0000000..75479c9 --- /dev/null +++ b/vendor/assets/coffeescripts/prolog.coffee @@ -0,0 +1,73 @@ +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) -> + e = e || window.event + + JHW.hasError() + JHW.stdout.puts('The code tried to leave the test page. Check for unhandled form submits and link clicks.') + + if e + e.returnValue = 'string' + + return 'string' + + window.confirm = (message) -> + JHW.stderr.puts("#{"[confirm]".foreground('red')} jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm. Returning true.") + true + + window.alert = (message) -> + JHW.stderr.puts("[alert] ".foreground('red') + message) + + JHW._hasErrors = false + JHW._handleError = (message, lineNumber, sourceURL) -> + JHW.stderr.puts(message) + JHW._hasErrors = true + false + + JHW._setColors = (useColors) -> + Intense.useColors = useColors + + createHandle = (handle) -> + JHW[handle] = + print: (content) -> JHW.print(handle, content) + puts: (content) -> JHW.print(handle, content + "\n") + + createHandle(handle) for handle in [ 'stdout', 'stderr', 'report' ] + + JHW._usedConsole = false + + JHW.log = (msg) -> + JHW.hasUsedConsole() + JHW.report.puts("CONSOLE||#{msg}") + JHW._usedConsole = true + JHW.stdout.puts(msg) + +window.CoffeeScriptToFilename = {} +window.CSTF = window.CoffeeScriptToFilename + diff --git a/js-lib/beautify-html.js b/vendor/assets/javascripts/beautify-html.js similarity index 100% rename from js-lib/beautify-html.js rename to vendor/assets/javascripts/beautify-html.js diff --git a/vendor/assets/javascripts/headless_reporter_result.js b/vendor/assets/javascripts/headless_reporter_result.js new file mode 100644 index 0000000..14ba347 --- /dev/null +++ b/vendor/assets/javascripts/headless_reporter_result.js @@ -0,0 +1,72 @@ +(function() { + window.HeadlessReporterResult = (function() { + function HeadlessReporterResult(name, splitName) { + this.name = name; + this.splitName = splitName; + this.results = []; + } + HeadlessReporterResult.prototype.addResult = function(message) { + return this.results.push(message); + }; + HeadlessReporterResult.prototype.print = function() { + var bestChoice, output, result, _i, _len, _ref, _results; + output = this.name.foreground('red'); + bestChoice = HeadlessReporterResult.findSpecLine(this.splitName); + if (bestChoice.file) { + output += (" (" + bestChoice.file + ":" + bestChoice.lineNumber + ")").foreground('blue'); + } + JHW.stdout.puts("\n\n" + output); + _ref = this.results; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + result = _ref[_i]; + output = result.message.foreground('red'); + if (result.lineNumber) { + output += (" (line ~" + (bestChoice.lineNumber + result.lineNumber) + ")").foreground('red').bright(); + } + JHW.stdout.puts(" " + output); + _results.push(result.line != null ? JHW.stdout.puts((" " + result.line).foreground('yellow')) : void 0); + } + return _results; + }; + HeadlessReporterResult.findSpecLine = function(splitName) { + var bestChoice, file, index, lastLine, line, lineNumber, lines, newLineNumberInfo, _i, _len, _ref; + bestChoice = { + accuracy: 0, + file: null, + lineNumber: null + }; + _ref = HeadlessReporterResult.specLineNumbers; + for (file in _ref) { + lines = _ref[file]; + index = 0; + lineNumber = 0; + while (newLineNumberInfo = lines[splitName[index]]) { + if (newLineNumberInfo.length === 0) { + lineNumber = newLineNumberInfo[0]; + } else { + lastLine = null; + for (_i = 0, _len = newLineNumberInfo.length; _i < _len; _i++) { + line = newLineNumberInfo[_i]; + lastLine = line; + if (line > lineNumber) { + break; + } + } + lineNumber = lastLine; + } + index++; + } + if (index > bestChoice.accuracy) { + bestChoice = { + accuracy: index, + file: file, + lineNumber: lineNumber + }; + } + } + return bestChoice; + }; + return HeadlessReporterResult; + })(); +}).call(this); diff --git a/vendor/assets/javascripts/intense.js b/vendor/assets/javascripts/intense.js new file mode 100644 index 0000000..2e5fffd --- /dev/null +++ b/vendor/assets/javascripts/intense.js @@ -0,0 +1,37 @@ +(function() { + var code, method, _ref; + window.Intense = { + colors: { + black: 0, + red: 1, + green: 2, + yellow: 3, + blue: 4, + magenta: 5, + cyan: 6, + white: 7 + }, + methods: { + foreground: function(color) { + if (Intense.useColors) { + return "\033[3" + Intense.colors[color] + "m" + this + "\033[0m"; + } else { + return this; + } + }, + bright: function() { + if (Intense.useColors) { + return "\033[1m" + this + "\033[0m"; + } else { + return this; + } + } + }, + useColors: true + }; + _ref = Intense.methods; + for (method in _ref) { + code = _ref[method]; + String.prototype[method] = code; + } +}).call(this); diff --git a/vendor/assets/javascripts/jasmine-extensions.js b/vendor/assets/javascripts/jasmine-extensions.js new file mode 100644 index 0000000..d7a64e0 --- /dev/null +++ b/vendor/assets/javascripts/jasmine-extensions.js @@ -0,0 +1,97 @@ +(function() { + var getSplitName, pauseAndRun; + if (!(typeof jasmine !== "undefined" && jasmine !== null)) { + throw new Error("jasmine not laoded!"); + } + if (window.JHW) { + getSplitName = function(parts) { + parts.push(String(this.description).replace(/[\n\r]/g, ' ')); + return parts; + }; + jasmine.Suite.prototype.getSuiteSplitName = function() { + return this.getSplitName(this.parentSuite ? this.parentSuite.getSuiteSplitName() : []); + }; + jasmine.Spec.prototype.getSpecSplitName = function() { + return this.getSplitName(this.suite.getSuiteSplitName()); + }; + jasmine.Suite.prototype.getSplitName = getSplitName; + jasmine.Spec.prototype.getSplitName = getSplitName; + jasmine.Spec.prototype.getJHWSpecInformation = function() { + var parts, specLineInfo; + parts = this.getSpecSplitName(); + specLineInfo = HeadlessReporterResult.findSpecLine(parts); + if (specLineInfo.file) { + parts.push("" + specLineInfo.file + ":" + specLineInfo.lineNumber); + } else { + parts.push(''); + } + return parts.join("||"); + }; + jasmine.Spec.prototype.fail = function(e) { + var expectationResult, filename, realFilename; + if (e && e.sourceURL && window.CoffeeScriptToFilename) { + filename = e.sourceURL.split('/').pop(); + if (realFilename = window.CoffeeScriptToFilename[filename]) { + e = { + name: e.name, + message: e.message, + lineNumber: "~" + String(e.line), + sourceURL: realFilename + }; + } + } + expectationResult = new jasmine.ExpectationResult({ + passed: false, + message: e ? jasmine.util.formatException(e) : 'Exception', + trace: { + stack: e.stack + } + }); + return this.results_.addResult(expectationResult); + }; + jasmine.NestedResults.isValidSpecLine = function(line) { + return line.match(/^\s*expect/) !== null || line.match(/^\s*return\s*expect/) !== null; + }; + jasmine.NestedResults.parseFunction = function(func) { + var line, lineCount, lines, _i, _len, _ref; + lines = []; + lineCount = 0; + _ref = func.split("\n"); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + line = _ref[_i]; + if (jasmine.NestedResults.isValidSpecLine(line)) { + line = line.replace(/^\s*/, '').replace(/\s*$/, '').replace(/^return\s*/, ''); + lines.push([line, lineCount]); + } + lineCount += 1; + } + return lines; + }; + jasmine.NestedResults.parseAndStore = function(func) { + if (!jasmine.NestedResults.ParsedFunctions[func]) { + jasmine.NestedResults.ParsedFunctions[func] = jasmine.NestedResults.parseFunction(func); + } + return jasmine.NestedResults.ParsedFunctions[func]; + }; + jasmine.NestedResults.ParsedFunctions = []; + if (!jasmine.WaitsBlock.prototype._execute) { + jasmine.WaitsBlock.prototype._execute = jasmine.WaitsBlock.prototype.execute; + jasmine.WaitsForBlock.prototype._execute = jasmine.WaitsForBlock.prototype.execute; + pauseAndRun = function(onComplete) { + JHW.timerPause(); + return this._execute(function() { + JHW.timerDone(); + return onComplete(); + }); + }; + jasmine.WaitsBlock.prototype.execute = pauseAndRun; + jasmine.WaitsForBlock.prototype.execute = pauseAndRun; + jasmine.NestedResults.prototype.addResult_ = jasmine.NestedResults.prototype.addResult; + jasmine.NestedResults.prototype.addResult = function(result) { + result.expectations = []; + result.expectations = jasmine.NestedResults.parseAndStore(arguments.callee.caller.caller.caller.toString()); + return this.addResult_(result); + }; + } + } +}).call(this); diff --git a/vendor/assets/javascripts/jasmine.HeadlessConsoleReporter.js b/vendor/assets/javascripts/jasmine.HeadlessConsoleReporter.js new file mode 100644 index 0000000..2a3e934 --- /dev/null +++ b/vendor/assets/javascripts/jasmine.HeadlessConsoleReporter.js @@ -0,0 +1,95 @@ +(function() { + if (!(typeof jasmine !== "undefined" && jasmine !== null)) { + throw new Error("jasmine not loaded!"); + } + jasmine.HeadlessConsoleReporter = (function() { + function HeadlessConsoleReporter(callback) { + this.callback = callback != null ? callback : null; + this.results = []; + this.failedCount = 0; + this.length = 0; + } + HeadlessConsoleReporter.prototype.reportRunnerResults = function(runner) { + var output, result, resultLine, runtime, _i, _len, _ref; + if (this.hasError()) { + return; + } + runtime = (new Date() - this.startTime) / 1000.0; + JHW.stdout.print("\n"); + resultLine = this._formatResultLine(runtime); + if (this.failedCount === 0) { + JHW.stdout.puts(("PASS: " + resultLine).foreground('green')); + } else { + JHW.stdout.puts(("FAIL: " + resultLine).foreground('red')); + JHW.hasSpecFailure(); + } + output = "TOTAL||" + this.length + "||" + this.failedCount + "||" + runtime + "||" + (JHW._hasErrors ? "T" : "F"); + JHW.report.puts(output); + _ref = this.results; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + result = _ref[_i]; + result.print(); + } + if (window.JHW) { + window.onbeforeunload = null; + } + return JHW.finishSuite(); + }; + HeadlessConsoleReporter.prototype.reportRunnerStarting = function(runner) { + this.startTime = new Date(); + return JHW.stdout.puts("\nRunning Jasmine specs...".bright()); + }; + HeadlessConsoleReporter.prototype.reportSpecResults = function(spec) { + var failureResult, foundLine, result, results, testCount, _i, _len, _ref; + if (this.hasError()) { + return; + } + results = spec.results(); + this.length++; + if (results.passed()) { + JHW.stdout.print('.'.foreground('green')); + return JHW.report.puts("PASS||" + spec.getJHWSpecInformation()); + } else { + JHW.stdout.print('F'.foreground('red')); + JHW.report.puts("FAIL||" + spec.getJHWSpecInformation()); + this.failedCount++; + failureResult = new HeadlessReporterResult(spec.getFullName(), spec.getSpecSplitName()); + testCount = 1; + _ref = results.getItems(); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + result = _ref[_i]; + if (result.type === 'expect' && !result.passed_) { + if (foundLine = result.expectations[testCount - 1]) { + result.line = foundLine[0], result.lineNumber = foundLine[1]; + } + failureResult.addResult(result); + } + testCount += 1; + } + return this.results.push(failureResult); + } + }; + HeadlessConsoleReporter.prototype.reportSpecStarting = function(spec) { + if (this.hasError()) { + spec.finish(); + return spec.suite.finish(); + } + }; + HeadlessConsoleReporter.prototype.reportSuiteResults = function(suite) {}; + HeadlessConsoleReporter.prototype.hasError = function() { + return JHW._hasErrors; + }; + HeadlessConsoleReporter.prototype._formatResultLine = function(runtime) { + var line; + line = []; + line.push(this.length); + line.push((this.length === 1 ? "test" : "tests") + ','); + line.push(this.failedCount); + line.push((this.failedCount === 1 ? "failure" : "failures") + ','); + line.push(runtime); + line.push((runtime === 1.0 ? "sec" : "secs") + '.'); + return line.join(' '); + }; + return HeadlessConsoleReporter; + })(); +}).call(this); diff --git a/js-lib/jsDump.js b/vendor/assets/javascripts/jsDump.js similarity index 100% rename from js-lib/jsDump.js rename to vendor/assets/javascripts/jsDump.js diff --git a/vendor/assets/javascripts/prolog.js b/vendor/assets/javascripts/prolog.js new file mode 100644 index 0000000..2fd358b --- /dev/null +++ b/vendor/assets/javascripts/prolog.js @@ -0,0 +1,89 @@ +(function() { + var createHandle, handle, _i, _len, _ref; + if (window.JHW) { + window.console = { + log: function(data) { + var dump, useJsDump; + if (typeof jQuery !== 'undefined' && data instanceof jQuery) { + return 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) { + return JHW.log(dump); + } else { + return JHW.log("jsDump: " + dump); + } + } + } + }, + pp: function(data) { + return JHW.log(jasmine ? jasmine.pp(data) : console.log(data)); + }, + peek: function(data) { + console.log(data); + return data; + } + }; + window.onbeforeunload = function(e) { + e = e || window.event; + JHW.hasError(); + JHW.stdout.puts('The code tried to leave the test page. Check for unhandled form submits and link clicks.'); + if (e) { + e.returnValue = 'string'; + } + return 'string'; + }; + window.confirm = function(message) { + JHW.stderr.puts("" + ("[confirm]".foreground('red')) + " jasmine-headless-webkit can't handle confirm() yet! You should mock window.confirm. Returning true."); + return true; + }; + window.alert = function(message) { + return JHW.stderr.puts("[alert] ".foreground('red') + message); + }; + JHW._hasErrors = false; + JHW._handleError = function(message, lineNumber, sourceURL) { + JHW.stderr.puts(message); + JHW._hasErrors = true; + return false; + }; + JHW._setColors = function(useColors) { + return Intense.useColors = useColors; + }; + createHandle = function(handle) { + return JHW[handle] = { + print: function(content) { + return JHW.print(handle, content); + }, + puts: function(content) { + return JHW.print(handle, content + "\n"); + } + }; + }; + _ref = ['stdout', 'stderr', 'report']; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + handle = _ref[_i]; + createHandle(handle); + } + JHW._usedConsole = false; + JHW.log = function(msg) { + JHW.hasUsedConsole(); + JHW.report.puts("CONSOLE||" + msg); + JHW._usedConsole = true; + return JHW.stdout.puts(msg); + }; + } + window.CoffeeScriptToFilename = {}; + window.CSTF = window.CoffeeScriptToFilename; +}).call(this);