Skip to content

Commit

Permalink
Merge branch 't/31'. Closes #31.
Browse files Browse the repository at this point in the history
  • Loading branch information
oleq committed Oct 15, 2015
2 parents 559cb19 + a419e0c commit ffda447
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
3 changes: 2 additions & 1 deletion dev/bender/plugins/ckeditor5/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

var path = require( 'path' );
var files = [
path.join( __dirname, '../static/extensions.js' )
path.join( __dirname, '../static/extensions.js' ),
path.join( __dirname, '../static/tools.js' )
];

module.exports = {
Expand Down
51 changes: 51 additions & 0 deletions dev/bender/plugins/ckeditor5/static/tools.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

/* globals bender, before, afterEach, sinon */

'use strict';

( function() {
/**
* Test tools for CKEditor.
*
* This is a main namespace for the test tools.
*
* * General tools go directly to `bender.tools.*`.
* * Core tools (introduced by `ckeditor5-core`) go to `bender.tools.core.*`.
* * Plugin tools (introduced by plugins) go to `bender.tools.plugin.<plugin-name>.*`.
*
* Tools for specific plugins or the core should be kept in `tests/_tools/tools.js` file
* of the respective repository. They can be loaded using Bender's `bender-include` directive.
* Their tests should be kept in `tests/bender/*` directory.
*/
bender.tools = {
/**
* Creates Sinon sandbox in {@link bender#sinon} and plugs `afterEach()` callback which
* restores all spies and stubs created in this sandbox.
*
* See https://github.com/ckeditor/ckeditor5-design/issues/72 and http://sinonjs.org/docs/#sinon-sandbox
*
* Usage:
*
* // Directly in the test file:
* bender.tools.createSinonSandbox();
*
* // Then inside tests you can use bender.sinon:
* it( 'does something', function() {
* bender.sinon.spy( obj, 'method' );
* } );
*/
createSinonSandbox() {
before( function() {
bender.sinon = sinon.sandbox.create();
} );

afterEach( function() {
bender.sinon.restore();
} );
}
};
} )();
35 changes: 35 additions & 0 deletions tests/bender/createsinonsandbox.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* @license Copyright (c) 2003-2015, CKSource - Frederico Knabben. All rights reserved.
* For licensing, see LICENSE.md.
*/

'use strict';

var obj = {
method() {}
};
var spy;
var origMethod = obj.method;

bender.tools.createSinonSandbox();

describe( 'bender.tools.createSinonSandbox()', function() {
it( 'creates a sandbox', function() {
expect( bender.sinon ).to.be.an( 'object' );
expect( bender.sinon ).to.have.property( 'spy' );
} );

// This test is needed for the following one.
it( 'really works', function() {
spy = bender.sinon.spy( obj, 'method' );

expect( obj ).to.have.property( 'method', spy );
} );

it( 'restores spies after each test', function() {
obj.method();

sinon.assert.notCalled( spy );
expect( obj ).to.have.property( 'method', origMethod );
} );
} );

0 comments on commit ffda447

Please sign in to comment.