Skip to content

Commit

Permalink
Added support for optional, explicit test names.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmohl committed Dec 26, 2011
1 parent f121efb commit 53c2a7f
Show file tree
Hide file tree
Showing 29 changed files with 588 additions and 477 deletions.
67 changes: 33 additions & 34 deletions example/pavlov/example.specs.coffee
@@ -1,35 +1,34 @@
pavlov.specify "Example Specifications", ->
describe "", ->
foo = "bar"
describe "When testing should equal", ->
expectThat -> foo.should equal "bar"
describe "When testing shouldnt equal", ->
expectThat -> foo.shouldnt equal "baz"
describe "When testing to and be", ->
expectThat -> foo.should be equal to "bar"
expectThat -> foo.shouldnt be equal to "bah"
describe "When testing for true", ->
expectThat -> (foo is "bar").should be true
expectThat -> (foo is "baz").shouldnt be true
describe "When testing for false", ->
expectThat -> (foo is "baz").should be false
expectThat -> (foo is "bar").shouldnt be false
describe "When testing for null or undefined", ->
testNull = null
testUndefined = undefined
expectThat -> (testNull is null).should be true
expectThat -> (testNull isnt null).shouldnt be true
expectThat -> (testUndefined is undefined).should be true
expectThat -> (testUndefined is undefined).shouldnt be false
describe "When testing for throw", ->
expectThat -> (-> throw "test exception").should throwException
expectThat -> (-> throw "test exception").should throwException "test exception"
describe "When testing for greater than", ->
expectThat -> 10.should be greaterThan 9
expectThat -> 9.1.shouldnt be greaterThan 10
describe "When testing for less than", ->
expectThat -> 10.should be lessThan 11
expectThat -> 10.1.shouldnt be lessThan 10
describe "When testing with the example custom matcher", ->
expectThat -> 10.should be atleastTwoGreaterThan 8
expectThat -> 10.shouldnt be atleastTwoGreaterThan 9
foo = "bar"
describe "When testing should equal", ->
expectThat -> foo.should equal "bar"
describe "When testing shouldnt equal", ->
expectThat -> foo.shouldnt equal "baz"
describe "When testing to and be", ->
expectThat -> foo.should be equal to "bar"
expectThat -> foo.shouldnt be equal to "bah"
describe "When testing for true", ->
expectThat -> (foo is "bar").should be true
expectThat -> (foo is "baz").shouldnt be true
describe "When testing for false", ->
expectThat -> (foo is "baz").should be false
expectThat -> (foo is "bar").shouldnt be false
describe "When testing for null or undefined", ->
testNull = null
testUndefined = undefined
expectThat -> (testNull is null).should be true
expectThat -> (testNull isnt null).shouldnt be true
expectThat -> (testUndefined is undefined).should be true
expectThat -> (testUndefined is undefined).shouldnt be false
describe "When testing for throw", ->
expectThat -> (-> throw "test exception").should throwException
expectThat -> (-> throw "test exception").should throwException "test exception"
describe "When testing for greater than", ->
expectThat -> 10.should be greaterThan 9
expectThat -> 9.1.shouldnt be greaterThan 10
describe "When testing for less than", ->
expectThat -> 10.should be lessThan 11
expectThat -> 10.1.shouldnt be lessThan 10
describe "When testing with the example custom matcher", ->
expectThat -> 10.should be atleastTwoGreaterThan 8
expectThat -> 10.shouldnt be atleastTwoGreaterThan 9
176 changes: 87 additions & 89 deletions example/pavlov/min/example.specs.js
@@ -1,94 +1,92 @@

