[Groonga-commit] groonga/groonga [master] [test] extract outputy_type dependent helpers

アーカイブの一覧に戻る

null+****@clear***** null+****@clear*****
2011年 12月 19日 (月) 17:49:57 JST


Yoji SHIDARA	2011-12-19 08:49:57 +0000 (Mon, 19 Dec 2011)

  New Revision: c73fbdef60fffcdd8c934fc3b73ab3daf5606346

  Log:
    [test] extract outputy_type dependent helpers

  Modified files:
    test/unit/http/test-http.rb
    test/unit/lib/ruby/groonga-http-test-utils.rb

  Modified: test/unit/http/test-http.rb (+2 -26)
===================================================================
--- test/unit/http/test-http.rb    2011-12-19 08:43:54 +0000 (5de2878)
+++ test/unit/http/test-http.rb    2011-12-19 08:49:57 +0000 (a09cf6a)
@@ -90,6 +90,7 @@ end
 
 class JSONHTTPTest < Test::Unit::TestCase
   include HTTPTests
+  include Format::JSON
 
   def test_jsonp
     response = get(command_path(:status,
@@ -98,34 +99,9 @@ class JSONHTTPTest < Test::Unit::TestCase
     assert_equal(content_type, response.content_type)
     assert_match(/\Afunc\(.+\);\z/, response.body)
   end
-
-  private
-  def output_type
-    nil
-  end
-
-  def content_type
-    "application/json"
-  end
-
-  def parse(response)
-    JSON.parse(response)
-  end
 end
 
 class MessagePackHTTPTest < Test::Unit::TestCase
   include HTTPTests
-
-  private
-  def output_type
-    "msgpack"
-  end
-
-  def content_type
-    "application/x-msgpack"
-  end
-
-  def parse(response)
-    MessagePack.unpack(response)
-  end
+  include Format::MessagePack
 end

  Modified: test/unit/lib/ruby/groonga-http-test-utils.rb (+38 -5)
===================================================================
--- test/unit/lib/ruby/groonga-http-test-utils.rb    2011-12-19 08:43:54 +0000 (f76fdc3)
+++ test/unit/lib/ruby/groonga-http-test-utils.rb    2011-12-19 08:49:57 +0000 (c0c8d10)
@@ -19,10 +19,43 @@ require 'groonga-test-utils'
 require 'net/http'
 require 'cgi'
 require 'json'
+require 'msgpack'
 
 module GroongaHTTPTestUtils
   include GroongaTestUtils
 
+  module Format
+    module JSON
+      private
+      def output_type
+        nil
+      end
+
+      def content_type
+        "application/json"
+      end
+
+      def parse(response)
+        ::JSON.parse(response)
+      end
+    end
+
+    module MessagePack
+      private
+      def output_type
+        "msgpack"
+      end
+
+      def content_type
+        "application/x-msgpack"
+      end
+
+      def parse(response)
+        ::MessagePack.unpack(response)
+      end
+    end
+  end
+
   def setup_server
     super("http")
   end
@@ -204,7 +237,7 @@ module GroongaHTTPTestUtils
   end
 
   def json(object)
-    JSON.generate(object)
+    ::JSON.generate(object)
   end
 
   def success_status_response
@@ -222,16 +255,16 @@ module GroongaHTTPTestUtils
     case response.content_type
     when "application/json"
       begin
-        actual = JSON.parse(response.body)
-      rescue JSON::ParserError => e
+        actual = ::JSON.parse(response.body)
+      rescue ::JSON::ParserError => e
         raise "JSON ParserError #{e.message}\nJSON is ...\n" \
               "---\n#{response.body}\n---"
       end
       normalize_structured_response(actual)
     when "application/x-msgpack"
       begin
-        actual = MessagePack.unpack(response.body)
-      rescue MessagePack::UnpackError => e
+        actual = ::MessagePack.unpack(response.body)
+      rescue ::MessagePack::UnpackError => e
         raise "MessagePack UnpackError #{e.message}\nMessagePack is ...\n" \
               "---\n#{response.body}\n---"
       end




Groonga-commit メーリングリストの案内
アーカイブの一覧に戻る