RubyExt 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +846 -0
- data/lib/RubyExt/Cache.rb +101 -0
- data/lib/RubyExt/Cache.res/multiple_version_with_args.txt +12 -0
- data/lib/RubyExt/Cache.res/multiple_version_without_args.txt +11 -0
- data/lib/RubyExt/Cache.res/single_version_with_args.txt +11 -0
- data/lib/RubyExt/Cache.res/single_version_without_args.txt +10 -0
- data/lib/RubyExt/ClassLoader.rb +142 -0
- data/lib/RubyExt/Debug.rb +24 -0
- data/lib/RubyExt/ExtraBlankSlate.rb +14 -0
- data/lib/RubyExt/ImportAll.rb +9 -0
- data/lib/RubyExt/Localization/Module.rb +12 -0
- data/lib/RubyExt/Localization/Object.rb +19 -0
- data/lib/RubyExt/Localization/require.rb +3 -0
- data/lib/RubyExt/Localization.rb +28 -0
- data/lib/RubyExt/Log.config.sample +57 -0
- data/lib/RubyExt/Log.rb +59 -0
- data/lib/RubyExt/OpenConstructor.rb +51 -0
- data/lib/RubyExt/Path.rb +91 -0
- data/lib/RubyExt/Resource/file_system_provider.rb +244 -0
- data/lib/RubyExt/StateMashine.rb +176 -0
- data/lib/RubyExt/Synchronizer.rb +29 -0
- data/lib/RubyExt/array.rb +24 -0
- data/lib/RubyExt/assert.rb +111 -0
- data/lib/RubyExt/class.rb +0 -0
- data/lib/RubyExt/debug.rb +71 -0
- data/lib/RubyExt/false_class.rb +5 -0
- data/lib/RubyExt/file.rb +23 -0
- data/lib/RubyExt/ideas.txt +17 -0
- data/lib/RubyExt/kernel.rb +61 -0
- data/lib/RubyExt/module.rb +102 -0
- data/lib/RubyExt/nil_class.rb +5 -0
- data/lib/RubyExt/object.rb +7 -0
- data/lib/RubyExt/observable.rb +25 -0
- data/lib/RubyExt/require.rb +56 -0
- data/lib/RubyExt/require_base.rb +35 -0
- data/lib/RubyExt/resource.rb +198 -0
- data/lib/RubyExt/string.rb +21 -0
- data/lib/RubyExt/symbol.rb +21 -0
- data/lib/RubyExt/true_class +0 -0
- data/lib/RubyExt/true_class.rb +5 -0
- data/rakefile +49 -0
- data/spec/RubyExt/ForClassLoader/ClassA.rb +4 -0
- data/spec/RubyExt/ForClassLoader/LoadCount.rb +1 -0
- data/spec/RubyExt/ForClassLoader/ModuleA/ClassB.rb +3 -0
- data/spec/RubyExt/ForClassLoader/ModuleA/ClassInsideAnonymousClass.rb +3 -0
- data/spec/RubyExt/ForClassLoader/ModuleA/InfinityLoop.rb +3 -0
- data/spec/RubyExt/ForClassLoader/ModuleA/ModuleB/ClassC.rb +3 -0
- data/spec/RubyExt/ForClassLoader/ModuleA/SameName/SomeClass.rb +2 -0
- data/spec/RubyExt/ForClassLoader/ModuleA/SameName.rb +2 -0
- data/spec/RubyExt/ForClassLoader/Scope/ScopeA1.rb +3 -0
- data/spec/RubyExt/ForClassLoader/Scope/ScopeB1.rb +5 -0
- data/spec/RubyExt/ForKernel/Raise2.rb +5 -0
- data/spec/RubyExt/ForKernel/RaiseWithoutSelf.rb +9 -0
- data/spec/RubyExt/ForLocalization/NS/A.rb +3 -0
- data/spec/RubyExt/ForLocalization/NS/A.ru.localization.yaml +2 -0
- data/spec/RubyExt/ForLocalization/NS/B.rb +22 -0
- data/spec/RubyExt/ForLocalization/NS/B.ru.localization.yaml +3 -0
- data/spec/RubyExt/ForLocalization/NS.ru.localization.yaml +2 -0
- data/spec/RubyExt/ForModule/NS1/A.data +1 -0
- data/spec/RubyExt/ForModule/NS1/A.rb +1 -0
- data/spec/RubyExt/ForModule/NS1/A2.rb +1 -0
- data/spec/RubyExt/ForModule/NS1/B.rb +2 -0
- data/spec/RubyExt/ForModule/NS1/B2.rb +1 -0
- data/spec/RubyExt/ForModule/NS1.data +1 -0
- data/spec/RubyExt/ForModule/NS2/A.data +1 -0
- data/spec/RubyExt/ForModule/NS2/A.rb +3 -0
- data/spec/RubyExt/ForModule/NS2/B.rb +3 -0
- data/spec/RubyExt/ForModule/NS2/M.data +1 -0
- data/spec/RubyExt/ForModule/NS2/M.rb +3 -0
- data/spec/RubyExt/ForResource/ChangedClass.rb +1 -0
- data/spec/RubyExt/ForResource/ChangedClass.res/Text.txt +0 -0
- data/spec/RubyExt/ForResource/ChangedClass.txt +0 -0
- data/spec/RubyExt/ForResource/ProviderChaining/ProviderABaseDir/ChainTest.rb +3 -0
- data/spec/RubyExt/ForResource/ProviderChaining/ProviderABaseDir/ChainTest.resource +1 -0
- data/spec/RubyExt/ForResource/ProviderChaining/ProviderABaseDir/ClassExistOnlyInProviderA.rb +3 -0
- data/spec/RubyExt/ForResource/ProviderChaining/ProviderBBaseDir/ChainTest.rb +3 -0
- data/spec/RubyExt/ForResource/ProviderChaining/ProviderBBaseDir/ChainTest.resource +1 -0
- data/spec/RubyExt/ForResource/ResourceExtension.rb +1 -0
- data/spec/RubyExt/ForResource/ResourceExtension.res/Data.yaml +2 -0
- data/spec/RubyExt/ForResource/ResourceTest/Test.rb +1 -0
- data/spec/RubyExt/ForResource/ResourceTest/Test.res/Data.txt +1 -0
- data/spec/RubyExt/ForResource/ResourceTest/Test.res/txt +1 -0
- data/spec/array_spec.rb +27 -0
- data/spec/assert_spec.rb +18 -0
- data/spec/cache_spec.rb +95 -0
- data/spec/class_loader_spec.rb +94 -0
- data/spec/import_all_spec.rb +21 -0
- data/spec/kernel_spec.rb +38 -0
- data/spec/localization_spec.rb +49 -0
- data/spec/module_spec.rb +135 -0
- data/spec/object_spec.rb +8 -0
- data/spec/observable_spec.rb +44 -0
- data/spec/open_constructor_spec.rb +38 -0
- data/spec/path_spec.rb +169 -0
- data/spec/resource_spec.rb +135 -0
- data/spec/state_machine_spec.rb +201 -0
- data/spec/synchronizer_spec.rb +66 -0
- metadata +130 -10
- data/lib/RubyExt.rb +0 -1
- data/lib/hello_gem.rb +0 -5
@@ -0,0 +1,22 @@
|
|
1
|
+
class B < A
|
2
|
+
def message
|
3
|
+
to_l("English")
|
4
|
+
end
|
5
|
+
|
6
|
+
def class_hierarchy_message
|
7
|
+
to_l("Class Hierarchy English")
|
8
|
+
end
|
9
|
+
|
10
|
+
def namespace_hierarchy_message
|
11
|
+
to_l("Namespace Hierarchy English")
|
12
|
+
end
|
13
|
+
|
14
|
+
def substitution
|
15
|
+
value = 10
|
16
|
+
to_l("English \#{value}", binding)
|
17
|
+
end
|
18
|
+
|
19
|
+
def not_localized
|
20
|
+
to_l("English Not Localized")
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
A.data
|
@@ -0,0 +1 @@
|
|
1
|
+
class A; end
|
@@ -0,0 +1 @@
|
|
1
|
+
class A2; end
|
@@ -0,0 +1 @@
|
|
1
|
+
class B2 < ForModule::NS1::A2; end
|
@@ -0,0 +1 @@
|
|
1
|
+
NS1.data
|
@@ -0,0 +1 @@
|
|
1
|
+
A.data
|
@@ -0,0 +1 @@
|
|
1
|
+
M.data
|
@@ -0,0 +1 @@
|
|
1
|
+
class ChangedClass; end
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
ProviderA
|
@@ -0,0 +1 @@
|
|
1
|
+
ProviderB
|
@@ -0,0 +1 @@
|
|
1
|
+
class ResourceExtension; end
|
@@ -0,0 +1 @@
|
|
1
|
+
class Test; end
|
@@ -0,0 +1 @@
|
|
1
|
+
Data.txt
|
@@ -0,0 +1 @@
|
|
1
|
+
Test.txt
|
data/spec/array_spec.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'RubyExt/require'
|
2
|
+
require 'spec'
|
3
|
+
|
4
|
+
module RubyExt
|
5
|
+
describe 'Array' do
|
6
|
+
class Respond
|
7
|
+
def test; 2 end
|
8
|
+
end
|
9
|
+
|
10
|
+
it "sort_by_weight" do
|
11
|
+
a = [:a, :b, :c]
|
12
|
+
w = [3, 2, 1]
|
13
|
+
a.sort_by_weight(w).should == [:c, :b, :a]
|
14
|
+
a.should == [:a, :b, :c]
|
15
|
+
a.sort_by_weight! w
|
16
|
+
a.should == [:c, :b, :a]
|
17
|
+
end
|
18
|
+
|
19
|
+
it "sort_by_weight (from error)" do
|
20
|
+
a = ["Attributes", "Micelaneous", "Containers", "Tools"]
|
21
|
+
w = [0, 0, -1, -2]
|
22
|
+
a.sort_by_weight! w
|
23
|
+
a.should == ["Tools", "Containers", "Attributes", "Micelaneous"]
|
24
|
+
w.should == [-2, -1, 0, 0]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/spec/assert_spec.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'RubyExt/require'
|
2
|
+
require 'spec'
|
3
|
+
|
4
|
+
module RubyExt
|
5
|
+
describe 'Assert' do
|
6
|
+
it do
|
7
|
+
lambda{should! :be_never_called}.should raise_error(/ever/)
|
8
|
+
lambda{nil.should_not! :be_nil}.should raise_error(/nil/)
|
9
|
+
1.should_not! :be_nil
|
10
|
+
1.should! :==, 1
|
11
|
+
lambda{1.should! :==, 2}.should raise_error(/==/)
|
12
|
+
1.should! :be_in, [1, 2]
|
13
|
+
"".should! :be_a, String
|
14
|
+
String.should! :be, String
|
15
|
+
1.should! :<, 2
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/spec/cache_spec.rb
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'RubyExt/require'
|
2
|
+
require 'spec'
|
3
|
+
|
4
|
+
module RubyExt
|
5
|
+
describe 'Cache' do
|
6
|
+
class CachedClass
|
7
|
+
attr_accessor :value
|
8
|
+
def value_get; @value end
|
9
|
+
|
10
|
+
attr_accessor :value2
|
11
|
+
def value2_get; @value2 end
|
12
|
+
|
13
|
+
attr_accessor :params
|
14
|
+
def params_get param; @params[param] end
|
15
|
+
end
|
16
|
+
|
17
|
+
Cache.cached CachedClass, CachedClass, :value_get
|
18
|
+
Cache.cached :cache_version_name, CachedClass, :value2_get
|
19
|
+
Cache.cached_with_params CachedClass, CachedClass, :params_get
|
20
|
+
|
21
|
+
it "Simple Cache" do
|
22
|
+
o = CachedClass.new
|
23
|
+
o.value = 0
|
24
|
+
o.value2 = 0
|
25
|
+
o.value_get.should == 0
|
26
|
+
o.value2_get.should == 0
|
27
|
+
o.value = 1
|
28
|
+
o.value2 = 1
|
29
|
+
o.value_get.should == 0
|
30
|
+
o.value2_get.should == 0
|
31
|
+
Cache.update CachedClass
|
32
|
+
o.value_get.should == 1
|
33
|
+
o.value2_get.should == 0
|
34
|
+
Cache.update :cache_version_name
|
35
|
+
o.value2_get.should == 1
|
36
|
+
Cache.update CachedClass, :cache_version_name
|
37
|
+
end
|
38
|
+
|
39
|
+
it "Cache With Params" do
|
40
|
+
o = CachedClass.new
|
41
|
+
o.params = {:a => :b}
|
42
|
+
o.params_get(:a).should == :b
|
43
|
+
o.params = {:a => :c}
|
44
|
+
o.params_get(:a).should == :b
|
45
|
+
Cache.update CachedClass
|
46
|
+
o.params_get(:a).should == :c
|
47
|
+
end
|
48
|
+
|
49
|
+
class CachedClass2
|
50
|
+
class << self
|
51
|
+
attr_accessor :value
|
52
|
+
def value_get; @value end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
Cache.cached CachedClass2, CachedClass2.singleton_class, :value_get
|
57
|
+
|
58
|
+
it "Simple Cache" do
|
59
|
+
CachedClass2.value = 0
|
60
|
+
CachedClass2.value_get.should == 0
|
61
|
+
CachedClass2.value = 1
|
62
|
+
CachedClass2.value_get.should == 0
|
63
|
+
Cache.update CachedClass2
|
64
|
+
CachedClass2.value_get.should == 1
|
65
|
+
end
|
66
|
+
|
67
|
+
class MultipleCacheVersions
|
68
|
+
attr_accessor :value
|
69
|
+
def value_get; @value end
|
70
|
+
|
71
|
+
attr_accessor :value2
|
72
|
+
def value2_get params; @value2 end
|
73
|
+
end
|
74
|
+
|
75
|
+
Cache.cached [:class, :resource_update, :security_update], MultipleCacheVersions, :value_get
|
76
|
+
Cache.cached_with_params [:class, :resource_update, :security_update], MultipleCacheVersions, :value2_get
|
77
|
+
|
78
|
+
it "Multiple cache versions" do
|
79
|
+
o = MultipleCacheVersions.new
|
80
|
+
o.value, o.value2 = 0, 0
|
81
|
+
|
82
|
+
o.value_get.should == 0
|
83
|
+
o.value = 1
|
84
|
+
o.value_get.should == 0
|
85
|
+
Cache.update :class
|
86
|
+
o.value_get.should == 1
|
87
|
+
o.value = 2
|
88
|
+
o.value_get.should == 1
|
89
|
+
Cache.update :resource_update, :security_update
|
90
|
+
o.value_get.should == 2
|
91
|
+
|
92
|
+
o.value2_get("params").should == 0
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'RubyExt/require_base'
|
2
|
+
require 'spec'
|
3
|
+
|
4
|
+
module RubyExt
|
5
|
+
describe "PackageManager" do
|
6
|
+
it "Should load classes only one time" do
|
7
|
+
class CustomObserver
|
8
|
+
attr_reader :list
|
9
|
+
def initialize
|
10
|
+
@list = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def update_class klass
|
14
|
+
@list << klass
|
15
|
+
end
|
16
|
+
end
|
17
|
+
obs = CustomObserver.new
|
18
|
+
RubyExt::ClassLoader.add_observer obs
|
19
|
+
ForClassLoader::LoadCount
|
20
|
+
ForClassLoader::LoadCount
|
21
|
+
RubyExt::ClassLoader.delete_observers
|
22
|
+
obs.list.inject(0){|count, klass| klass == ForClassLoader::LoadCount ? count + 1 : count}.
|
23
|
+
should == 1
|
24
|
+
end
|
25
|
+
|
26
|
+
it "Should load classes From Multiple directories" do
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
it "Class has the same name as package" do
|
31
|
+
ForClassLoader::ModuleA::SameName
|
32
|
+
RubyExt::ForClassLoader::ModuleA::SameName::SomeClass
|
33
|
+
end
|
34
|
+
|
35
|
+
it "Infinity Loop" do
|
36
|
+
lambda{ForClassLoader::ModuleA::InfinityLoop}.
|
37
|
+
should raise_error(/Class Name .+ doesn't correspond to File Name/)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "Core" do
|
41
|
+
ForClassLoader::ModuleA::ModuleB::ClassC.new
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
module ForClassLoader::ModuleA
|
46
|
+
class << self
|
47
|
+
def anonymous
|
48
|
+
ClassInsideAnonymousClass
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "Should works inside Anonymous Class" do
|
54
|
+
ForClassLoader::ModuleA.anonymous
|
55
|
+
end
|
56
|
+
|
57
|
+
it "Should raise exception if class isn't defined in scope" do
|
58
|
+
ForClassLoader::Scope::ScopeA1
|
59
|
+
RubyExt::ClassLoader.error_on_defined_constant = true
|
60
|
+
lambda{ForClassLoader::Scope::ScopeB1}.
|
61
|
+
should raise_error(/Class '.+' is not defined in the '.+' Namespace!/)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "Class Reloading" do
|
65
|
+
fname = File.join(File.dirname(__FILE__), 'RubyExt/ForClassLoader/ModuleA/ClassReloading.rb')
|
66
|
+
File.delete fname if File.exist? fname
|
67
|
+
File.open(fname, 'w') do |f|
|
68
|
+
f.write %{\
|
69
|
+
class ClassReloading
|
70
|
+
def test
|
71
|
+
1
|
72
|
+
end
|
73
|
+
end}
|
74
|
+
end
|
75
|
+
|
76
|
+
test = ForClassLoader::ModuleA::ClassReloading.new
|
77
|
+
test.test.should == 1
|
78
|
+
|
79
|
+
File.open(fname, 'w') do |f|
|
80
|
+
f.write %{\
|
81
|
+
class ClassReloading
|
82
|
+
def test
|
83
|
+
2
|
84
|
+
end
|
85
|
+
end}
|
86
|
+
end
|
87
|
+
|
88
|
+
RubyExt::ClassLoader.reload_class(ForClassLoader::ModuleA::ClassReloading.name)
|
89
|
+
test.test.should == 2
|
90
|
+
|
91
|
+
File.delete fname if File.exist? fname
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'RubyExt/require_base'
|
2
|
+
require 'spec'
|
3
|
+
|
4
|
+
module RubyExt
|
5
|
+
describe "ImportAll" do
|
6
|
+
class A
|
7
|
+
class B; end
|
8
|
+
class C; end
|
9
|
+
class D; end
|
10
|
+
end
|
11
|
+
|
12
|
+
class E
|
13
|
+
extend RubyExt::ImportAll
|
14
|
+
import_all A
|
15
|
+
end
|
16
|
+
|
17
|
+
it do
|
18
|
+
E::B
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/kernel_spec.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'RubyExt/require'
|
2
|
+
require 'spec'
|
3
|
+
|
4
|
+
module RubyExt
|
5
|
+
describe 'Kernel' do
|
6
|
+
class Respond
|
7
|
+
def test; 2 end
|
8
|
+
end
|
9
|
+
|
10
|
+
it "respond_to" do
|
11
|
+
r = Respond.new
|
12
|
+
r.respond_to(:not_exist).should be_nil
|
13
|
+
r.respond_to(:test).should == 2
|
14
|
+
end
|
15
|
+
|
16
|
+
it "raise_without_self" do
|
17
|
+
begin
|
18
|
+
ForKernel::RaiseWithoutSelf.new.test
|
19
|
+
rescue RuntimeError => e
|
20
|
+
stack = e.backtrace
|
21
|
+
stack.any?{|line| line =~ /RaiseWithoutSelf/}.should be_false
|
22
|
+
stack.any?{|line| line =~ /kernel_spec/}.should be_true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "raise_without_self" do
|
27
|
+
begin
|
28
|
+
t1 = ForKernel::RaiseWithoutSelf.new
|
29
|
+
ForKernel::Raise2.new.test t1
|
30
|
+
rescue RuntimeError => e
|
31
|
+
stack = e.backtrace
|
32
|
+
stack.any?{|line| line =~ /RaiseWithoutSelf/}.should be_false
|
33
|
+
stack.any?{|line| line =~ /Raise2/}.should be_false
|
34
|
+
stack.any?{|line| line =~ /kernel_spec/}.should be_true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec'
|
2
|
+
require 'RubyExt/Localization/require'
|
3
|
+
|
4
|
+
module RubyExt
|
5
|
+
describe "RubyExt::Localization" do
|
6
|
+
before :each do
|
7
|
+
RubyExt::Localization.default_language = :en
|
8
|
+
RubyExt::Localization.language = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
it "Default Language" do
|
12
|
+
ForLocalization::NS::B.new.message.should == "English"
|
13
|
+
RubyExt::Localization.default_language = :ru
|
14
|
+
ForLocalization::NS::B.new.message.should == "Russian"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "Not Localized" do
|
18
|
+
RubyExt::Localization.default_language = :ru
|
19
|
+
ForLocalization::NS::B.new.not_localized.should == "English Not Localized"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "Language set" do
|
23
|
+
ForLocalization::NS::B.new.message.should == "English"
|
24
|
+
RubyExt::Localization.language = lambda{:ru}
|
25
|
+
ForLocalization::NS::B.new.message.should == "Russian"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "Language not set" do
|
29
|
+
RubyExt::Localization.language = lambda{nil}
|
30
|
+
ForLocalization::NS::B.new.message.should == "English"
|
31
|
+
end
|
32
|
+
|
33
|
+
it "Class Hierarchy" do
|
34
|
+
RubyExt::Localization.language = lambda{:ru}
|
35
|
+
ForLocalization::NS::B.new.class_hierarchy_message.should == "Class Hierarchy Russian"
|
36
|
+
end
|
37
|
+
|
38
|
+
it "Namespace Hierarchy" do
|
39
|
+
RubyExt::Localization.language = lambda{:ru}
|
40
|
+
ForLocalization::NS::B.new.namespace_hierarchy_message.should ==
|
41
|
+
"Namespace Hierarchy Russian"
|
42
|
+
end
|
43
|
+
|
44
|
+
it "Substitution" do
|
45
|
+
RubyExt::Localization.language = lambda{:ru}
|
46
|
+
ForLocalization::NS::B.new.substitution.should == "Russian 10"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/spec/module_spec.rb
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'RubyExt/require_base'
|
2
|
+
require 'spec'
|
3
|
+
|
4
|
+
module RubyExt
|
5
|
+
describe "Module" do
|
6
|
+
class A
|
7
|
+
class B
|
8
|
+
class C
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "Namespace" do
|
15
|
+
File.namespace.should == nil
|
16
|
+
A::B::C.namespace.should == RubyExt::A::B
|
17
|
+
end
|
18
|
+
|
19
|
+
class AnonymousClass
|
20
|
+
class << self
|
21
|
+
def anonymous_name
|
22
|
+
self.name
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
it "name" do
|
29
|
+
A::B::C.name.should == "RubyExt::A::B::C"
|
30
|
+
end
|
31
|
+
|
32
|
+
class X; end
|
33
|
+
class Y < X; end
|
34
|
+
class Z < Y; end
|
35
|
+
|
36
|
+
|
37
|
+
it "each_ancestor" do
|
38
|
+
list = []
|
39
|
+
Z.each_ancestor{|a| list << a}
|
40
|
+
list.should include Y
|
41
|
+
list.should include X
|
42
|
+
list.should_not include Z
|
43
|
+
list.should_not include Object
|
44
|
+
list.should_not include Kernel
|
45
|
+
|
46
|
+
list = []
|
47
|
+
Z.each_ancestor(true){|a| list << a}
|
48
|
+
list.should include Y
|
49
|
+
list.should include X
|
50
|
+
list.should_not include Z
|
51
|
+
list.should include Object
|
52
|
+
list.should include Kernel
|
53
|
+
end
|
54
|
+
|
55
|
+
it "each_namespace" do
|
56
|
+
list = []
|
57
|
+
A::B::C.each_namespace{|n| list << n}
|
58
|
+
list.should == [RubyExt::A::B, RubyExt::A, RubyExt]
|
59
|
+
end
|
60
|
+
|
61
|
+
it "is?" do
|
62
|
+
File.is?(IO).should be_true
|
63
|
+
end
|
64
|
+
|
65
|
+
class WrapMethod
|
66
|
+
def method_name value
|
67
|
+
10*value
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it "wrap_method" do
|
72
|
+
WrapMethod.wrap_method :method_name do |old, value|
|
73
|
+
send(old, value)*value
|
74
|
+
end
|
75
|
+
WrapMethod.new.method_name(10).should == 1000
|
76
|
+
end
|
77
|
+
|
78
|
+
it "resources" do
|
79
|
+
ForModule::NS1::B["data"].should == "A.data"
|
80
|
+
ForModule::NS1::B2["data"].should == "NS1.data"
|
81
|
+
end
|
82
|
+
|
83
|
+
it "resources, should aslo inherit resources from included modules" do
|
84
|
+
ForModule::NS2::B["data"].should == "M.data"
|
85
|
+
end
|
86
|
+
|
87
|
+
module M
|
88
|
+
def m_m; end
|
89
|
+
module ClassMethods
|
90
|
+
def cm_m; end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
class C
|
95
|
+
inherit M
|
96
|
+
end
|
97
|
+
|
98
|
+
it "inherit" do
|
99
|
+
C.respond_to?(:cm_m).should be_true
|
100
|
+
C.new.respond_to?(:m_m).should be_true
|
101
|
+
end
|
102
|
+
|
103
|
+
module M2
|
104
|
+
include M
|
105
|
+
|
106
|
+
module ClassMethods
|
107
|
+
def cm2_m; end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
class D
|
112
|
+
inherit M2
|
113
|
+
end
|
114
|
+
|
115
|
+
it "should inherit all ancestors class methods" do
|
116
|
+
D.respond_to?(:cm_m).should be_true
|
117
|
+
D.respond_to?(:cm2_m).should be_true
|
118
|
+
D.new.respond_to?(:m_m).should be_true
|
119
|
+
end
|
120
|
+
|
121
|
+
class C2
|
122
|
+
inherit M
|
123
|
+
end
|
124
|
+
|
125
|
+
it "Shouldn't redefine ancestors class methods" do
|
126
|
+
C2.respond_to?(:cm2_m).should be_false
|
127
|
+
end
|
128
|
+
|
129
|
+
it "inherited_instance_methods" do
|
130
|
+
im = Set.instance_methods - Set.inherited_instance_methods
|
131
|
+
im.should include("union")
|
132
|
+
im.should_not include("object_id")
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
data/spec/object_spec.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'RubyExt/require_base'
|
2
|
+
require 'spec'
|
3
|
+
|
4
|
+
module RubyExt
|
5
|
+
describe "Observable" do
|
6
|
+
class AnObservable
|
7
|
+
include Observable
|
8
|
+
end
|
9
|
+
|
10
|
+
it "Method without Parameters" do
|
11
|
+
mock = mock("Observer")
|
12
|
+
obs = AnObservable.new
|
13
|
+
obs.add_observer mock
|
14
|
+
mock.should_receive(:update).with(2)
|
15
|
+
obs.notify_observers :update, 2
|
16
|
+
end
|
17
|
+
|
18
|
+
# it "Method without Parameters" do
|
19
|
+
# mock = mock("Observer")
|
20
|
+
# obs = AnObservable.new
|
21
|
+
# obs.add_observer(mock, :method => :custom_update, :filter => lambda{|o| o == 2})
|
22
|
+
# mock.should_receive(:custom_update).with(2)
|
23
|
+
# obs.notify_observers 2
|
24
|
+
# obs.notify_observers 4
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# it "With Block" do
|
28
|
+
# mock = mock("Observer")
|
29
|
+
# mock.should_receive(:got)
|
30
|
+
# obs = AnObservable.new
|
31
|
+
# obs.add_observer{mock.got}
|
32
|
+
# obs.notify_observers
|
33
|
+
# end
|
34
|
+
#
|
35
|
+
# it "With Block and Filter" do
|
36
|
+
# mock = mock("Observer")
|
37
|
+
# obs = AnObservable.new
|
38
|
+
# obs.add_observer(:filter => lambda{|o| o == 2}){|o| mock.got o}
|
39
|
+
# mock.should_receive(:got).with(2)
|
40
|
+
# obs.notify_observers 2
|
41
|
+
# obs.notify_observers 4
|
42
|
+
# end
|
43
|
+
end
|
44
|
+
end
|