aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorToshiaki Asai <toshi.alternative@gmail.com>2013-04-03 10:29:01 +0900
committerToshiaki Asai <toshi.alternative@gmail.com>2013-04-04 11:33:44 +0900
commit3aa4cadc967a635e0da86b20baf88831fca713f7 (patch)
tree895ee881fe4bf465b82e594fa7565a5a86605740 /test
parenta9d6778796d69ab2ecc2a5fa63f79338521dc456 (diff)
downloadmikutter-3aa4cadc967a635e0da86b20baf88831fca713f7.tar.gz
プラグインのロード、依存解決を Miquire::Plugin に移動
Diffstat (limited to 'test')
-rw-r--r--test/core/miquire/plugin/child/child.rb5
-rw-r--r--test/core/miquire/plugin/child/spec9
-rw-r--r--test/core/miquire/plugin/display_requirements.rb0
-rw-r--r--test/core/miquire/plugin/parent/parent.rb5
-rw-r--r--test/core/miquire/plugin/parent/spec9
-rw-r--r--test/core/miquire/plugin/parent_not_found/parent_not_found.rb5
-rw-r--r--test/core/miquire/plugin/parent_not_found/spec9
-rw-r--r--test/core/miquire/plugin/standalone/standalone.rb5
-rw-r--r--test/core/miquire/plugin/tooold/spec9
-rw-r--r--test/core/miquire/plugin/tooold/tooold.rb5
-rw-r--r--test/core/test_miquire.rb18
-rw-r--r--test/core/test_miquire_plugin.rb101
-rw-r--r--test/core/test_plugin.rb17
13 files changed, 162 insertions, 35 deletions
diff --git a/test/core/miquire/plugin/child/child.rb b/test/core/miquire/plugin/child/child.rb
new file mode 100644
index 00000000..e26b8f98
--- /dev/null
+++ b/test/core/miquire/plugin/child/child.rb
@@ -0,0 +1,5 @@
+# -*- coding: utf-8 -*-
+
+Plugin.create(:child) do
+
+end
diff --git a/test/core/miquire/plugin/child/spec b/test/core/miquire/plugin/child/spec
new file mode 100644
index 00000000..0ed80ff6
--- /dev/null
+++ b/test/core/miquire/plugin/child/spec
@@ -0,0 +1,9 @@
+---
+slug: :child
+depends:
+ mikutter: 0.2.2.1150
+ plugin: [parent]
+version: '1.0'
+author: toshi_a
+name: child plugin
+description: dependency test
diff --git a/test/core/miquire/plugin/display_requirements.rb b/test/core/miquire/plugin/display_requirements.rb
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/core/miquire/plugin/display_requirements.rb
diff --git a/test/core/miquire/plugin/parent/parent.rb b/test/core/miquire/plugin/parent/parent.rb
new file mode 100644
index 00000000..136fb7fd
--- /dev/null
+++ b/test/core/miquire/plugin/parent/parent.rb
@@ -0,0 +1,5 @@
+# -*- coding: utf-8 -*-
+
+Plugin.create(:parent) do
+
+end
diff --git a/test/core/miquire/plugin/parent/spec b/test/core/miquire/plugin/parent/spec
new file mode 100644
index 00000000..75ffd569
--- /dev/null
+++ b/test/core/miquire/plugin/parent/spec
@@ -0,0 +1,9 @@
+---
+slug: :parent
+depends:
+ mikutter: 0.2.2.1150
+ plugin: []
+version: '1.0'
+author: toshi_a
+name: parent
+description: dependency test
diff --git a/test/core/miquire/plugin/parent_not_found/parent_not_found.rb b/test/core/miquire/plugin/parent_not_found/parent_not_found.rb
new file mode 100644
index 00000000..e26b8f98
--- /dev/null
+++ b/test/core/miquire/plugin/parent_not_found/parent_not_found.rb
@@ -0,0 +1,5 @@
+# -*- coding: utf-8 -*-
+
+Plugin.create(:child) do
+
+end
diff --git a/test/core/miquire/plugin/parent_not_found/spec b/test/core/miquire/plugin/parent_not_found/spec
new file mode 100644
index 00000000..6e4644fb
--- /dev/null
+++ b/test/core/miquire/plugin/parent_not_found/spec
@@ -0,0 +1,9 @@
+---
+slug: :parent_not_found
+depends:
+ mikutter: 0.2.2.1150
+ plugin: [not_exist]
+version: '1.0'
+author: toshi_a
+name: parent not exist plugin
+description: dependency test for parent not found
diff --git a/test/core/miquire/plugin/standalone/standalone.rb b/test/core/miquire/plugin/standalone/standalone.rb
new file mode 100644
index 00000000..1493ee78
--- /dev/null
+++ b/test/core/miquire/plugin/standalone/standalone.rb
@@ -0,0 +1,5 @@
+# -*- coding: utf-8 -*-
+
+Plugin.create(:standalone) do
+
+end
diff --git a/test/core/miquire/plugin/tooold/spec b/test/core/miquire/plugin/tooold/spec
new file mode 100644
index 00000000..3c98201c
--- /dev/null
+++ b/test/core/miquire/plugin/tooold/spec
@@ -0,0 +1,9 @@
+---
+slug: :tooold
+depends:
+ mikutter: 1.0
+ plugin: []
+version: '1.0'
+author: toshi_a
+name: tooold mikutter
+description: dependency test for too old mikutter
diff --git a/test/core/miquire/plugin/tooold/tooold.rb b/test/core/miquire/plugin/tooold/tooold.rb
new file mode 100644
index 00000000..136fb7fd
--- /dev/null
+++ b/test/core/miquire/plugin/tooold/tooold.rb
@@ -0,0 +1,5 @@
+# -*- coding: utf-8 -*-
+
+Plugin.create(:parent) do
+
+end
diff --git a/test/core/test_miquire.rb b/test/core/test_miquire.rb
index 01817df5..0f5e3243 100644
--- a/test/core/test_miquire.rb
+++ b/test/core/test_miquire.rb
@@ -41,22 +41,4 @@ class TC_Miquire < Test::Unit::TestCase
miquire :allfiles
end
- must "get plugin slug by path (spec exist)" do
- assert_equal(:rest, Miquire::Plugin.get_slug(File.expand_path(File.join(File.dirname(__FILE__), '../../core/plugin/rest/'))))
- end
-
- must "get plugin slug by path (spec not exist)" do
- Miquire::Plugin.stubs(:get_spec).returns(false)
- assert_equal(:rest, Miquire::Plugin.get_slug(File.expand_path(File.join(File.dirname(__FILE__), '../../core/plugin/rest/'))))
- assert_equal(:rest, Miquire::Plugin.get_slug(File.expand_path(File.join(File.dirname(__FILE__), '../../core/plugin/rest/rest.rb'))))
- end
-
- must "to_hash plugin slug and path" do
- p Miquire::Plugin.to_hash
- end
-
- must "load a plugin and depends" do
- #Miquire::Plugin.load(:home_timeline)
- end
-
end
diff --git a/test/core/test_miquire_plugin.rb b/test/core/test_miquire_plugin.rb
new file mode 100644
index 00000000..ca139db0
--- /dev/null
+++ b/test/core/test_miquire_plugin.rb
@@ -0,0 +1,101 @@
+# -*- coding: utf-8 -*-
+
+require 'test/unit'
+require 'rubygems'
+require 'mocha'
+require File.expand_path(File.dirname(__FILE__)+'/../helper')
+
+miquire :core, "miquire_plugin"
+
+Miquire::Plugin.loadpath << File.join(File.dirname(__FILE__), "miquire/plugin")
+
+class TC_MiquirePlugin < Test::Unit::TestCase
+ def setup
+ Plugin.clear!
+ end
+
+ must "to_hash return all spec" do
+ hash = Miquire::Plugin.to_hash
+ assert_equal :standalone, hash[:standalone][:slug]
+ end
+
+ must "get plugin slug by path (spec exist)" do
+ assert_equal(:standalone, Miquire::Plugin.get_slug(File.expand_path(File.join(File.dirname(__FILE__), 'miquire/standalone'))))
+ assert_equal(:parent_not_found, Miquire::Plugin.get_slug(File.expand_path(File.join(File.dirname(__FILE__), 'miquire/parent_not_found'))))
+ assert_equal(:tooold, Miquire::Plugin.get_slug(File.expand_path(File.join(File.dirname(__FILE__), 'miquire/tooold'))))
+ end
+
+ must "get plugin slug by plugin path" do
+ assert_equal(:standalone, Miquire::Plugin.get_slug(File.expand_path(File.join(File.dirname(__FILE__), 'miquire/standalone'))),
+ "spec がないとき slug が取得できる")
+ assert_equal(:not_exist, Miquire::Plugin.get_slug(File.expand_path(File.join(File.dirname(__FILE__), 'miquire/not_exist'))),
+ "plugin が存在しないとき slug が取得できる")
+ assert_equal(:display_requirements, Miquire::Plugin.get_slug(File.expand_path(File.join(File.dirname(__FILE__), 'miquire/display_requirements.rb'))),
+ "plugin が一つの.rbファイルだけの時 slug が取得できる")
+ end
+
+ must "get spec by plugin path" do
+ standalone = Miquire::Plugin.get_spec(File.expand_path(File.join(File.dirname(__FILE__), 'miquire/plugin/standalone')))
+ not_exist = Miquire::Plugin.get_spec(File.expand_path(File.join(File.dirname(__FILE__), 'miquire/plugin/not_exist')))
+ display_requirements = Miquire::Plugin.get_spec(File.expand_path(File.join(File.dirname(__FILE__), 'miquire/plugin/display_requirements.rb')))
+
+ assert_kind_of(Hash, standalone,
+ "spec file がないとき plugin があれば spec を取得できる")
+ assert_equal(:standalone, standalone[:slug],
+ "spec file がないとき plugin があれば spec を取得できる")
+ assert_nil(not_exist,
+ "plugin がないときは slug を取得できない")
+ assert_kind_of(Hash, display_requirements,
+ "plugin ファイルが単一の時、 spec を取得できる")
+ assert_equal(:display_requirements, display_requirements[:slug],
+ "plugin ファイルが単一の時、 spec を取得できる")
+ end
+
+ must "get spec by plugin slug" do
+ standalone = Miquire::Plugin.get_spec_by_slug(:standalone)
+ not_exist = Miquire::Plugin.get_spec_by_slug(:not_exist)
+ display_requirements = Miquire::Plugin.get_spec_by_slug(:display_requirements)
+
+ assert_kind_of(Hash, standalone,
+ "spec file がないとき plugin があれば spec を取得できる")
+ assert_equal(:standalone, standalone[:slug],
+ "spec file がないとき plugin があれば spec を取得できる")
+ assert_nil(not_exist,
+ "plugin がないときは slug を取得できない")
+ assert_kind_of(Hash, display_requirements,
+ "plugin ファイルが単一の時、 spec を取得できる")
+ assert_equal(:display_requirements, display_requirements[:slug],
+ "plugin ファイルが単一の時、 spec を取得できる")
+ end
+
+ must "load plugin by symbol" do
+ assert(Miquire::Plugin.load(:standalone),
+ "プラグインがロードできる")
+ assert(Plugin.instance_exist?(:standalone), "プラグインがロードできる")
+ assert_equal(false, Miquire::Plugin.load(:not_exist), "存在しないプラグインはロードできない")
+ end
+
+ must "load plugin by slug" do
+ assert(Miquire::Plugin.load(Miquire::Plugin.get_spec_by_slug(:standalone)),
+ "プラグインがロードできる")
+ assert(Plugin.instance_exist?(:standalone), "プラグインがロードできる")
+ assert_raise(ArgumentError, "存在しないプラグインはロードできない") {
+ Miquire::Plugin.load(Miquire::Plugin.get_spec_by_slug(:not_exist))
+ }
+ end
+
+ must "load child plugin with parent" do
+ assert(Miquire::Plugin.load(:child),
+ "依存関係のあるプラグインをロードできる")
+ assert(Plugin.instance_exist?(:child), "依存のあるプラグインをロードできる")
+ assert(Plugin.instance_exist?(:parent), "依存されているプラグインも自動でロードされる")
+ end
+
+ must "load error depended plugin not exists." do
+ assert_raise(Miquire::LoadError, "依存しているプラグインがない場合ロードに失敗する") {
+ Miquire::Plugin.load(:parent_not_found)
+ }
+ assert(!Plugin.instance_exist?(:parent_not_found), "依存しているプラグインがない場合ロードに失敗する")
+ end
+
+end
diff --git a/test/core/test_plugin.rb b/test/core/test_plugin.rb
index 76a13608..39082111 100644
--- a/test/core/test_plugin.rb
+++ b/test/core/test_plugin.rb
@@ -75,23 +75,6 @@ class TC_Plugin < Test::Unit::TestCase
assert_equal([:plugin_0, :plugin_1], Plugin.plugin_list)
end
- must "load exist plugin" do
- Plugin.stubs(:require).with("/path/to/plugin/loadtest/loadtest.rb").returns(true).once
- Plugin.load_file("/path/to/plugin/loadtest/loadtest.rb", slug: :loadtest)
- end
-
- must "load plugin dependencies" do
- Plugin.stubs(:require).with("a.rb").returns(true).once
- Plugin.stubs(:require).with("b.rb").returns(true).once
- Plugin.stubs(:require).with("c.rb").returns(true).once
- Plugin.load_file("a.rb", slug: :a, depends: {plugin: [:b, :c]})
- assert_equal([], Plugin.plugin_list)
- Plugin.load_file("b.rb", slug: :b)
- assert_equal([:b], Plugin.plugin_list)
- Plugin.load_file("c.rb", slug: :c)
- assert_equal([:b, :c, :a], Plugin.plugin_list)
- end
-
must "dsl method defevent" do
Plugin.create :defevent do
defevent :increase, prototype: [Integer] end