Skip to content

Commit

Permalink
Added statement chaining to specs
Browse files Browse the repository at this point in the history
  • Loading branch information
pivotal committed Dec 1, 2008
1 parent 9f2d3e0 commit a4979fe
Show file tree
Hide file tree
Showing 16 changed files with 237 additions and 111 deletions.
Empty file modified images/accept.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified images/exclamation.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified jasmine.iml
100644 → 100755
Empty file.
Empty file modified jasmine.ipr
100644 → 100755
Empty file.
139 changes: 82 additions & 57 deletions jasmine.iws

Large diffs are not rendered by default.

89 changes: 65 additions & 24 deletions lib/jasmine.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ if (typeof Object.create !== 'function') {
}

// Klass.method instead of Klass.prototype.name = function
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
if (typeof Function.method !== 'function') {
Function.prototype.method = function (name, func) {
this.prototype[name] = func;
return this;
}
}

/******************************************************************************
Expand Down Expand Up @@ -49,7 +51,7 @@ Matchers.method('should_not_equal', function (expected) {
});

/*
* expects helper method that allows for chaining Matcher
* expects_hat helper method that allows for chaining Matcher
*/
var expects_that = function (actual) {
return new Matchers(actual);
Expand All @@ -59,12 +61,45 @@ var expects_that = function (actual) {
* Jasmine spec constructor
*/
var it = function (description, func) {
return {
var that = {
description: description,
execute: func
func: func,
done: false,
execute: function() {
that.func.apply(that);
}
}
return that;
}

var it_async = function (description) {
var that = {
description: description,
queue: [],
waits: function (timeout) {
return that;
},
done: false,
execute: function () {
for(i = 0; i < that.queue.length; i++) {
that.queue[i]();
}
}

};

var addToQueue = function(func) {
that.queue.push(func);
return that;
}

that.runs = addToQueue;
that.then = addToQueue;

return that;
}


/*
* Jasmine constructor
*/
Expand All @@ -79,21 +114,27 @@ var jasmine_init = function () {
*/
var Jasmine = jasmine_init();

// spec: {
// description: description,
// func: func,
// execute: function() {with(jasmine) {func();}}
// },
//
// expects_that: function(actual) {
//
// this.actual = actual;
// return this;
// },
//
// }
//}
//
//var JasmineSpec = function(description, func) {
//
//}
/*
* TODO:
* - add spec or description to results
* - spec.execute needs to wait until the spec is done
* - an async test will be killed after X ms if not done and then listed as failed with an "async fail" message of some sort
* - Suite to run tests in order, constructed with a function called describe
* - Suite supports before
* - Suite supports after
* - Suite supports before_each
* - Suite supports after_each
* - Suite supports asynch
* - Runner that runs suites in order
* - Runner supports async
* - HTML reporter
* - Shows pass/fail progress (just like bootstrap reporter)
* - Lists a Summary: total # specs, # of passed, # of failed
* - Failed reports lists all specs that failed and what the failure was
* - Failed output is styled with red
* - JSON reporter
* - Lists full results as a JSON object/string
* - Luna reporter
* - each result calls back into widgets for rendering to Luna views
*/

Empty file modified nbproject/private/private.xml
100644 → 100755
Empty file.
Empty file modified nbproject/project.properties
100644 → 100755
Empty file.
Empty file modified nbproject/project.xml
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions test/bootstrap.html
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ <h1>
<div id="results_summary" style="display:none;">
<h2>Summary</h2>
</div>
<div id="fails">
<h2 id="fails_header" style="display:none;">Failure Messages</h2>
<div id="fails" style="display:none;">
<h2 id="fails_header">Failure Messages</h2>
<div id="fail_messages"></div>
</div>
</div>
Expand Down
116 changes: 88 additions & 28 deletions test/bootstrap.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,44 @@ var reporter = function () {
}
else {
fails++;
var failsHeader = $('fails_header');
failsHeader.show();
var fails_report = $('fails');
fails_report.show();

iconElement = $('icons');
iconElement.appendChild(new Element('img', {src: '../images/exclamation.png'}));

var failMessages = $('fail_messages');
var newFail = new Element('p', {class: 'fail'});
var newFail = new Element('p', {'class': 'fail'});
newFail.innerHTML = message;
failMessages.appendChild(newFail);
}
},

summary: function () {
summary = new Element('p', {class: ((fails > 0) ? 'fail_in_summary' : '') });
summary.innerHTML = total + ' tests, ' + passes + ' passing, ' + fails + ' failed.';
var summaryElement = $('results_summary');
summaryElement.appendChild(summary);
summaryElement.show();
summary = new Element('p', {'class': ((fails > 0) ? 'fail_in_summary' : '') });
summary.innerHTML = total + ' tests, ' + passes + ' passing, ' + fails + ' failed.';

var summaryElement = $('results_summary');
summaryElement.appendChild(summary);
summaryElement.show();
}
}
return that;
}();

var testMatchersComparisons = function () {
Jasmine = jasmine_init();

reporter.test(expects_that(true).should_equal(true),
'expects_that(true).should_equal(true) returned false');
'expects_that(true).should_equal(true) returned false');

reporter.test(!(expects_that(false).should_equal(true)),
'expects_that(true).should_equal(true) returned true');
'expects_that(true).should_equal(true) returned true');

