Skip to content

Commit

Permalink
Added default pending state of a spec when 'it' is called without the…
Browse files Browse the repository at this point in the history
… callback
  • Loading branch information
Marcin Bunsch committed May 27, 2011
1 parent 919e851 commit 2cdddc7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 24 deletions.
10 changes: 10 additions & 0 deletions lib/jessie/jasmine.js
Expand Up @@ -22,6 +22,16 @@ global.pending = function(message) {
// Remove the global window to not pollute the global namespace
delete global.window

jasmine.placeholderPendingFunction = function() { pending() }

jasmine.Env.prototype.it_without_default_pending = jasmine.Env.prototype.it

// Add default pending function when no func is supplied
jasmine.Env.prototype.it = function(description, func) {
if (!func) func = jasmine.placeholderPendingFunction
this.it_without_default_pending(description, func)
};

// Extend the fail to extract the proper stacktrace
jasmine.Spec.prototype.fail = function (e) {
var expectationResult = new jasmine.ExpectationResult({
Expand Down
11 changes: 8 additions & 3 deletions spec/jessie/jasmine_spec.js
@@ -1,13 +1,13 @@
describe('jessie.jasmine', function() {

it('should extend jasmine.Spec.prototype.fail with stacktrace', function() {
jasmine.Spec.prototype.fail.toString().should_match('expectationResult.stacktrace')
})

it('should extend jasmine.PrettyPrinter.prototype.iterateObject with checking for should_ properties', function() {
jasmine.PrettyPrinter.prototype.iterateObject.toString().should_match('var should_regex')
})

it('should extend jasmine.Suite.prototype.execute with reportSuiteStarting event', function() {
jasmine.Suite.prototype.execute.toString().should_match('reportSuiteStarting')
})
Expand All @@ -17,7 +17,7 @@ describe('jessie.jasmine', function() {
jasmine.Spec.prototype.fail("this is an error");
expect(jasmine.Spec.prototype.results_.addResult).toHaveBeenCalled();
});

it("should extend Jasmine with ability to add pending notification", function() {
var raised = 0, exception = null
try {
Expand All @@ -42,4 +42,9 @@ describe('jessie.jasmine', function() {
exception.message.should_be('Write some specs')
})

it("should extend Jasmine with ability to define a pending spec by calling a it without a callback", function() {
spyOn(jasmine.Env.prototype, 'it_without_default_pending').andReturn('')
jasmine.Env.prototype.it("Foo")
expect(jasmine.Env.prototype.it_without_default_pending).toHaveBeenCalledWith("Foo", jasmine.placeholderPendingFunction)
})
})
32 changes: 16 additions & 16 deletions spec/jessie/reporter_spec.js
Expand Up @@ -4,7 +4,7 @@ describe('jessie.reporter', function() {
it("should load formatter", function() {
expect(reporter.formatter.constructor).toEqual(Object)
})

it("should respond to jasmine reporter methods", function() {
reporter.log.should_be_a(Function)
reporter.reportSpecStarting.should_be_a(Function)
Expand All @@ -14,9 +14,9 @@ describe('jessie.reporter', function() {
reporter.reportSuiteResults.should_be_a(Function)
reporter.reportRunnerResults.should_be_a(Function)
})

describe('#printSummary', function() {

it("should print a summary of a good run", function() {
capture = require('helpers/stdout').capture(function() {
reporter.printSummary({duration: 12, failed: 0, total: 2})
Expand All @@ -25,7 +25,7 @@ describe('jessie.reporter', function() {
capture.output().should_match(/\033\[32m/) // green
capture.output().should_match('Completed in 0.012 seconds')
})

it("should print a summary a failed run", function() {
capture = require('helpers/stdout').capture(function() {
reporter.printSummary({duration: 15, failed: 1, total: 2})
Expand All @@ -52,35 +52,35 @@ describe('jessie.reporter', function() {
capture.output().should_match('3 examples, 1 pending')
capture.output().should_match('Completed in 0.015 seconds')
})

})

describe('#extractFailureLine', function() {

it("should extract a line from a stacktrace line", function() {
capture = require('helpers/stdout').capture(function() {
reporter.extractFailureLine('./spec/jessie/reporter_spec.js:1:1')
})
capture.output().should_match(/describe\(\'jessie.reporter\', function\(\) \{/)
})

})

describe('#printFailures', function() {

it("should print errors with stack trace", function() {
var failures= [{
description: 'it should print errors',
message: 'Expected A to be B',
stacktrace: ['Expected A to be B', 'file.js:23:2', 'another_file.js:30:11']
}]

capture = require('helpers/stdout').capture(function() {
reporter.printFailures(failures)
})

capture.output().should_match(/\033\[31m/) // red

capture.output().should_match('Failures:')
capture.output().should_match('it should print errors')
capture.output().should_match('Expected A to be B')
Expand All @@ -95,12 +95,12 @@ describe('jessie.reporter', function() {
message: 'Expected A to be B',
stacktrace: ['Expected A to be B', 'file.js:23:2', 'another_file.js:30:11']
}]

capture = require('helpers/stdout').capture(function() {
reporter.printPendings(failures)
})

capture.output().should_match('Pending:')
capture.output().should_match('Pending:')
capture.output().should_match(/\033\[33m/) // yellow
capture.output().should_match('it should print errors')
capture.output().should_match('Expected A to be B')
Expand All @@ -109,5 +109,5 @@ describe('jessie.reporter', function() {
})

})

})
10 changes: 5 additions & 5 deletions spec/jessie/runner_spec.js
@@ -1,24 +1,24 @@
describe('jessie.runner', function() {

var runner = new (require('jessie/runner')).runner([''], {})

it("should load finder", function() {
expect(runner.finder).toBeDefined()
})

it("should load reporter", function() {
expect(runner.reporter).toBeDefined()
})

it("should fire execute() on jasmine", function() {
var check = 0
runner.jasmine = {
runner.jasmine = {
execute: function() {
check = 1
}
}
runner.run()
check.should_be(1)
check.should_be(1)
})

})

0 comments on commit 2cdddc7

Please sign in to comment.