[MediaWiki-commits] [Gerrit] Extends QUnit.parameterize to take a callback providing the ... - change (mediawiki...DataValues)

2013-05-08 Thread Daniel Werner (Code Review)
Daniel Werner has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/62798


Change subject: Extends QUnit.parameterize to take a callback providing the 
test cases
..

Extends QUnit.parameterize to take a callback providing the test cases

By providing a callback, the parameters provided to the tests will be created 
separately for each
test. This allows to provide instances which involve state without running into 
problems when
manipulating state in one test case but expecting initial state in another one.

NOTE: We should probably make a fork of jQuery.parameterize and import its 
tests, adjust them
  to properly run in our environment. Also renaming things, like 
QUnit.cases which should
  perhaps better be QUnit.provide.

This change set also changes some usage of QUnit.parameterize in our tests to 
use a callback now.

Change-Id: I18247a7a43c39c634745e9e925d846b060772927
---
M DataValues/resources/qunit.parameterize/qunit.parameterize.js
M ValueView/tests/qunit/jquery.valueview/valueview.tests.testExpert.js
2 files changed, 29 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/DataValues 
refs/changes/98/62798/1

diff --git a/DataValues/resources/qunit.parameterize/qunit.parameterize.js 
b/DataValues/resources/qunit.parameterize/qunit.parameterize.js
index 5fe90a4..24daae7 100644
--- a/DataValues/resources/qunit.parameterize/qunit.parameterize.js
+++ b/DataValues/resources/qunit.parameterize/qunit.parameterize.js
@@ -21,6 +21,15 @@
 QUnit.cases = ( function( QUnit ) {
'use strict';
 
+   /**
+* @param {[]|Function} testCases An Array (or a callback returning 
such an object) which
+*has to hold different Objects where each defines what will be 
passed to tests which
+*will be registered to the Object returned by the function. By 
providing a callback,
+*the parameters provided to the tests will be created 
separately for each test. This
+*allows to provide instances which involve state without 
running into problems when
+*manipulating state in one test case but expecting initial 
state in another one.
+* @return {Object}
+*/
return function(testCases) {
var createTest = function(methodName, title, expected, 
callback, parameters) {
QUnit[methodName](
@@ -38,8 +47,12 @@
expected = null;
}
 
-   for (var i = 0; i  testCases.length; ++i) {
-   var parameters = testCases[i];
+   var testTestCases = QUnit.is( function, testCases )
+   ? testCases()
+   : testCases;
+
+   for (var i = 0; i  testTestCases.length; ++i) {
+   var parameters = testTestCases[i];
 
var testCaseTitle = title;
if (parameters.title) {
diff --git 
a/ValueView/tests/qunit/jquery.valueview/valueview.tests.testExpert.js 
b/ValueView/tests/qunit/jquery.valueview/valueview.tests.testExpert.js
index 32d1ef3..e7a333d 100644
--- a/ValueView/tests/qunit/jquery.valueview/valueview.tests.testExpert.js
+++ b/ValueView/tests/qunit/jquery.valueview/valueview.tests.testExpert.js
@@ -99,7 +99,12 @@
return experts;
}
 
-   var expertCases = QUnit.cases( expertProvider() );
+   var expertCases = QUnit.cases(
+   // provide fresh instances for each test
+   function() {
+   return expertProvider();
+   }
+   );
 
expertCases.test( 'constructor', function( args, assert ) {
assert.ok(
@@ -164,6 +169,14 @@
);
} );
 
+   expertCases.test( 'rawValue: initial value', function( args, assert ) {
+   assert.equal(
+   args.expert.rawValue(),
+   null,
+   'newly initialized expert has no value (rawValue() 
returns null)'
+   );
+   } );
+
expertCases.test( 'rawValue: setting and getting raw value', function( 
args, assert ) {
var expert = args.expert;
 

-- 
To view, visit https://gerrit.wikimedia.org/r/62798
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I18247a7a43c39c634745e9e925d846b060772927
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Daniel Werner daniel.wer...@wikimedia.de

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] Extends QUnit.parameterize to take a callback providing the ... - change (mediawiki...DataValues)

2013-05-08 Thread Tobias Gritschacher (Code Review)
Tobias Gritschacher has submitted this change and it was merged.

Change subject: Extends QUnit.parameterize to take a callback providing the 
test cases
..


Extends QUnit.parameterize to take a callback providing the test cases

By providing a callback, the parameters provided to the tests will be created 
separately for each
test. This allows to provide instances which involve state without running into 
problems when
manipulating state in one test case but expecting initial state in another one.

NOTE: We should probably make a fork of jQuery.parameterize and import its 
tests, adjust them
  to properly run in our environment. Also renaming things, like 
QUnit.cases which should
  perhaps better be QUnit.provide.

This change set also changes some usage of QUnit.parameterize in our tests to 
use a callback now.

Change-Id: I18247a7a43c39c634745e9e925d846b060772927
---
M DataValues/resources/qunit.parameterize/qunit.parameterize.js
M ValueView/tests/qunit/jquery.valueview/valueview.tests.testExpert.js
2 files changed, 29 insertions(+), 3 deletions(-)

Approvals:
  Tobias Gritschacher: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/DataValues/resources/qunit.parameterize/qunit.parameterize.js 
b/DataValues/resources/qunit.parameterize/qunit.parameterize.js
index 5fe90a4..24daae7 100644
--- a/DataValues/resources/qunit.parameterize/qunit.parameterize.js
+++ b/DataValues/resources/qunit.parameterize/qunit.parameterize.js
@@ -21,6 +21,15 @@
 QUnit.cases = ( function( QUnit ) {
'use strict';
 
+   /**
+* @param {[]|Function} testCases An Array (or a callback returning 
such an object) which
+*has to hold different Objects where each defines what will be 
passed to tests which
+*will be registered to the Object returned by the function. By 
providing a callback,
+*the parameters provided to the tests will be created 
separately for each test. This
+*allows to provide instances which involve state without 
running into problems when
+*manipulating state in one test case but expecting initial 
state in another one.
+* @return {Object}
+*/
return function(testCases) {
var createTest = function(methodName, title, expected, 
callback, parameters) {
QUnit[methodName](
@@ -38,8 +47,12 @@
expected = null;
}
 
-   for (var i = 0; i  testCases.length; ++i) {
-   var parameters = testCases[i];
+   var testTestCases = QUnit.is( function, testCases )
+   ? testCases()
+   : testCases;
+
+   for (var i = 0; i  testTestCases.length; ++i) {
+   var parameters = testTestCases[i];
 
var testCaseTitle = title;
if (parameters.title) {
diff --git 
a/ValueView/tests/qunit/jquery.valueview/valueview.tests.testExpert.js 
b/ValueView/tests/qunit/jquery.valueview/valueview.tests.testExpert.js
index 32d1ef3..e7a333d 100644
--- a/ValueView/tests/qunit/jquery.valueview/valueview.tests.testExpert.js
+++ b/ValueView/tests/qunit/jquery.valueview/valueview.tests.testExpert.js
@@ -99,7 +99,12 @@
return experts;
}
 
-   var expertCases = QUnit.cases( expertProvider() );
+   var expertCases = QUnit.cases(
+   // provide fresh instances for each test
+   function() {
+   return expertProvider();
+   }
+   );
 
expertCases.test( 'constructor', function( args, assert ) {
assert.ok(
@@ -164,6 +169,14 @@
);
} );
 
+   expertCases.test( 'rawValue: initial value', function( args, assert ) {
+   assert.equal(
+   args.expert.rawValue(),
+   null,
+   'newly initialized expert has no value (rawValue() 
returns null)'
+   );
+   } );
+
expertCases.test( 'rawValue: setting and getting raw value', function( 
args, assert ) {
var expert = args.expert;
 

-- 
To view, visit https://gerrit.wikimedia.org/r/62798
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I18247a7a43c39c634745e9e925d846b060772927
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/DataValues
Gerrit-Branch: master
Gerrit-Owner: Daniel Werner daniel.wer...@wikimedia.de
Gerrit-Reviewer: Tobias Gritschacher tobias.gritschac...@wikimedia.de
Gerrit-Reviewer: jenkins-bot

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org