Provide a way to add more matchers in a spec or suite without affecting later specs or suites.

This commit is contained in:
Christian Williams
2009-07-07 23:57:03 -07:00
parent 378d6bb4ff
commit ed00c13b15
3 changed files with 68 additions and 2 deletions

View File

@@ -728,4 +728,36 @@ describe("jasmine spec running", function () {
expect(exceptionMessage).toEqual('explodes function should not have been called');
});
it("should be easy to add more matchers local to a spec, suite, etc.", function() {
var spec1, spec2, spec1Matcher, spec2Matcher;
var suite = env.describe('some suite', function() {
env.beforeEach(function() {
this.addMatchers({ matcherForSuite: function(expected) {
return "matcherForSuite: actual: " + this.actual + "; expected: " + expected;
} });
});
spec1 = env.it('spec with an expectation').runs(function () {
this.addMatchers( { matcherForSpec: function(expected) {
return "matcherForSpec: actual: " + this.actual + "; expected: " + expected;
} });
spec1Matcher = this.expect("xxx");
});
spec2 = env.it('spec with failing expectation').runs(function () {
spec2Matcher = this.expect("yyy");
});
});
suite.execute();
expect(spec1Matcher.matcherForSuite("expected")).toEqual("matcherForSuite: actual: xxx; expected: expected");
expect(spec1Matcher.matcherForSpec("expected")).toEqual("matcherForSpec: actual: xxx; expected: expected");
expect(spec2Matcher.matcherForSuite("expected")).toEqual("matcherForSuite: actual: yyy; expected: expected");
expect(spec2Matcher.matcherForSpec).toBe(undefined);
});
});