[Groonga-commit] droonga/fluent-plugin-droonga at 2da88ba [master] Test: use stub method instead of mock

Back to archive index

YUKI Hiroshi null+****@clear*****
Wed Nov 20 14:22:43 JST 2013


YUKI Hiroshi	2013-11-20 14:22:43 +0900 (Wed, 20 Nov 2013)

  New Revision: 2da88ba0136bac42bc8fab6026817331caa719f1
  https://github.com/droonga/fluent-plugin-droonga/commit/2da88ba0136bac42bc8fab6026817331caa719f1

  Message:
    Test: use stub method instead of mock

  Copied files:
    test/helper/handler_helper.rb
      (from test/helper.rb)
  Modified files:
    test/helper.rb
    test/plugin/handler/groonga/test_table_create.rb
    test/plugin/handler/test_handler_groonga.rb

  Modified: test/helper.rb (+1 -0)
===================================================================
--- test/helper.rb    2013-11-20 14:02:35 +0900 (acb1c6e)
+++ test/helper.rb    2013-11-20 14:22:43 +0900 (f3a09be)
@@ -16,6 +16,7 @@
 require_relative "helper/sandbox"
 require_relative "helper/fixture"
 require_relative "helper/stub_worker"
+require_relative "helper/handler_helper"
 require_relative "helper/watch_helper"
 
 class Test::Unit::TestCase

  Copied: test/helper/handler_helper.rb (+8 -7) 77%
===================================================================
--- test/helper.rb    2013-11-20 14:02:35 +0900 (acb1c6e)
+++ test/helper/handler_helper.rb    2013-11-20 14:22:43 +0900 (5d2ed2d)
@@ -13,12 +13,13 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-require_relative "helper/sandbox"
-require_relative "helper/fixture"
-require_relative "helper/stub_worker"
-require_relative "helper/watch_helper"
+module HandlerHelper
+  attr_reader :emitted
 
-class Test::Unit::TestCase
-  include Sandbox
-  include Fixture
+  def setup_stub_emit(handler)
+    @emitted = nil
+    stub(handler).emit do |response|
+      @emitted = response
+    end
+  end
 end

  Modified: test/plugin/handler/groonga/test_table_create.rb (+10 -10)
===================================================================
--- test/plugin/handler/groonga/test_table_create.rb    2013-11-20 14:02:35 +0900 (fa5797a)
+++ test/plugin/handler/groonga/test_table_create.rb    2013-11-20 14:22:43 +0900 (c8aa7f8)
@@ -15,25 +15,25 @@
 
 class TableCreateTest < GroongaHandlerTest
   def test_success
-    mock(@handler).emit([true])
+    setup_stub_emit(@handler)
     @handler.table_create({"name" => "Books"})
     assert_equal(
       [[Droonga::GroongaHandler::Status::SUCCESS, NORMALIZED_START_TIME, NORMALIZED_ELAPSED_TIME], true],
-      [normalize_header(@worker.body.first), @worker.body.last]
+      [normalize_header(emitted.first), emitted.last]
     )
   end
 
   def test_failure
-    mock(@handler).emit([false])
+    setup_stub_emit(@handler)
     @handler.table_create({})
     assert_equal(
       [[Droonga::GroongaHandler::Status::INVALID_ARGUMENT, NORMALIZED_START_TIME, NORMALIZED_ELAPSED_TIME], false],
-      [normalize_header(@worker.body.first), @worker.body.last]
+      [normalize_header(emitted.first), emitted.last]
     )
   end
 
   def test_name
-    mock(@handler).emit([true])
+    setup_stub_emit(@handler)
     @handler.table_create({"name" => "Books"})
     assert_equal(<<-SCHEMA, dump)
 table_create Books TABLE_HASH_KEY --key_type ShortText
@@ -84,7 +84,7 @@ table_create Books TABLE_NO_KEY
         "name" => "Books",
         "flags" => data[:flags],
       }
-      mock(@handler).emit([true])
+      setup_stub_emit(@handler)
       @handler.table_create(request)
       assert_equal(data[:schema], dump)
     end
@@ -96,7 +96,7 @@ table_create Books TABLE_NO_KEY
         "name"  => "Books",
         "key_type" => "Int32",
       }
-      mock(@handler).emit([true])
+      setup_stub_emit(@handler)
       @handler.table_create(request)
       assert_equal(<<-SCHEMA, dump)
 table_create Books TABLE_HASH_KEY --key_type Int32
@@ -110,7 +110,7 @@ table_create Books TABLE_HASH_KEY --key_type Int32
         "name"  => "Books",
         "value_type" => "Int32",
       }
-      mock(@handler).emit([true])
+      setup_stub_emit(@handler)
       @handler.table_create(request)
       assert_equal(<<-SCHEMA, dump)
 table_create Books TABLE_HASH_KEY --key_type ShortText --value_type Int32
@@ -124,7 +124,7 @@ table_create Books TABLE_HASH_KEY --key_type ShortText --value_type Int32
         "name"  => "Books",
         "default_tokenizer" => "TokenBigram",
       }
-      mock(@handler).emit([true])
+      setup_stub_emit(@handler)
       @handler.table_create(request)
       assert_equal(<<-SCHEMA, dump)
 table_create Books TABLE_HASH_KEY --key_type ShortText --default_tokenizer TokenBigram
@@ -138,7 +138,7 @@ table_create Books TABLE_HASH_KEY --key_type ShortText --default_tokenizer Token
         "name"  => "Books",
         "normalizer" => "NormalizerAuto",
       }
-      mock(@handler).emit([true])
+      setup_stub_emit(@handler)
       @handler.table_create(request)
       assert_equal(<<-SCHEMA, dump)
 table_create Books TABLE_HASH_KEY|KEY_NORMALIZE --key_type ShortText

  Modified: test/plugin/handler/test_handler_groonga.rb (+2 -0)
===================================================================
--- test/plugin/handler/test_handler_groonga.rb    2013-11-20 14:02:35 +0900 (683cdf5)
+++ test/plugin/handler/test_handler_groonga.rb    2013-11-20 14:22:43 +0900 (aef9aa8)
@@ -16,6 +16,8 @@
 require "droonga/plugin/handler_groonga"
 
 class GroongaHandlerTest < Test::Unit::TestCase
+  include HandlerHelper
+
   def setup
     setup_database
     setup_handler
-------------- next part --------------
HTML����������������������������...
다운로드 



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