[Groonga-commit] ranguba/chupa-text at 0b7746f [master] Raise error when Decomposer doesn't implement required methods

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Jan 1 23:06:40 JST 2014


Kouhei Sutou	2014-01-01 23:06:40 +0900 (Wed, 01 Jan 2014)

  New Revision: 0b7746f5fe25019e4d10f3f4b100ddfcda4d77cd
  https://github.com/ranguba/chupa-text/commit/0b7746f5fe25019e4d10f3f4b100ddfcda4d77cd

  Message:
    Raise error when Decomposer doesn't implement required methods

  Copied files:
    test/test-decomposer.rb
      (from lib/chupa-text/decomposer.rb)
  Modified files:
    lib/chupa-text/decomposer.rb

  Modified: lib/chupa-text/decomposer.rb (+2 -1)
===================================================================
--- lib/chupa-text/decomposer.rb    2014-01-01 23:02:11 +0900 (9585eca)
+++ lib/chupa-text/decomposer.rb    2014-01-01 23:06:40 +0900 (9a38b58)
@@ -36,10 +36,11 @@ module ChupaText
     end
 
     def target?(data)
-      false
+      raise NotImplementedError, "must implement #{self.class}\##{__method__}"
     end
 
     def decompose(data)
+      raise NotImplementedError, "must implement #{self.class}\##{__method__}"
     end
   end
 end

  Copied: test/test-decomposer.rb (+17 -21) 57%
===================================================================
--- lib/chupa-text/decomposer.rb    2014-01-01 23:02:11 +0900 (9585eca)
+++ test/test-decomposer.rb    2014-01-01 23:06:40 +0900 (1592b9d)
@@ -14,32 +14,28 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
-require "chupa-text/decomposer-registory"
-
-module ChupaText
-  class Decomposer
-    class << self
-      def registory
-        @@registory ||= DecomposerRegistory.new
-      end
+class TestDecomposer < Test::Unit::TestCase
+  sub_test_case("not-implemented") do
+    class NotImplementedDecomposer < ChupaText::Decomposer
+    end
 
-      def load
-        $LOAD_PATH.each do |load_path|
-          next unless File.directory?(load_path)
-          Dir.chdir(load_path) do
-            Dir.glob("chupa-text/plugin/decomposer/*.rb") do |plugin_path|
-              require plugin_path.gsub(/\.rb\z/, "")
-            end
-          end
-        end
-      end
+    def setup
+      @decomposer = NotImplementedDecomposer.new
+      @data = ChupaText::Data.new
     end
 
-    def target?(data)
-      false
+    def test_target?
+      message = "must implement #{NotImplementedDecomposer}\#target?"
+      assert_raise(NotImplementedError.new(message)) do
+        @decomposer.target?(@data)
+      end
     end
 
-    def decompose(data)
+    def test_decompose
+      message = "must implement #{NotImplementedDecomposer}\#decompose"
+      assert_raise(NotImplementedError.new(message)) do
+        @decomposer.decompose(@data)
+      end
     end
   end
 end
-------------- next part --------------
HTML����������������������������...
Download 



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