reporter.test(expects_that(true).should_not_equal(false),
'expects_that(true).should_not_equal(false) retruned false');
'expects_that(true).should_not_equal(false) retruned false');

reporter.test(!(expects_that(true).should_not_equal(true)),
'expects_that(true).should_not_equal(false) retruned true');
'expects_that(true).should_not_equal(false) retruned true');
}

var testMatchersReporting = function () {
Expand All @@ -63,56 +63,58 @@ var testMatchersReporting = function () {
expects_that(false).should_equal(true);

reporter.test((Jasmine.results.length == 2),
"Jasmine results array doesn't have 2 results");
"Jasmine results array doesn't have 2 results");

reporter.test((Jasmine.results[0].passed == true),
"First spec didn't pass");
"First spec didn't pass");

reporter.test((Jasmine.results[1].passed == false),
"Second spec did pass");
"Second spec did pass");

Jasmine = jasmine_init();

expects_that(false).should_equal(true);

reporter.test((Jasmine.results[0].message == 'Expected true but got false.'),
"Failed expectation didn't test the failure message");
"Failed expectation didn't test the failure message");

Jasmine = jasmine_init();

expects_that(true).should_equal(true);

reporter.test((Jasmine.results[0].message == 'Passed.'),
"Passing expectation didn't test the passing message");
"Passing expectation didn't test the passing message");
}

var testSpecs = function () {
Jasmine = jasmine_init();
var spec = it('new spec');
reporter.test((spec.description == 'new spec'),
"Spec did not have a description");
"Spec did not have a description");

Jasmine = jasmine_init();
var another_spec = it('another spec', function () {
var another_spec = it('spec with an expectation', function () {
var foo = 'bar';
expects_that(foo).should_equal('bar');
});
another_spec.execute();
another_spec.done = true;

reporter.test((Jasmine.results.length == 1),
"Results aren't there after a spec was executed");
"Results aren't there after a spec was executed");
reporter.test((Jasmine.results[0].passed == true),
"Results has a result, but it's true");
"Results has a result, but it's true");

Jasmine = jasmine_init();
var yet_another_spec = it('spec with failing expectation', function () {
var foo = 'bar';
expects_that(foo).should_equal('baz');
});
yet_another_spec.execute();
another_spec.done = true;

reporter.test((Jasmine.results[0].passed == false),
"Expectation that failed, passed");
"Expectation that failed, passed");

Jasmine = jasmine_init();
var yet_yet_another_spec = it('spec with multiple assertions', function () {
Expand All @@ -123,18 +125,76 @@ var testSpecs = function () {
expects_that(baz).should_equal('quux');
});
yet_yet_another_spec.execute();
another_spec.done = true;

reporter.test((Jasmine.results.length == 2),
"Spec doesn't support multiple expectations");
"Spec doesn't support multiple expectations");
}

var testAsyncSpecs = function () {
Jasmine = jasmine_init();
var foo = 0;

var a_spec = it_async('simple queue test').
runs(function () {
foo++;
}).then(function() {
expects_that(foo).should_equal(1)
});

reporter.test(a_spec.queue.length === 2,
'Spec queue length is not 2');

Jasmine = jasmine_init();
foo = 0;
a_spec = it_async('spec w/ queued statments').
runs(function () {
foo++;
}).then(function() {
expects_that(foo).should_equal(1)
});

a_spec.execute();

reporter.test((Jasmine.results.length === 1),
'Spec queue did not run all functions');
reporter.test((Jasmine.results[0].passed === true),
'Queued expectation failed');

Jasmine = jasmine_init();
foo = 0;
a_spec = it_async('spec w/ queued statments').
runs(function () {
setTimeout(function() {
foo++
}, 500);
}).waits(1000).then(function() {
expects_that(foo).should_equal(1);
});

a_spec.execute();

reporter.test((Jasmine.results.length === 1),
'Spec queue did not run all functions');

reporter.test((Jasmine.results[0].passed === true),
'Queued expectation failed');
}

var runTests = function () {
$('spinner').show();

testMatchersComparisons();
testMatchersReporting();
testSpecs();
// testMatchersComparisons();
// testMatchersReporting();
// testSpecs();

testAsyncSpecs();
$('spinner').hide();
reporter.summary();
}
}

//it('should be an async test') {
// run(function() {setup}).and.wait(2000).then.expects_that(true).should_equal(true).and.expects_that
//}


Empty file modified test/prototype-1.6.0.3.js
100644 → 100755
Empty file.
Empty file modified test/spinner.gif
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified test/test.css
100644 → 100755
Empty file.
Empty file modified test/test.html
100644 → 100755
Empty file.
Empty file modified test/test.js
100644 → 100755
Empty file.

0 comments on commit a4979fe

Please sign in to comment.