pavlov.specify("Example Specifications", function() {
return describe("", function() {
var foo;
foo = "bar";
describe("When testing should equal", function() {
return expectThat(function() {
return foo.should(equal("bar"));
});
});
describe("When testing shouldnt equal", function() {
return expectThat(function() {
return foo.shouldnt(equal("baz"));
});
});
describe("When testing to and be", function() {
expectThat(function() {
return foo.should(be(equal(to("bar"))));
});
return expectThat(function() {
return foo.shouldnt(be(equal(to("bah"))));
});
});
describe("When testing for true", function() {
expectThat(function() {
return (foo === "bar").should(be(true));
});
return expectThat(function() {
return (foo === "baz").shouldnt(be(true));
});
});
describe("When testing for false", function() {
expectThat(function() {
return (foo === "baz").should(be(false));
});
return expectThat(function() {
return (foo === "bar").shouldnt(be(false));
});
});
describe("When testing for null or undefined", function() {
var testNull, testUndefined;
testNull = null;
testUndefined = void 0;
expectThat(function() {
return (testNull === null).should(be(true));
});
expectThat(function() {
return (testNull !== null).shouldnt(be(true));
});
expectThat(function() {
return (testUndefined === void 0).should(be(true));
});
return expectThat(function() {
return (testUndefined === void 0).shouldnt(be(false));
});
});
describe("When testing for throw", function() {
expectThat(function() {
return (function() {
throw "test exception";
}).should(throwException);
});
return expectThat(function() {
return (function() {
throw "test exception";
}).should(throwException("test exception"));
});
});
describe("When testing for greater than", function() {
expectThat(function() {
return 10..should(be(greaterThan(9)));
});
return expectThat(function() {
return 9.1.shouldnt(be(greaterThan(10)));
});
});
describe("When testing for less than", function() {
expectThat(function() {
return 10..should(be(lessThan(11)));
});
return expectThat(function() {
return 10.1.shouldnt(be(lessThan(10)));
});
});
return describe("When testing with the example custom matcher", function() {
expectThat(function() {
return 10..should(be(atleastTwoGreaterThan(8)));
});
return expectThat(function() {
return 10..shouldnt(be(atleastTwoGreaterThan(9)));
});
var foo;
foo = "bar";
describe("When testing should equal", function() {
return expectThat(function() {
return foo.should(equal("bar"));
});
});
describe("When testing shouldnt equal", function() {
return expectThat(function() {
return foo.shouldnt(equal("baz"));
});
});
describe("When testing to and be", function() {
expectThat(function() {
return foo.should(be(equal(to("bar"))));
});
return expectThat(function() {
return foo.shouldnt(be(equal(to("bah"))));
});
});
describe("When testing for true", function() {
expectThat(function() {
return (foo === "bar").should(be(true));
});
return expectThat(function() {
return (foo === "baz").shouldnt(be(true));
});
});
describe("When testing for false", function() {
expectThat(function() {
return (foo === "baz").should(be(false));
});
return expectThat(function() {
return (foo === "bar").shouldnt(be(false));
});
});
describe("When testing for null or undefined", function() {
var testNull, testUndefined;
testNull = null;
testUndefined = void 0;
expectThat(function() {
return (testNull === null).should(be(true));
});
expectThat(function() {
return (testNull !== null).shouldnt(be(true));
});
expectThat(function() {
return (testUndefined === void 0).should(be(true));
});
return expectThat(function() {
return (testUndefined === void 0).shouldnt(be(false));
});
});
describe("When testing for throw", function() {
expectThat(function() {
return (function() {
throw "test exception";
}).should(throwException);
});
return expectThat(function() {
return (function() {
throw "test exception";
}).should(throwException("test exception"));
});
});
describe("When testing for greater than", function() {
expectThat(function() {
return 10..should(be(greaterThan(9)));
});
return expectThat(function() {
return 9.1.shouldnt(be(greaterThan(10)));
});
});
describe("When testing for less than", function() {
expectThat(function() {
return 10..should(be(lessThan(11)));
});
return expectThat(function() {
return 10.1.shouldnt(be(lessThan(10)));
});
});
return describe("When testing with the example custom matcher", function() {
expectThat(function() {
return 10..should(be(atleastTwoGreaterThan(8)));
});
return expectThat(function() {
return 10..shouldnt(be(atleastTwoGreaterThan(9)));
});
});
});
24 changes: 16 additions & 8 deletions lib/expectThat.jasmine.js
@@ -1,7 +1,7 @@
var expectThatApi;
expectThatApi = (function(expectThatApi) {
return {
version: "0.2.0.2",
version: "0.2.1.0",
init: function(assertProvider) {
var _this;
_this = this;
Expand Down Expand Up @@ -102,13 +102,19 @@ expectThatApi = (function(expectThatApi) {
"expected": expected
};
},
extendApi: function(fn, assertProvder) {
extendApi: function(fn, assertProvder, desc) {
var description;
if (!Object.prototype.should) {
expectThatApi.init(assertProvder);
}
description = fn.toString().match(/^[^\{]*\{((.*\s*)*)\}/m)[1];
return description.replace(/(\^\s+|\s)+$/g, "").replace(/[(\^(?)]/g, " ").replace(/.should/g, " should").replace(/return/g, " ").replace(/shouldnt/g, "shouldn't").replace(/void 0/g, "null").replace(/!= null/g, "").replace(/typeof null !== "undefined" && null !== null/g, "undefined");
if (typeof desc === "function" && typeof fn !== "function") {
fn = desc;
description = fn.toString().match(/^[^\{]*\{((.*\s*)*)\}/m)[1];
description = description.replace(/(\^\s+|\s)+$/g, "").replace(/\);/g, "").replace(/[(\^(?)]/g, " ").replace(/.should/g, " should").replace(/return/g, " ").replace(/shouldnt/g, "shouldn't").replace(/void 0/g, "null").replace(/!= null/g, "").replace(/typeof null !== "undefined" && null !== null/g, "undefined");
} else {
description = desc;
}
return [fn, description];
}
};
return expectThatApi.util.extend(expectThatApi, expectThatApi.api);
Expand Down Expand Up @@ -206,11 +212,13 @@ expectThatApi = (function(expectThatApi) {
};
expectThatApi.util.extend(expectThatApi.api.jasmine, expectThatApi.assertionProvider);
expectThatApi.api.jasmine = {
expectThat: function(fn) {
var env, testDescription;
testDescription = expectThatApi.api.extendApi(fn, expectThatApi.assertionProvider);
expectThat: function(desc, fn) {
var env, newFn, result, testDescription;
result = expectThatApi.api.extendApi(fn, expectThatApi.assertionProvider, desc);
newFn = result[0];
testDescription = result[1];
env = jasmine.getEnv();
return env.it(testDescription, fn);
return env.it(testDescription, newFn);
}
};
expectThatApi.util.extend(expectThatApi, expectThatApi.api.jasmine);
Expand Down
Binary file modified lib/expectThat.jasmine.min.gz.js
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/expectThat.jasmine.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 53c2a7f

Please sign in to comment.