1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
require 'test/unit'
require 'coderay'
require 'pathname'
class PluginScannerTest < Test::Unit::TestCase
module Plugins
extend CodeRay::PluginHost
plugin_path File.dirname(__FILE__), 'plugins'
class Plugin
extend CodeRay::Plugin
plugin_host Plugins
end
end
module PluginsWithDefault
extend CodeRay::PluginHost
plugin_path File.dirname(__FILE__), 'plugins_with_default'
class Plugin
extend CodeRay::Plugin
plugin_host PluginsWithDefault
end
default :default
end
def test_load
require Pathname.new(__FILE__).realpath.dirname + 'plugins' + 'user_defined' + 'user_plugin'
assert_equal 'UserPlugin', Plugins.load(:user_plugin).name
end
def test_load_all
assert_instance_of Symbol, Plugins.load_all.first
assert_operator Plugins.all_plugins.first, :<, Plugins::Plugin
assert_equal 'The Example', Plugins.all_titles.sort.first
end
def test_default
assert_nothing_raised do
assert_operator PluginsWithDefault[:gargamel], :<, PluginsWithDefault::Plugin
end
assert_equal PluginsWithDefault::Default, PluginsWithDefault.default
end
def test_plugin_not_found
assert_raise CodeRay::PluginHost::PluginNotFound do
Plugins[:thestral]
end
assert_raise ArgumentError do
Plugins[14]
end
assert_raise ArgumentError do
Plugins['test/test']
end
assert_raise CodeRay::PluginHost::PluginNotFound do
PluginsWithDefault[:example_without_register_for]
end
end
def test_autoload_constants
assert_operator Plugins::Example, :<, Plugins::Plugin
end
def test_title
assert_equal 'The Example', Plugins::Example.title
end
def assert_warning expected_warning
require 'stringio'
oldstderr = $stderr
$stderr = StringIO.new
yield
$stderr.rewind
given_warning = $stderr.read.chomp
assert_equal expected_warning, given_warning
ensure
$stderr = oldstderr
end
end
|