Skip to content

Commit

Permalink
fix first test #10
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaudan committed Jan 24, 2015
1 parent 44cfffa commit bf55f80
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 38 deletions.
41 changes: 21 additions & 20 deletions spec/helpers/test-helper.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ equalOrMatch = (actual, expected) ->

addMatchers = ->
beforeEach ->
@addMatchers
contains: (sequence) ->
sequence = [sequence] unless typeIsArray sequence
i = 0
while i < @actual.length - sequence.length + 1
j = 0
while j < sequence.length && equalOrMatch(@actual[i + j], sequence[j])
j++
return true if j == sequence.length
i++
false
jasmine.addMatchers
contains: ->
compare: (actual, sequence) ->
sequence = [sequence] unless typeIsArray sequence
i = 0
while i < actual.length - sequence.length + 1
j = 0
while j < sequence.length && equalOrMatch(actual[i + j], sequence[j])
j++
return pass: true if j == sequence.length
i++
pass: false

class Test
constructor: (@reporter, @testFn) ->
Expand All @@ -42,21 +43,22 @@ class Test

run: ->
env = new FakeEnv(@testFn)
@reporter.reportRunnerStarting()
@reporter.jasmineStarted()

for suite in env.queue
@execSuite suite

@reporter.reportRunnerResults()
@reporter.jasmineDone()

execSuite: (suite) ->
@reporter.suiteStarted()
for item in suite.queue
if @isSpec(item)
@reporter.reportSpecStarting(item)
@reporter.reportSpecResults(item)
@reporter.specStarted(item)
@reporter.specDone(item)
else
@execSuite item
@reporter.reportSuiteResults()
@reporter.suiteDone()

isSpec: (it) -> it.suite != undefined

Expand Down Expand Up @@ -88,8 +90,7 @@ class Suite

class Spec
constructor: (@env, @suite, @description, fn) ->
@success = false
@skipped = false
@status = ''
@items = []
@id = @env.nextId++
fn.apply(@)
Expand All @@ -101,11 +102,11 @@ class Spec
skipped: @skipped

passed: (message = '') ->
@success = true
@status = 'passed'
@items.push {message, passed: -> true}

failed: (message = '') ->
@success = false
@status = 'failed'
@items.push {message, trace: {stack: 'Error: Expectation\n{Stacktrace}'}, passed: -> false}

global.Test = Test
Expand Down
2 changes: 1 addition & 1 deletion spec/jasmine-spec-reporter.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe 'spec reporter', ->
@reporter = new SpecReporter()

describe 'when spec', ->
it 'should report success', ->
fit 'should report success', ->
expect(new Test(@reporter,->
@describe 'suite', ->
@it 'successful spec', ->
Expand Down
35 changes: 19 additions & 16 deletions src/jasmine-spec-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,35 @@ function initProcessors(options) {
}

SpecReporter.prototype = {
reportRunnerStarting: function () {
jasmineStarted: function () {
this.started = true;
this.display.log('Spec started');
this.metrics.start();
},

reportRunnerResults: function (runner) {
jasmineDone: function (runner) {
this.metrics.stop();
this.display.summary(this.metrics);
this.finished = true;
},

reportSuiteResults: function (suite) {
suiteStarted: function (suite) {
},

suiteDone: function (suite) {
this.display.suiteResults(suite);
},

reportSpecStarting: function (spec) {
specStarted: function (spec) {
this.metrics.startSpec();
},

reportSpecResults: function (spec) {
specDone: function (spec) {
this.metrics.stopSpec(spec);
if (spec.results().skipped) {
if (spec.status == 'pending') {
this.metrics.skippedSpecs++;
this.display.skipped(spec);
} else if (spec.results().passed()) {
} else if (spec.status == 'passed') {
this.metrics.successfulSpecs++;
this.display.successful(spec);
} else {
Expand All @@ -86,16 +89,16 @@ SpecReporter.prototype = {
}
},

jasmineStarted: function () {
reportRunnerStarting: function () {
this.display.newLine();
this.display.log("*******************************************************************");
this.display.log("* Oops! *");
this.display.log("* jasmine-spec-reporter 1.x is not compatible with jasmine > 1.x. *");
this.display.log("* *");
this.display.log("* Please consider using jasmine-spec-reporter >= 2.0.0. *");
this.display.log("* *");
this.display.log("* npm install jasmine-spec-reporter@latest --save-dev *");
this.display.log("*******************************************************************");
this.display.log('*******************************************************************');
this.display.log('* Oops! *');
this.display.log('* jasmine-spec-reporter 2.x is not compatible with jasmine < 2.x. *');
this.display.log('* *');
this.display.log('* Please consider using jasmine-spec-reporter < 2.0.0. *');
this.display.log('* *');
this.display.log('* npm install jasmine-spec-reporter@"<2.0.0" --save-dev *');
this.display.log('*******************************************************************');
this.display.newLine();
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/processors/default-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ DefaultProcessor.prototype.displaySuite = function (suite) {
};

function displaySpecDescription(spec) {
return spec.results().description;
return spec.description;
}

DefaultProcessor.prototype.displaySuccessfulSpec = displaySpecDescription;
Expand Down

0 comments on commit bf55f80

Please sign in to comment.