spectacular
Version:
Advanced BDD framework for CoffeeScript and JavaScript
1,698 lines (1,563 loc) • 135 kB
JavaScript
// Generated by CoffeeScript 1.6.3
(function() {
var ClassWithCollection, ConcernWithExcludedHook, ConcernWithIncludedAndExcluded, Dummy, DummyWithCustomBuild, DurationFormatter, ErrorSourceFormatter, ErrorStackFormatter, ExampleResultsFormatter, GlobalizableClass, MixinWithExcludedClassProperty, MixinWithExcludedProperty, MixinWithExtendedHook, MixinWithIncludedHook, MixinWithoutExtendedHook, MixinWithoutIncludedHook, ProfileFormatter, ProgressFormatter, ResultsFormatter, ResumeFormatter, SeedFormatter, _ref,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
__slice = [].slice;
factory('exampleGroup', {
"class": spectacular.ExampleGroup
}, function() {
set('ownDescription', 'Some group description');
return trait('with root', function() {
return set('parent', function() {
return create('exampleGroup');
});
});
});
factory('expectation', {
"class": spectacular.Expectation
}, function() {
createWith(function() {
return [null, null, equal(42, false, new Error)];
});
trait('successful', function() {
set('actual', 42);
set('success', true);
return set('message', 'succeed');
});
return trait('failure', function() {
set('actual', 24);
set('success', false);
return set('message', 'failed');
});
});
factory('example', {
"class": spectacular.Example
}, function() {
set('ownDescription', 'Some example description');
set('parent', function() {
return create('exampleGroup', 'with root');
});
trait('successful', function() {
return after('build', function(example) {
return example.result = {
example: example,
state: 'success',
hasFailures: function() {
return false;
},
expectations: [create('expectation', 'successful')]
};
});
});
trait('failure', function() {
return after('build', function(example) {
return example.result = {
example: example,
state: 'failure',
hasFailures: function() {
return true;
},
expectations: [create('expectation', 'failure')]
};
});
});
return trait('errored', function() {
return after('build', function(example) {
return example.result = {
example: example,
state: 'errored',
hasFailures: function() {
return false;
},
expectations: []
};
});
});
});
spectacular.matcher('sample', function() {
description(function() {
return 'sample description';
});
match(function() {
return true;
});
return failureMessageForShould(function() {
return 'sample message';
});
});
spectacular.matcher('parameterizableMatcher', function() {
takes('value1', 'value2');
description(function() {
return 'parameterizableMatcher description';
});
match(function() {
return this.value1 && this.value2;
});
return failureMessageForShould(function() {
return 'parameterizableMatcher message';
});
});
spectacular.matcher('chainableMatcher', function() {
match(function() {
return this.value;
});
description(function() {
return 'chain';
});
return chain('chain', function(value) {
this.value = value;
});
});
spectacular.matcher('initializableMatcher', function() {
init(function() {
return this.value = true;
});
match(function() {
return this.value;
});
return description(function() {
return 'initalized';
});
});
spectacular.matcher('timeout', function() {
timeout(100);
description(function() {
return 'timing out promise based matcher';
});
match(function() {
return new spectacular.Promise;
});
return failureMessageForShould(function() {
return 'matcher message';
});
});
spectacular.matcher('throwing', function() {
return match(function() {
throw new Error('foo');
});
});
if (typeof module === 'undefined') {
fixture('formatters/reporter.html', {
as: 'reporterContainer'
});
spectacular.helper('withWidgetSetup', function(block) {
given('reporter', function() {
return {
container: this.reporterContainer[0],
widgets: [],
openDetails: function() {},
errorOccured: function() {}
};
});
given('runner', function() {
return {
examples: [],
options: spectacular.options
};
});
return block.call(this);
});
}
sharedExample('match error', function() {
return describe('the parser', function() {
the(function() {
return this.parser.should(exist);
});
the('size', function() {
return this.parser.size.should(equal(4));
});
describe('::find', function() {
return context('with a file path', function() {
subject(function() {
return this.parser.find('file.js');
});
return it(function() {
return should(have(2, 'lines'));
});
});
});
return describe('::details', function() {
return context('with a line from the stack', function() {
subject(function() {
var line;
line = this.parser.find('file.js')[0];
return this.parser.details(line);
});
its('line', function() {
return should(equal('10'));
});
its('file', function() {
return should(equal('file.js'));
});
return its('method', function() {
return should(equal('failingFunction'));
});
});
});
});
});
sharedExample('a formatter', function() {
return specify('the returned promise value', function(async) {
var _this = this;
return this.subject.then(function(result) {
expect(result).to(equal(_this.expected));
return async.resolve();
}).fail(function(reason) {
return async.reject(reason);
});
});
});
spectacular.helper('createEnv', function(block, context, options) {
var env, k, v;
env = spectacular.env.clone();
env.options.colors = false;
env.options.format = 'documentation';
env.options.valueOutput = function(str) {
return str;
};
for (k in options) {
v = options[k];
env.options[k] = v;
}
context.results = '';
spyOn(env, 'globalize').andCallThrough(function() {
var promise;
promise = spectacular.Promise.unit();
return promise.then(function() {
return block();
});
});
return env;
});
spectacular.helper('createReporter', function(env, context, async) {
var reporter;
reporter = spectacular.ConsoleReporter.getDefault(env.options);
context.results = '';
reporter.on('message', function(e) {
return context.results += e.target;
});
reporter.on('report', function(e) {
context.results += e.target;
if (context.ended) {
if (context.rejected != null) {
async.reject(context.rejected);
} else {
async.resolve();
}
}
return context.ended = true;
});
env.runner.on('message', reporter.onMessage);
env.runner.on('result', reporter.onResult);
env.runner.on('end', reporter.onEnd);
return reporter;
});
spectacular.helper('runEnvExpectingNormalTermination', function(env, context, async) {
var oldEnv;
oldEnv = spectacular.env;
oldEnv.unglobalize();
spectacular.env = env;
return env.globalize().then(function() {
return env.run();
}).then(function(status) {
context.status = status;
spectacular.env.unglobalize();
spectacular.env = oldEnv;
oldEnv.globalize();
if (context.ended) {
async.resolve();
}
return context.ended = true;
}).fail(function(reason) {
context.reason = context.rejected = reason;
spectacular.env.unglobalize();
spectacular.env = oldEnv;
oldEnv.globalize();
return async.reject(reason);
});
});
spectacular.helper('runEnvExpectingInterruption', function(env, context, async) {
var oldEnv,
_this = this;
oldEnv = spectacular.env;
oldEnv.unglobalize();
spectacular.env = env;
return env.globalize().then(function() {
return env.run();
}).then(function(status) {
spectacular.env = oldEnv;
spectacular.env.unglobalize();
oldEnv.globalize();
context.rejected = new Error("run didn't failed");
if (context.ended) {
async.reject(context.rejected);
}
return context.ended = true;
}).fail(function(reason) {
spectacular.env = oldEnv;
spectacular.env.unglobalize();
context.reason = reason;
oldEnv.globalize();
return async.resolve();
});
});
spectacular.helper('runningSpecs', function(desc) {
var options;
options = {};
return {
withOption: function(option, value) {
options[option] = value;
return this;
},
shouldFailWith: function(re, block) {
describe("running specs with " + desc, function() {
before(function(async) {
this.env = createEnv(block, this, options);
this.reporter = createReporter(this.env, this, async);
return runEnvExpectingNormalTermination(this.env, this, async);
});
specify('the status', function() {
return this.status.should(be(1));
});
return specify('the results', function() {
return this.results.should(match(re));
});
});
return this;
},
shouldSucceedWith: function(re, block) {
describe("running specs with " + desc, function() {
before(function(async) {
this.env = createEnv(block, this, options);
this.reporter = createReporter(this.env, this, async);
return runEnvExpectingNormalTermination(this.env, this, async);
});
specify('the status', function() {
return this.status.should(be(0));
});
return specify('the results', function() {
return this.results.should(match(re));
});
});
return this;
},
shouldStopWith: function(re, block) {
describe("running specs with " + desc, function() {
before(function(async) {
this.env = createEnv(block, this, options);
this.reporter = createReporter(this.env, this, async);
return runEnvExpectingInterruption(this.env, this, async);
});
return specify('the error message', function() {
return this.reason.message.should(match(re));
});
});
return this;
}
};
});
spectacular.helper('environmentMethod', function(method) {
return {
cannotBeCalledInsideIt: function() {
return runningSpecs('call inside it').shouldFailWith(/called inside a it block/, function() {
return describe('foo', function() {
return it(function() {
return spectacular.global[method]();
});
});
});
},
cannotBeCalledOutsideIt: function() {
return runningSpecs('call outside it').shouldStopWith(/called outside a it block/, function() {
return describe('foo', function() {
return spectacular.global[method]();
});
});
},
cannotBeCalledWithoutPreviousSubject: function() {
return runningSpecs('call in context without previous subject').shouldStopWith(/called in context without a previous subject/, function() {
return describe('foo', function() {
return spectacular.global[method]();
});
});
},
cannotBeCalledWithoutMatcher: function() {
return runningSpecs('call without matcher').shouldFailWith(/called without a matcher/, function() {
return specify(function() {
return spectacular.global[method]();
});
});
}
};
});
runningSpecs('without examples').shouldSucceedWith(/0 success, 0 assertions, 0 failures/, function() {});
runningSpecs('an error raised in spec file').shouldStopWith(/message/, function() {
throw new Error('message');
});
runningSpecs('an error raised in describe').shouldStopWith(/message/, function() {
return describe('failing declaration', function() {
throw new Error('message');
});
});
runningSpecs('pending examples').shouldSucceedWith(/0 errors, 0 skipped, 2 pending/, function() {
return describe('pending examples', function() {
it(function() {
return pending();
});
return it(function() {
return pending();
});
});
});
runningSpecs('excluded examples').shouldSucceedWith(/2 success, 2 assertion/, function() {
return describe('inclusive examples', function() {
it(function() {
return true.should(be(true));
});
it(function() {
return true.should(be(true));
});
return except(it(function() {
return true.should(be(true));
}));
});
});
runningSpecs('scoped examples').shouldSucceedWith(/1 success, 1 assertion/, function() {
return describe('exclusive examples', function() {
it(function() {
return true.should(be(true));
});
it(function() {
return true.should(be(true));
});
return only(it(function() {
return true.should(be(true));
}));
});
});
runningSpecs('inclusive groups').shouldSucceedWith(/2 success, 2 assertion/, function() {
describe('included groups', function() {
it(function() {
return true.should(be(true));
});
return it(function() {
return true.should(be(true));
});
});
return except(describe('inclusive groups', function() {
return it(function() {
return true.should(be(true));
});
}));
});
runningSpecs('exclusive groups').shouldSucceedWith(/1 success, 1 assertion/, function() {
describe('excluded groups', function() {
it(function() {
return true.should(be(true));
});
return it(function() {
return true.should(be(true));
});
});
return only(describe('exclusive groups', function() {
return it(function() {
return true.should(be(true));
});
}));
});
runningSpecs('skipped examples').shouldFailWith(/0 errors, 2 skipped/, function() {
return describe('skipped examples', function() {
it(function() {
return skip();
});
return it(function() {
return skip();
});
});
});
runningSpecs('failing examples').shouldFailWith(/2 failures, 0 errors/, function() {
return describe('failing examples', function() {
it(function() {
return fail();
});
return it(function() {
return fail();
});
});
});
runningSpecs('long trace, colors, no source and no documentation').withOption('longTrace', true).withOption('noColors', false).withOption('showSource', false).withOption('documentation', false).shouldFailWith(/1\ssuccess(.*)1\sfailure(.*)1\serror(.*)1\sskipped(.*)1\spending/, function() {
return describe('failing examples', function() {
it(function() {
return true.should(be(true));
});
it(function() {
return fail();
});
it(function() {
throw new Error;
});
it(function() {
return skip();
});
return it(function() {
return pending();
});
});
});
runningSpecs('it without block').shouldSucceedWith(/0 success, 0 assertions, (.*), 1 pending/, function() {
return describe('it without block', function() {
return it('foo');
});
});
runningSpecs('describe without block').shouldSucceedWith(/0 success, 0 assertions, (.*), 1 pending/, function() {
return describe('foo');
});
runningSpecs('an async example timing out').shouldFailWith(/1 failure/, function() {
return it(function(async) {
return async.rejectAfter(100, 'Timed out');
});
});
runningSpecs('an unhandled exception raised in example').shouldFailWith(/0 assertions, 0 failures, 1 error/, function() {
return describe('failing example', function() {
return it(function() {
throw new Error('message');
});
});
});
runningSpecs('an unhandled exception raised in example with expectations').shouldFailWith(/1 assertion, 0 failures, 1 error/, function() {
return describe('failing example with expectation', function() {
return it('should have been stopped', function() {
true.should(be(true));
throw new Error('message');
});
});
});
runningSpecs('an unhandled exception raised in before').shouldFailWith(/0 assertions, 0 failures, 1 error/, function() {
return describe('with successful example', function() {
before(function() {
throw new Error('message');
});
return it(function() {
return true.should(be(true));
});
});
});
runningSpecs('an async before hook timing out').shouldFailWith(/0 assertions, (.*), 1 error/, function() {
return describe('with successful example', function() {
before(function(async) {
return async.rejectAfter(100);
});
return it(function() {
return true.should(be(true));
});
});
});
runningSpecs('a rejected async before hook').shouldFailWith(/0 assertions, (.*), 1 error/, function() {
return describe('with successful example', function() {
before(function(async) {
return async.reject(new Error('message'));
});
return it(function() {
return true.should(be(true));
});
});
});
runningSpecs('an unhandled exception raised in after').shouldFailWith(/0 success, 1 assertion, 0 failures, 1 error/, function() {
return describe('with successful example', function() {
after(function() {
throw new Error('message');
});
return it(function() {
return true.should(be(true));
});
});
});
runningSpecs('an unhandled exception raised in after').shouldFailWith(/0 success, 1 assertion, 0 failures, 1 error/, function() {
return describe('with failing example', function() {
after(function() {
throw new Error('message');
});
return it(function() {
return true.should(be(false));
});
});
});
runningSpecs('an async after hook timing out').shouldFailWith(/1 assertion, (.*), 1 error/, function() {
return describe('with successful example', function() {
after(function(async) {
return async.rejectAfter(100);
});
return it(function() {
return true.should(be(true));
});
});
});
runningSpecs('a rejected async after hook').shouldFailWith(/1 assertion, (.*), 1 error/, function() {
return describe('with successful example', function() {
after(function(async) {
return async.reject(new Error('message'));
});
return it(function() {
return true.should(be(true));
});
});
});
runningSpecs('an unhandled exception raised in matcher').shouldFailWith(/1 assertion, 0 failures, 1 error/, function() {
return describe('failing example', function() {
return it(function() {
return {}.should(throwing);
});
});
});
describe('sequencial assertions', function() {
return it('should succeed', function() {
var o;
o = {
foo: 10
};
o.foo.should(equal(10));
o.foo = "100";
return o.foo.should(equal('100'));
});
});
describe('snake case syntax', function() {
given('object', function() {
return {
method: function() {}
};
});
before(function() {
spy_on(this.object, 'method');
return this.object.method();
});
return specify('for haveBeenCalled matcher', function() {
return this.object.method.should(have_been_called);
});
});
describe('the custom matcher', function() {
describe(sample, function() {
it(function() {
return should(exist);
});
return it(function() {
return should(sample);
});
});
describe(parameterizableMatcher, function() {
it(function() {
return should(exist);
});
return it(function() {
return should(parameterizableMatcher(true, true));
});
});
describe(chainableMatcher, function() {
it(function() {
return should(exist);
});
return it(function() {
return should(chainableMatcher.chain(true));
});
});
describe(initializableMatcher, function() {
it(function() {
return should(exist);
});
return it(function() {
return should(initializableMatcher);
});
});
runningSpecs('matcher returning timing out promise').shouldStopWith(/can't create matcher foo without a match/, function() {
return spectacular.matcher('foo', function() {});
});
return runningSpecs('matcher returning timing out promise').shouldFailWith(/1 failure/, function() {
return describe(timeout, function() {
return it(function() {
return should(timeout);
});
});
});
});
runningSpecs('missing dependency').shouldSucceedWith(/Warning: unmet dependency foo/, function() {
return describe('dependent', function() {
dependsOn('foo');
return it(function() {
return true.should(be(true));
});
});
});
runningSpecs('example depending on succeeding examples').shouldSucceedWith(/3 success, 3 assertions, 0 failures, 0 errors, 0 skipped/, function() {
describe('dependency 1', {
id: 'success1'
}, function() {
return it(function() {
return true.should(be(true));
});
});
describe('dependency 2', {
id: 'success2'
}, function() {
return it(function() {
return true.should(be(true));
});
});
return describe('dependent', function() {
dependsOn('success1');
dependsOn('success2');
return it(function() {
return true.should(be(true));
});
});
});
runningSpecs('example depending on a failing example').shouldFailWith(/1 failure, 0 errors, 1 skipped/, function() {
describe('dependency', {
id: 'top'
}, function() {
return context('succeeding', function() {
return it(function() {
return true.should(be(true));
});
});
});
describe('dependency failing', {
id: 'failure'
}, function() {
return it(function() {
return false.should(be(true));
});
});
return describe('dependent', function() {
dependsOn('top');
dependsOn('failure');
return it('should be skipped', function() {
return true.should(be(true));
});
});
});
runningSpecs('parent depending on child').shouldStopWith(/can't depends on ancestor/, function() {
return describe('parent', {
id: 'parent1'
}, function() {
return context('child', {
id: 'child1'
}, function() {
dependsOn('parent1');
return it(function() {
return true.should(be(true));
});
});
});
});
runningSpecs('child depending on parent').shouldStopWith(/can't depends on ancestor/, function() {
return describe('parent', {
id: 'parent2'
}, function() {
dependsOn('child2');
return context('child', {
id: 'child2'
}, function() {
return it(function() {
return true.should(be(true));
});
});
});
});
runningSpecs('circular dependencies').shouldStopWith(/circular dependencies between/, function() {
describe('cycle 1', {
id: 'c1'
}, function() {
dependsOn('c2');
return it(function() {
return true.should(be(true));
});
});
return describe('cycle 2', {
id: 'c2'
}, function() {
dependsOn('c1');
return it(function() {
return true.should(be(true));
});
});
});
runningSpecs('exclusive examples in group with dependencies').shouldSucceedWith(/3 success, 3 assertion/, function() {
describe('excluded groups', {
id: 'success'
}, function() {
it(function() {
return true.should(be(true));
});
return it(function() {
return true.should(be(true));
});
});
return describe('exclusive groups', function() {
dependsOn('success');
return only(it(function() {
return true.should(be(true));
}));
});
});
runningSpecs('deep circular dependencies').shouldStopWith(/circular dependencies between/, function() {
describe('cycle 1', {
id: 'c1'
}, function() {
describe('child 1', {
id: 'cc1'
}, function() {
return dependsOn('c2');
});
return it(function() {
return true.should(be(true));
});
});
return describe('cycle 2', {
id: 'c2'
}, function() {
dependsOn('cc1');
return it(function() {
return true.should(be(true));
});
});
});
runningSpecs('n+1 circular dependencies').shouldStopWith(/circular dependencies between/, function() {
describe('cycle 1', {
id: 'c1'
}, function() {
dependsOn('c2');
return it(function() {
return true.should(be(true));
});
});
describe('cycle 2', {
id: 'c2'
}, function() {
dependsOn('c3');
return it(function() {
return true.should(be(true));
});
});
return describe('cycle 3', {
id: 'c3'
}, function() {
dependsOn('c1');
return it(function() {
return true.should(be(true));
});
});
});
runningSpecs('cascading successful examples').shouldSucceedWith(/3 success, 3 assertions, 0 failures/, function() {
return describe('parent group', function() {
it(function() {
return true.should(be(true));
});
return whenPass(function() {
it(function() {
return true.should(be(true));
});
return whenPass(function() {
return context('in a nested context', function() {
return it(function() {
return true.should(be(true));
});
});
});
});
});
});
runningSpecs('cascading failing examples').shouldFailWith(/0 success, 1 assertion, 1 failure, (.*), 2 skipped/, function() {
return describe(null, function() {
it(function() {
return should(exist);
});
return whenPass(function() {
return context('skipped', function() {
it(function() {
return true.should(be(true));
});
return whenPass(function() {
return context('skipped', function() {
return it(function() {
return true.should(be(true));
});
});
});
});
});
});
});
runningSpecs('cascading & depenpent failing examples').shouldFailWith(/1 success, 2 assertions, 1 failure, (.*), 1 skipped/, function() {
describe('success group', {
id: 'success'
}, function() {
return it(function() {
return true.should(be(true));
});
});
return describe('parent group', function() {
it(function() {
return true.should(be(false));
});
return whenPass(function() {
dependsOn('success');
return context('skipped', function() {
return it(function() {
return true.should(be(true));
});
});
});
});
});
describe(spectacular.dom.DOMExpression, function() {
fixture('sample.html');
it(function() {
return should(exist);
});
return whenPass(function() {
given('dom', function() {
return 'html\n head\n body\n section\n header\n h1\n \'title\'\n article\n h3\n \'article title\'\n p\n /article content/\n\n footer';
});
withArguments(function() {
return [this.dom];
});
itsInstance(function() {
return should(exist);
});
itsInstance('source', function() {
return should(equal(this.dom));
});
describe('::match', function() {
itsReturn({
"with": (function() {
return [document.querySelector('html')];
})
}, function() {
return should(be(true));
});
itsReturn({
"with": (function() {
return [document.querySelector('#fixtures section')];
})
}, function() {
return should(be(false));
});
return itsReturn({
"with": (function() {
return [document.querySelectorAll('section')];
})
}, function() {
return should(be(false));
});
});
describe('::contained', function() {
itsReturn({
"with": (function() {
return [document.querySelector('html')];
})
}, function() {
return should(be(false));
});
context('with a dom looking for node content', function() {
given('dom', function() {
return 'article\n h3\n \'article title\'\n p\n /article.*content/';
});
return itsReturn({
"with": (function() {
return [document];
})
}, function() {
return should(be(true));
});
});
return context('with a dom failing after a negative indent', function() {
given('dom', function() {
return 'article\n h3\n \'article title\'\n p\n /article.*foo/';
});
return itsReturn({
"with": (function() {
return [document];
})
}, function() {
return should(be(false));
});
});
});
return context('with an invalid dom', function() {
subject(function() {
var _this = this;
return function() {
return new spectacular.dom.DOMExpression(_this.dom);
};
});
context('due to an invalid root indent', function() {
given('dom', function() {
return ' html';
});
return it(function() {
return should(throwAnError(/invalid indent on line 1/));
});
});
context('due to an invalid nested indent', function() {
given('dom', function() {
return 'html\n head';
});
return it(function() {
return should(throwAnError(/invalid indent on line 2/));
});
});
context('due to an incomplete indent', function() {
given('dom', function() {
return 'html\n head';
});
return it(function() {
return should(throwAnError(/invalid indent on line 2/));
});
});
return context('due to a child for text expression', function() {
given('dom', function() {
return 'html\n "text"\n div';
});
return it(function() {
return should(throwAnError(/text expressions cannot have children on line 3/));
});
});
});
});
});
describe(describe, function() {
runningSpecs('call in a describe block').shouldSucceedWith(/1 success/, function() {
return describe('foo', function() {
return describe('bar', function() {
subject(function() {
return true;
});
return it(function() {
return should(be(true));
});
});
});
});
runningSpecs('without examples').shouldSucceedWith(/1 pending/, function() {
return describe('foo', function() {});
});
return environmentMethod('describe').cannotBeCalledInsideIt();
});
describe(context, function() {
runningSpecs('call in a describe block').shouldSucceedWith(/1 success/, function() {
return describe('foo', function() {
return context('bar', function() {
subject(function() {
return true;
});
return it(function() {
return should(be(true));
});
});
});
});
return environmentMethod('context').cannotBeCalledInsideIt();
});
describe(xdescribe, function() {
runningSpecs('call at top level').shouldSucceedWith(/0 failures, (.*), 1 pending/, function() {
return xdescribe('pending examples', function() {
return it(function() {
return fail();
});
});
});
return environmentMethod('xdescribe').cannotBeCalledInsideIt();
});
describe(xcontext, function() {
runningSpecs('call at top level').shouldSucceedWith(/0 failures, (.*), 1 pending/, function() {
return xcontext('pending examples', function() {
return it(function() {
return fail();
});
});
});
return environmentMethod('xcontext').cannotBeCalledInsideIt();
});
describe(should, function() {
runningSpecs('call inside it').shouldSucceedWith(/1 success, 1 assertion/, function() {
return describe('foo', function() {
subject(function() {
return true;
});
return it(function() {
return should(be(true));
});
});
});
runningSpecs('call outside it').shouldStopWith(/should called outside a it block/, function() {
return describe('foo', function() {
return should(be(true));
});
});
return environmentMethod('should').cannotBeCalledWithoutMatcher();
});
describe(it, function() {
runningSpecs('call inside describe').shouldSucceedWith(/2 success, 2 assertion/, function() {
return describe('foo', function() {
subject(function() {
return true;
});
it(function() {
return should(be(true));
});
return it('with message', function() {
return should(be(true));
});
});
});
return environmentMethod('it').cannotBeCalledInsideIt();
});
describe(the, function() {
runningSpecs('call inside describe').shouldSucceedWith(/2 success, 2 assertion/, function() {
return describe('foo', function() {
subject(function() {
return true;
});
the(function() {
return should(be(true));
});
return the('with message', function() {
return should(be(true));
});
});
});
return environmentMethod('the').cannotBeCalledInsideIt();
});
describe(xit, function() {
runningSpecs('call inside describe').shouldSucceedWith(/2 pending/, function() {
return describe('foo', function() {
subject(function() {
return true;
});
xit(function() {
return should(be(true));
});
return xit('with message', function() {
return should(be(true));
});
});
});
return environmentMethod('xit').cannotBeCalledInsideIt();
});
describe(withParameters, function() {
runningSpecs('call inside describe').shouldSucceedWith(/1 success/, function() {
var f;
f = function(a) {
return a;
};
return describe(f, function() {
withParameters(10);
return itsReturn(function() {
return should(equal(10));
});
});
});
return environmentMethod('withParameters').cannotBeCalledInsideIt();
});
describe(withArguments, function() {
runningSpecs('call inside describe').shouldSucceedWith(/1 success/, function() {
var f;
f = function(a) {
return a;
};
return describe(f, function() {
withArguments(10);
return itsReturn(function() {
return should(equal(10));
});
});
});
return environmentMethod('withArguments').cannotBeCalledInsideIt();
});
describe(Object, function() {
return describe('::should', function() {
runningSpecs('call inside it').shouldSucceedWith(/1 success, 1 assertion/, function() {
return describe('foo', function() {
return the(function() {
return true.should(be(true));
});
});
});
runningSpecs('call inside it without matcher').shouldSucceedWith(/0 success, 0 assertions, (.*), 1 pending/, function() {
return describe('foo', function() {
return the(function() {
return {}.should();
});
});
});
return runningSpecs('call outside it').shouldStopWith(/should called outside a it block/, function() {
return describe('foo', function() {
return {}.should(be(true));
});
});
});
});
describe(before, function() {
runningSpecs('call in describe').shouldSucceedWith(/1 success/, function() {
return describe('foo', function() {
before(function() {
return this.object = {};
});
return the(function() {
return this.object.should(exist);
});
});
});
return environmentMethod('before').cannotBeCalledInsideIt();
});
describe(after, function() {
return environmentMethod('after').cannotBeCalledInsideIt();
});
describe(withParameters, function() {
return environmentMethod('withParameters').cannotBeCalledInsideIt();
});
describe(withArguments, function() {
return environmentMethod('withArguments').cannotBeCalledInsideIt();
});
describe(dependsOn, function() {
return environmentMethod('dependsOn').cannotBeCalledInsideIt();
});
describe(whenPass, function() {
return environmentMethod('whenPass').cannotBeCalledInsideIt();
});
describe(fixture, function() {
return environmentMethod('fixture').cannotBeCalledInsideIt();
});
describe(spyOn, function() {
return environmentMethod('spyOn').cannotBeCalledOutsideIt();
});
describe(itsReturn, function() {
environmentMethod('itsReturn').cannotBeCalledInsideIt();
return environmentMethod('itsReturn').cannotBeCalledWithoutPreviousSubject();
});
describe(itsInstance, function() {
environmentMethod('itsInstance').cannotBeCalledInsideIt();
environmentMethod('itsInstance').cannotBeCalledWithoutPreviousSubject();
return context('with a class that takes arguments in constructor', function() {
subject(function() {
var Foo;
return Foo = (function() {
function Foo(a, b) {
this.a = a;
this.b = b;
}
return Foo;
})();
});
itsInstance({
"with": [0, 1]
}, function() {
return should(exist);
});
itsInstance('a', {
"with": [0, 1]
}, function() {
return should(equal(0));
});
return itsInstance('b', {
"with": [0, 1]
}, function() {
return should(equal(1));
});
});
});
describe('expect(...).to', function() {
environmentMethod('expect').cannotBeCalledOutsideIt();
runningSpecs('call with only a value').withOption('documentation', true).shouldSucceedWith(/10 should be equal to 10/, function() {
return specify(function() {
return expect(10).to(equal(10));
});
});
runningSpecs('call with a description and a value').withOption('documentation', true).shouldSucceedWith(/a number should be equal to 10/, function() {
return specify(function() {
return expect('a number', 10).to(equal(10));
});
});
return runningSpecs('call without matcher').shouldFailWith(/called without a matcher/, function() {
return specify(function() {
return expect().to();
});
});
});
describe('expect(...).not.to', function() {
specify(function() {
return expect('a number', 5).not.to(equal(10));
});
return runningSpecs('call without matcher').shouldFailWith(/called without a matcher/, function() {
return specify(function() {
return expect().not.to();
});
});
});
runningSpecs('inner example alias').shouldSucceedWith(/1 success/, function() {
spectacular.env.createInnerExampleAlias('may', 'should');
return describe('foo', function() {
subject(function() {
return true;
});
return it(function() {
return may(be(true));
});
});
});
describe(spectacular.errors.ErrorParser, function() {
fixture('errors/firefox.txt', {
as: 'firefox'
});
fixture('errors/chrome.txt', {
as: 'chrome'
});
fixture('errors/node.txt', {
as: 'node'
});
given('parser', function() {
return new spectacular.errors.ErrorParser(this.stack);
});
context('for a chrome stack', function() {
given('stack', function() {
return this.chrome;
});
return itShould('match error');
});
context('for a node stack', function() {
given('stack', function() {
return this.node;
});
return itShould('match error');
});
context('for a firefox stack', function() {
given('stack', function() {
return this.firefox;
});
return itShould('match error');
});
context('for a native error', function() {
fixture('errors/firefox_native.txt', {
as: 'firefox'
});
fixture('errors/chrome_native.txt', {
as: 'chrome'
});
fixture('errors/node_native.txt', {
as: 'node'
});
context('for a chrome stack', function() {
given('stack', function() {
return this.chrome;
});
the(function() {
return this.parser.should(exist);
});
return the(function() {
return this.parser.details(this.parser.lines[0])["native"].should(be(true));
});
});
context('for a node stack', function() {
given('stack', function() {
return this.node;
});
the(function() {
return this.parser.should(exist);
});
return the(function() {
return this.parser.details(this.parser.lines[0])["native"].should(be(true));
});
});
return context('for a firefox stack', function() {
given('stack', function() {
return this.firefox;
});
the(function() {
return this.parser.should(exist);
});
return the(function() {
return this.parser.details(this.parser.lines[0]).line.should(equal('37'));
});
});
});
return context('with an error raised in an accessor', function() {
fixture('errors/firefox_accessor.txt', {
as: 'firefox'
});
fixture('errors/chrome_accessor.txt', {
as: 'chrome'
});
fixture('errors/node_accessor.txt', {
as: 'node'
});
context('for a chrome stack', function() {
given('stack', function() {
return this.chrome;
});
the(function() {
return this.parser.should(exist);
});
return the(function() {
return this.parser.details(this.parser.lines[0]).line.should(equal('83'));
});
});
context('for a node stack', function() {
given('stack', function() {
return this.node;
});
the(function() {
return this.parser.should(exist);
});
return the(function() {
return this.parser.details(this.parser.lines[0]).line.should(equal('83'));
});
});
return context('for a firefox stack', function() {
given('stack', function() {
return this.firefox;
});
the(function() {
return this.parser.should(exist);
});
return the(function() {
return this.parser.details(this.parser.lines[0]).line.should(equal('83'));
});
});
});
});
MixinWithIncludedHook = (function() {
function MixinWithIncludedHook() {}
MixinWithIncludedHook.included = function(cls) {
return cls.prototype.otherProperty = 'also irrelevant';
};
MixinWithIncludedHook.prototype.property = 'irrelevant';
return MixinWithIncludedHook;
})();
MixinWithoutIncludedHook = (function() {
function MixinWithoutIncludedHook() {}
MixinWithoutIncludedHook.prototype.property = 'irrelevant';
return MixinWithoutIncludedHook;
})();
MixinWithExcludedProperty = (function() {
function MixinWithExcludedProperty() {}
MixinWithExcludedProperty.prototype.property = 'irrelevant';
MixinWithExcludedProperty.prototype.otherProperty = 'also irrelevant';
MixinWithExcludedProperty.prototype.excluded = ['otherProperty'];
return MixinWithExcludedProperty;
})();
MixinWithExtendedHook = (function() {
function MixinWithExtendedHook() {}
MixinWithExtendedHook.extended = function(cls) {
return cls.otherProperty = 'also irrelevant';
};
MixinWithExtendedHook.property = 'irrelevant';
return MixinWithExtendedHook;
})();
MixinWithoutExtendedHook = (function() {
function MixinWithoutExtendedHook() {}
MixinWithoutExtendedHook.property = 'irrelevant';
return MixinWithoutExtendedHook;
})();
MixinWithExcludedClassProperty = (function() {
function MixinWithExcludedClassProperty() {}
MixinWithExcludedClassProperty.property = 'irrelevant';
MixinWithExcludedClassProperty.otherProperty = 'also irrelevant';
MixinWithExcludedClassProperty.excluded = ['otherProperty'];
return MixinWithExcludedClassProperty;
})();
ConcernWithIncludedAndExcluded = (function() {
function ConcernWithIncludedAndExcluded() {}
ConcernWithIncludedAndExcluded.included = function(cls) {
return cls.prototype.otherProperty = 'also irrelevant';
};
ConcernWithIncludedAndExcluded.extended = function(cls) {
return cls.otherProperty = 'also irrelevant';
};
ConcernWithIncludedAndExcluded.property = 'irrelevant';
ConcernWithIncludedAndExcluded.prototype.property = 'irrelevant';
return ConcernWithIncludedAndExcluded;
})();
ConcernWithExcludedHook = (function() {
function ConcernWithExcludedHook() {}
ConcernWithExcludedHook.property = 'irrelevant';
ConcernWithExcludedHook.otherProperty = 'also irrelevant';
ConcernWithExcludedHook.prototype.property = 'irrelevant';
ConcernWithExcludedHook.prototype.otherProperty = 'also irrelevant';
ConcernWithExcludedHook.excluded = ['otherProperty'];
ConcernWithExcludedHook.prototype.excluded = ['property'];
return ConcernWithExcludedHook;
})();
describe(Function, function() {
given('dummy', function() {
var DummyClass;
return DummyClass = (function() {
function DummyClass() {}
return DummyClass;
})();
});
describe('::include', function() {
context('with a mixin that do not define the included hook', function() {
before(function() {
return this.dummy.include(MixinWithoutIncludedHook);
});
subject(function() {
return new this.dummy;
});
return its('property', function() {
return should(equal('irrelevant'));
});
});
context('with a mixin that define the included hook', function() {
before(function() {
return this.dummy.include(MixinWithIncludedHook);
});
subject(function() {
return new this.dummy;
});
its('property', function() {
return should(equal('irrelevant'));
});
return its('otherProperty', function() {
return should(equal('also irrelevant'));
});
});
return context('with a mixin that define the excluded hook', function() {
before(function() {
return this.dummy.include(MixinWithExcludedProperty);
});
subject(function() {
return new this.dummy;
});
its('property', function() {
return should(equal('irrelevant'));
});
return its('otherProperty', function() {
return shouldnt(exist);
});
});
});
describe('::extend', function() {
context('with a mixin that do not define the extended hook', function() {
before(function() {
return this.dummy.extend(MixinWithoutExtendedHook);
});
subject(function() {
return this.dummy;
});
return its('property', function() {
return should(equal('irrelevant'));
});
});
context('with a mixin that define the extended hook', function() {
before(function() {
return this.dummy.extend(MixinWithExtendedHook);
});
subject(function() {
return this.dummy;
});
its('property', function() {
return should(equal('irrelevant'));
});
return its('otherProperty', function() {
return should(equal('also irrelevant'));
});