From a18100bb71e58aa91f79f26634899093d4632877 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 21 Nov 2011 14:13:15 -0500 Subject: [PATCH] move the jquery console test to the right spot --- spec/jasmine/console_log/console_log_spec.js | 7 ----- spec/javascripts/console.log_spec.coffee | 13 ++++++++++ spec/javascripts/support/jasmine.yml | 5 +++- .../javascripts/headless_reporter_result.js | 19 +++++++++----- vendor/assets/javascripts/intense.js | 3 +++ .../assets/javascripts/jasmine-extensions.js | 3 +++ .../jasmine.HeadlessConsoleReporter.js | 26 +++++++++++-------- vendor/assets/javascripts/prolog.js | 8 +++--- 8 files changed, 56 insertions(+), 28 deletions(-) create mode 100644 spec/javascripts/console.log_spec.coffee diff --git a/spec/jasmine/console_log/console_log_spec.js b/spec/jasmine/console_log/console_log_spec.js index b31345b..471396c 100644 --- a/spec/jasmine/console_log/console_log_spec.js +++ b/spec/jasmine/console_log/console_log_spec.js @@ -3,12 +3,5 @@ describe('console.log', function() { console.log("hello"); expect(success).toEqual(1); }); - - it("wont eat my precious jqueries", function() { - var d = $('
b
'); - expect(d.find('#inner').length).toBe(1); - console.log(d.find('#inner')); - expect(d.find('#inner').length).toBe(1); - }); }); diff --git a/spec/javascripts/console.log_spec.coffee b/spec/javascripts/console.log_spec.coffee new file mode 100644 index 0000000..cc1820d --- /dev/null +++ b/spec/javascripts/console.log_spec.coffee @@ -0,0 +1,13 @@ +describe 'console.log', -> + it 'should not eat my precious jqueries', -> + _log = JHW.log + + JHW.log = -> + + d = $('
b
'); + expect(d.find('#inner').length).toBe(1); + console.log(d.find('#inner')); + expect(d.find('#inner').length).toBe(1); + + JHW.log = _log + diff --git a/spec/javascripts/support/jasmine.yml b/spec/javascripts/support/jasmine.yml index 8d17208..fdbbc4c 100644 --- a/spec/javascripts/support/jasmine.yml +++ b/spec/javascripts/support/jasmine.yml @@ -1,4 +1,7 @@ -src_files: [ 'vendor/assets/coffeescripts/*.coffee' ] +src_files: + - 'spec/javascripts/support/jquery-1.6.2.min.js' + - 'vendor/assets/coffeescripts/*.coffee' + spec_files: [ 'spec/javascripts/*_spec.coffee' ] src_dir: . spec_dir: . diff --git a/vendor/assets/javascripts/headless_reporter_result.js b/vendor/assets/javascripts/headless_reporter_result.js index 14ba347..92ec7b9 100644 --- a/vendor/assets/javascripts/headless_reporter_result.js +++ b/vendor/assets/javascripts/headless_reporter_result.js @@ -1,13 +1,16 @@ -(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'); @@ -25,10 +28,15 @@ 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); + if (result.line != null) { + _results.push(JHW.stdout.puts((" " + result.line).foreground('yellow'))); + } else { + _results.push(void 0); + } } return _results; }; + HeadlessReporterResult.findSpecLine = function(splitName) { var bestChoice, file, index, lastLine, line, lineNumber, lines, newLineNumberInfo, _i, _len, _ref; bestChoice = { @@ -49,9 +57,7 @@ for (_i = 0, _len = newLineNumberInfo.length; _i < _len; _i++) { line = newLineNumberInfo[_i]; lastLine = line; - if (line > lineNumber) { - break; - } + if (line > lineNumber) break; } lineNumber = lastLine; } @@ -67,6 +73,7 @@ } return bestChoice; }; + return HeadlessReporterResult; + })(); -}).call(this); diff --git a/vendor/assets/javascripts/intense.js b/vendor/assets/javascripts/intense.js index 2e5fffd..6d885a1 100644 --- a/vendor/assets/javascripts/intense.js +++ b/vendor/assets/javascripts/intense.js @@ -1,5 +1,6 @@ (function() { var code, method, _ref; + window.Intense = { colors: { black: 0, @@ -29,9 +30,11 @@ }, 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 index 6464dd3..c9b4a93 100644 --- a/vendor/assets/javascripts/jasmine-extensions.js +++ b/vendor/assets/javascripts/jasmine-extensions.js @@ -1,8 +1,10 @@ (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, ' ')); @@ -98,4 +100,5 @@ }; } } + }).call(this); diff --git a/vendor/assets/javascripts/jasmine.HeadlessConsoleReporter.js b/vendor/assets/javascripts/jasmine.HeadlessConsoleReporter.js index be8f10b..ea1d365 100644 --- a/vendor/assets/javascripts/jasmine.HeadlessConsoleReporter.js +++ b/vendor/assets/javascripts/jasmine.HeadlessConsoleReporter.js @@ -1,19 +1,20 @@ -(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; - } + if (this.hasError()) return; runtime = (new Date() - this.startTime) / 1000.0; JHW.stdout.print("\n"); resultLine = this._formatResultLine(runtime); @@ -30,20 +31,18 @@ result = _ref[_i]; result.print(); } - if (window.JHW) { - window.onbeforeunload = null; - } + 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; - } + if (this.hasError()) return; JHW.ping(); results = spec.results(); this.length++; @@ -70,16 +69,20 @@ 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 = []; @@ -91,6 +94,7 @@ line.push((runtime === 1.0 ? "sec" : "secs") + '.'); return line.join(' '); }; + return HeadlessConsoleReporter; + })(); -}).call(this); diff --git a/vendor/assets/javascripts/prolog.js b/vendor/assets/javascripts/prolog.js index 8fe9b77..733c35e 100644 --- a/vendor/assets/javascripts/prolog.js +++ b/vendor/assets/javascripts/prolog.js @@ -1,5 +1,6 @@ (function() { var createHandle, handle, _i, _len, _ref; + if (window.JHW) { window.console = { log: function(data) { @@ -40,9 +41,7 @@ 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'; - } + if (e) e.returnValue = 'string'; return 'string'; }; window.confirm = function(message) { @@ -84,6 +83,9 @@ return JHW.stdout.puts(msg); }; } + window.CoffeeScriptToFilename = {}; + window.CSTF = window.CoffeeScriptToFilename; + }).call(this);