[Groonga-commit] droonga/express-droonga at b829fb1 [master] test: extract common code to keep only important thing in test function

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Apr 30 18:26:33 JST 2014


Kouhei Sutou	2014-04-30 18:26:33 +0900 (Wed, 30 Apr 2014)

  New Revision: b829fb10f099fcb1b5d7ca21d4ea53e4dba5bb18
  https://github.com/droonga/express-droonga/commit/b829fb10f099fcb1b5d7ca21d4ea53e4dba5bb18

  Message:
    test: extract common code to keep only important thing in test function

  Modified files:
    test/adapter/api/groonga/load.test.js

  Modified: test/adapter/api/groonga/load.test.js (+20 -23)
===================================================================
--- test/adapter/api/groonga/load.test.js    2014-04-30 18:05:32 +0900 (7afa5dd)
+++ test/adapter/api/groonga/load.test.js    2014-04-30 18:26:33 +0900 (8913e5d)
@@ -311,19 +311,13 @@ suite('adapter/api/groonga: load', function() {
     });
 
     suite('GET', function() {
-      test('object style', function(done) {
+      function get(values) {
         var requestBody;
         backend.reserveResponse(function(requestPacket) {
           requestBody = requestPacket[2].body;
           return utils.createReplyPacket(requestPacket, successMessage);
         });
-        var values = [
-          {
-            _key: 'alice',
-            name: 'Alice',
-            age: 20
-          }
-        ];
+
         var path = {
           pathname: '/d/load',
           query: {
@@ -331,8 +325,23 @@ suite('adapter/api/groonga: load', function() {
             values: JSON.stringify(values)
           }
         };
-        utils.get(path)
+
+        return utils.get(path)
           .next(function(response) {
+            return requestBody;
+          });
+      };
+
+      test('object style', function(done) {
+        var values = [
+          {
+            _key: 'alice',
+            name: 'Alice',
+            age: 20
+          }
+        ];
+        get(values)
+          .next(function(requestBody) {
             assert.deepEqual(requestBody,
                              {
                                table: 'Users',
@@ -350,11 +359,6 @@ suite('adapter/api/groonga: load', function() {
       });
 
       test('array style', function(done) {
-        var requestBody;
-        backend.reserveResponse(function(requestPacket) {
-          requestBody = requestPacket[2].body;
-          return utils.createReplyPacket(requestPacket, successMessage);
-        });
         var values = [
           [
             '_key',
@@ -367,15 +371,8 @@ suite('adapter/api/groonga: load', function() {
             20
           ]
         ];
-        var path = {
-          pathname: '/d/load',
-          query: {
-            table: 'Users',
-            values: JSON.stringify(values)
-          }
-        };
-        utils.get(path)
-          .next(function(response) {
+        get(values)
+          .next(function(requestBody) {
             assert.deepEqual(requestBody,
                              {
                                table: 'Users',
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index