diff --git a/Gemfile b/Gemfile index c16218b..8365077 100644 --- a/Gemfile +++ b/Gemfile @@ -12,3 +12,4 @@ gem 'guard-coffeescript' gem 'growl' gem 'rake', '0.8.7' gem 'mocha', '0.9.12' +gem 'guard-jasmine-headless-webkit' diff --git a/ext/jasmine-webkit-specrunner/HeadlessSpecRunner/Runner.cpp b/ext/jasmine-webkit-specrunner/HeadlessSpecRunner/Runner.cpp index 2ec04d1..d778fb1 100644 --- a/ext/jasmine-webkit-specrunner/HeadlessSpecRunner/Runner.cpp +++ b/ext/jasmine-webkit-specrunner/HeadlessSpecRunner/Runner.cpp @@ -83,6 +83,10 @@ namespace HeadlessSpecRunner { if (showColors) std::cout << "\033[0;32m"; } + bool Runner::hasError() { + return hasErrors; + } + void Runner::yellow() { if (showColors) std::cout << "\033[0;33m"; diff --git a/ext/jasmine-webkit-specrunner/HeadlessSpecRunner/Runner.h b/ext/jasmine-webkit-specrunner/HeadlessSpecRunner/Runner.h index 46d3bf7..5ff0e0a 100644 --- a/ext/jasmine-webkit-specrunner/HeadlessSpecRunner/Runner.h +++ b/ext/jasmine-webkit-specrunner/HeadlessSpecRunner/Runner.h @@ -21,6 +21,7 @@ namespace HeadlessSpecRunner { void go(); public slots: void log(const QString &msg); + bool hasError(); void leavePageAttempt(const QString &msg); void specPassed(); void specFailed(const QString &specDetail); diff --git a/jasmine/jasmine.headless-reporter.coffee b/jasmine/jasmine.headless-reporter.coffee index 45ec549..74517e1 100644 --- a/jasmine/jasmine.headless-reporter.coffee +++ b/jasmine/jasmine.headless-reporter.coffee @@ -54,6 +54,8 @@ class jasmine.HeadlessReporter @failedCount = 0 @length = 0 reportRunnerResults: (runner) -> + return if this.hasError() + for result in @results result.print() @@ -62,6 +64,8 @@ class jasmine.HeadlessReporter reportRunnerStarting: (runner) -> @startTime = new Date() reportSpecResults: (spec) -> + return if this.hasError() + results = spec.results() @length++ if results.passed() @@ -75,4 +79,10 @@ class jasmine.HeadlessReporter failureResult.addResult(result.message) @results.push(failureResult) reportSpecStarting: (spec) -> + if this.hasError() + spec.finish() + spec.suite.finish() reportSuiteResults: (suite) -> + hasError: -> + JHW.hasError() + diff --git a/jasmine/jasmine.headless-reporter.js b/jasmine/jasmine.headless-reporter.js index b95b23c..574b632 100644 --- a/jasmine/jasmine.headless-reporter.js +++ b/jasmine/jasmine.headless-reporter.js @@ -88,6 +88,9 @@ } 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]; @@ -103,6 +106,9 @@ }; HeadlessReporter.prototype.reportSpecResults = function(spec) { var failureResult, result, results, _i, _len, _ref; + if (this.hasError()) { + return; + } results = spec.results(); this.length++; if (results.passed()) { @@ -121,8 +127,16 @@ return this.results.push(failureResult); } }; - HeadlessReporter.prototype.reportSpecStarting = function(spec) {}; + 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/spec/javascripts/jasmine.headless-reporter_spec.coffee b/spec/javascripts/jasmine.headless-reporter_spec.coffee index 4a54c12..e58b911 100644 --- a/spec/javascripts/jasmine.headless-reporter_spec.coffee +++ b/spec/javascripts/jasmine.headless-reporter_spec.coffee @@ -14,3 +14,25 @@ describe 'HeadlessReporterResult', -> result = new HeadlessReporterResult('test', [ 'other', 'of', 'test' ]) expect(result._findSpecLine().lineNumber).toEqual(10) + +describe 'jasmine.HeadlessReporter', -> + reporter = null + + beforeEach -> + reporter = new jasmine.HeadlessReporter() + + it 'should stop running specs if there are errors reported', -> + # otherwise it gets really confusing! + + suite = { finish: -> null } + spec = new jasmine.Spec("env", suite, "test") + + spyOn(reporter, 'hasError').andReturn(true) + spyOn(spec, 'finish') + spyOn(suite, 'finish') + + reporter.reportSpecStarting(spec) + + expect(spec.finish).toHaveBeenCalled() + expect(suite.finish).toHaveBeenCalled() +