Skip to content

Commit

Permalink
Merge pull request mochajs#1164 from park9140/sibling-suites-have-sep…
Browse files Browse the repository at this point in the history
…arate-context

Make sibling Suites have separate contexts
  • Loading branch information
travisjeffery committed Apr 17, 2014
2 parents 638e049 + 6c705cd commit ca35545
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
6 changes: 4 additions & 2 deletions lib/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ exports.create = function(parent, title){
* @api private
*/

function Suite(title, ctx) {
function Suite(title, parentContext) {
this.title = title;
this.ctx = ctx;
var context = function() {};
context.prototype = parentContext;
this.ctx = new context();
this.suites = [];
this.tests = [];
this.pending = false;
Expand Down
6 changes: 4 additions & 2 deletions mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -5065,9 +5065,11 @@ exports.create = function(parent, title){
* @api private
*/

function Suite(title, ctx) {
function Suite(title, parentContext) {
this.title = title;
this.ctx = ctx;
var context = function () {};
context.prototype = parentContext;
this.ctx = new context();
this.suites = [];
this.tests = [];
this.pending = false;
Expand Down
43 changes: 42 additions & 1 deletion test/acceptance/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,45 @@ describe('Context', function(){
after(function(){
this.calls.should.eql(['before', 'before two', 'test', 'after two']);
})
})
})

describe('Context Siblings', function(){
beforeEach(function(){
this.calls = ['before'];
})

describe('sequestered sibling', function(){
beforeEach(function(){
this.calls.push('before two');
this.hiddenFromSibling = 'This should be hidden';
})

it('should work', function(){
this.hiddenFromSibling.should.eql('This should be hidden')
})
})

describe('sibling verifiction', function(){
beforeEach(function(){
this.calls.push('before sibling');
})

it('should not have value set within a sibling describe', function(){
'This should be hidden'.should.not.eql(this.hiddenFromSibling);
this.visibleFromTestSibling = 'Visible from test sibling';
})

it('should allow test siblings to modify shared context', function(){
'Visible from test sibling'.should.eql(this.visibleFromTestSibling);
})

it('should have reset this.calls before describe', function(){
this.calls.should.eql(['before', 'before sibling']);
})
})

after(function(){
this.calls.should.eql(['before', 'before sibling']);
})

})

0 comments on commit ca35545

Please sign in to comment.