ruby_ext 0.4.25 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +2 -0
- data/lib/rake_ext/project.rb +19 -19
- data/lib/rake_ext.rb +18 -18
- data/lib/rspec_ext/xhtml.rb +6 -6
- data/lib/rspec_ext.rb +40 -25
- data/lib/ruby_ext/core/array.rb +7 -7
- data/lib/ruby_ext/core/basic_object.rb +1 -1
- data/lib/ruby_ext/core/deep_clone.rb +2 -2
- data/lib/ruby_ext/core/enumerable.rb +1 -1
- data/lib/ruby_ext/core/hash.rb +4 -4
- data/lib/ruby_ext/core/module.rb +20 -30
- data/lib/ruby_ext/core/multiple_inheritance.rb +24 -24
- data/lib/ruby_ext/core/must.rb +39 -39
- data/lib/ruby_ext/core/object.rb +15 -3
- data/lib/ruby_ext/core/open_object.rb +22 -20
- data/lib/ruby_ext/core/string.rb +19 -19
- data/lib/ruby_ext/core/symbol.rb +1 -13
- data/lib/ruby_ext/core.rb +4 -8
- data/lib/ruby_ext/more/callbacks.rb +172 -0
- data/lib/ruby_ext/more/declarative_cache.rb +20 -22
- data/lib/ruby_ext/more/miscellaneous.rb +1 -46
- data/lib/ruby_ext/more/{observable2.rb → observable.rb} +8 -8
- data/lib/ruby_ext/more/open_constructor.rb +10 -10
- data/lib/ruby_ext/more/tuple.rb +1 -1
- data/lib/ruby_ext/more.rb +5 -3
- data/lib/ruby_ext.rb +0 -3
- data/lib/yaml_fix.rb +2 -2
- data/readme.md +51 -50
- data/spec/core/deep_clone_spec.rb +8 -8
- data/spec/core/module_spec.rb +29 -36
- data/spec/core/multiple_inheritance_spec.rb +32 -32
- data/spec/core/must_spec.rb +6 -6
- data/spec/core/object_spec.rb +15 -0
- data/spec/core/open_object_spec.rb +6 -6
- data/spec/more/callbacks_spec.rb +155 -0
- data/spec/more/declarative_cache_spec.rb +33 -33
- data/spec/more/{observable2_spec.rb → observable_spec.rb} +7 -7
- data/spec/more/open_constructor_spec.rb +5 -5
- metadata +7 -15
- data/lib/ruby_ext/core/class.rb +0 -0
- data/lib/ruby_ext/core/file.rb +0 -23
- data/lib/ruby_ext/core/kernel.rb +0 -69
- data/lib/ruby_ext/core/miscellaneous.rb +0 -14
- data/lib/ruby_ext/more/synchronize.rb +0 -26
- data/spec/core/kernel_spec/TheNamespace/ClassA.rb +0 -7
- data/spec/core/kernel_spec/another_class.rb +0 -5
- data/spec/core/kernel_spec/the_namespace/class_b.rb +0 -11
- data/spec/core/kernel_spec.rb +0 -51
- data/spec/more/miscellaneous_spec.rb +0 -14
- data/spec/more/synchronize_spec.rb +0 -79
@@ -5,47 +5,47 @@ describe 'DeclarativeCache' do
|
|
5
5
|
attr_accessor :value
|
6
6
|
def value_get; @value end
|
7
7
|
cache_method :value_get
|
8
|
-
|
8
|
+
|
9
9
|
attr_accessor :value2
|
10
|
-
def value2_get; @value2 end
|
11
|
-
|
10
|
+
def value2_get; @value2 end
|
11
|
+
|
12
12
|
attr_accessor :params
|
13
|
-
def params_get param; @params[param] end
|
14
|
-
|
13
|
+
def params_get param; @params[param] end
|
14
|
+
|
15
15
|
attr_accessor :multiplier
|
16
16
|
def *(arg)
|
17
17
|
@multiplier * arg
|
18
18
|
end
|
19
19
|
cache_method_with_params '*'
|
20
|
-
end
|
21
|
-
|
20
|
+
end
|
21
|
+
|
22
22
|
DeclarativeCache.cache_method CachedClass, :value2_get
|
23
|
-
DeclarativeCache.cache_method_with_params CachedClass, :params_get
|
24
|
-
|
23
|
+
DeclarativeCache.cache_method_with_params CachedClass, :params_get
|
24
|
+
|
25
25
|
it "Simple Cache" do
|
26
26
|
o = CachedClass.new
|
27
27
|
o.value = 0
|
28
|
-
o.value2 = 0
|
28
|
+
o.value2 = 0
|
29
29
|
o.value_get.should == 0
|
30
30
|
o.value2_get.should == 0
|
31
|
-
|
31
|
+
|
32
32
|
o.value = 1
|
33
33
|
o.value2 = 1
|
34
34
|
o.value_get.should == 0
|
35
35
|
o.value2_get.should == 0
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
it "should define <method>_with_cache and <method>_without_cache methods" do
|
39
39
|
o = CachedClass.new
|
40
|
-
|
40
|
+
|
41
41
|
# without params
|
42
42
|
o.value = 0
|
43
|
-
o.value_get.should == 0
|
43
|
+
o.value_get.should == 0
|
44
44
|
o.value = 1
|
45
45
|
o.value_get.should == 0
|
46
46
|
o.value_get_with_cache.should == 0
|
47
47
|
o.value_get_without_cache.should == 1
|
48
|
-
|
48
|
+
|
49
49
|
# with params
|
50
50
|
o.params = {a: :b}
|
51
51
|
o.params_get(:a).should == :b
|
@@ -54,7 +54,7 @@ describe 'DeclarativeCache' do
|
|
54
54
|
o.params_get_with_cache(:a).should == :b
|
55
55
|
o.params_get_without_cache(:a).should == :c
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
it "clear_cache" do
|
59
59
|
o = CachedClass.new
|
60
60
|
o.value = 0
|
@@ -63,15 +63,15 @@ describe 'DeclarativeCache' do
|
|
63
63
|
o.value = 1
|
64
64
|
o.value_get.should == 0
|
65
65
|
|
66
|
-
|
66
|
+
Module.clear_cache o
|
67
67
|
o.value_get.should == 1
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
it "should check for parameters" do
|
71
71
|
o = CachedClass.new
|
72
72
|
lambda{o.value_get(1)}.should raise_error(/cache_method_with_params/)
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
it "Cache With Params" do
|
76
76
|
o = CachedClass.new
|
77
77
|
o.params = {a: :b}
|
@@ -79,7 +79,7 @@ describe 'DeclarativeCache' do
|
|
79
79
|
o.params = {a: :c}
|
80
80
|
o.params_get(:a).should == :b
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
it "should works with operators" do
|
84
84
|
o = CachedClass.new
|
85
85
|
o.multiplier = 2
|
@@ -87,52 +87,52 @@ describe 'DeclarativeCache' do
|
|
87
87
|
o.multiplier = 3
|
88
88
|
(o * 2).should == 4
|
89
89
|
end
|
90
|
-
|
90
|
+
|
91
91
|
class CachedClass2
|
92
92
|
class << self
|
93
93
|
attr_accessor :value
|
94
94
|
def value_get; @value end
|
95
95
|
cache_method :value_get
|
96
96
|
end
|
97
|
-
end
|
98
|
-
|
97
|
+
end
|
98
|
+
|
99
99
|
it "Simple Cache" do
|
100
100
|
CachedClass2.value = 0
|
101
101
|
CachedClass2.value_get.should == 0
|
102
102
|
CachedClass2.value = 1
|
103
103
|
CachedClass2.value_get.should == 0
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
106
|
module CachedModule
|
107
107
|
attr_accessor :value
|
108
108
|
def value_get; @value end
|
109
109
|
cache_method :value_get
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
class CachedClass3
|
113
113
|
include CachedModule
|
114
114
|
end
|
115
|
-
|
115
|
+
|
116
116
|
it "should also works with modules (from error)" do
|
117
117
|
o = CachedClass.new
|
118
118
|
o.value = 0
|
119
119
|
o.value_get.should == 0
|
120
|
-
|
120
|
+
|
121
121
|
o.value = 1
|
122
122
|
o.value_get.should == 0
|
123
123
|
end
|
124
|
-
|
124
|
+
|
125
125
|
class CachedClass4
|
126
126
|
attr_accessor :value
|
127
|
-
def value_get; @value end
|
127
|
+
def value_get; @value end
|
128
128
|
end
|
129
|
-
|
129
|
+
|
130
130
|
it "should not cache twice, and should works" do
|
131
|
-
CachedClass4.cache_method :value_get
|
132
|
-
|
131
|
+
CachedClass4.cache_method :value_get
|
132
|
+
|
133
133
|
Object.should_receive(:warn){|msg| msg =~ /twice/}
|
134
134
|
CachedClass4.cache_method :value_get
|
135
|
-
|
135
|
+
|
136
136
|
o = CachedClass.new
|
137
137
|
o.value = 0
|
138
138
|
o.value_get.should == 0
|
@@ -2,17 +2,17 @@ require "more/spec_helper"
|
|
2
2
|
|
3
3
|
describe "Observable" do
|
4
4
|
class AnObservable
|
5
|
-
include
|
5
|
+
include RubyExt::Observable
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
it "Method without Parameters" do
|
9
9
|
mock = mock("Observer")
|
10
10
|
obs = AnObservable.new
|
11
11
|
obs.add_observer mock
|
12
12
|
mock.should_receive(:update).with(2)
|
13
|
-
obs.notify_observers :update, 2
|
13
|
+
obs.notify_observers :update, 2
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
# it "Method without Parameters" do
|
17
17
|
# mock = mock("Observer")
|
18
18
|
# obs = AnObservable.new
|
@@ -21,7 +21,7 @@ describe "Observable" do
|
|
21
21
|
# obs.notify_observers 2
|
22
22
|
# obs.notify_observers 4
|
23
23
|
# end
|
24
|
-
#
|
24
|
+
#
|
25
25
|
# it "With Block" do
|
26
26
|
# mock = mock("Observer")
|
27
27
|
# mock.should_receive(:got)
|
@@ -29,13 +29,13 @@ describe "Observable" do
|
|
29
29
|
# obs.add_observer{mock.got}
|
30
30
|
# obs.notify_observers
|
31
31
|
# end
|
32
|
-
#
|
32
|
+
#
|
33
33
|
# it "With Block and Filter" do
|
34
34
|
# mock = mock("Observer")
|
35
35
|
# obs = AnObservable.new
|
36
36
|
# obs.add_observer(filter: -> {|o| o == 2}){|o| mock.got o}
|
37
37
|
# mock.should_receive(:got).with(2)
|
38
38
|
# obs.notify_observers 2
|
39
|
-
# obs.notify_observers 4
|
39
|
+
# obs.notify_observers 4
|
40
40
|
# end
|
41
41
|
end
|
@@ -2,7 +2,7 @@ require "more/spec_helper"
|
|
2
2
|
|
3
3
|
describe 'OpenConstructor' do
|
4
4
|
class Test
|
5
|
-
include OpenConstructor
|
5
|
+
include RubyExt::OpenConstructor
|
6
6
|
attr_accessor :name, :value
|
7
7
|
end
|
8
8
|
|
@@ -10,23 +10,23 @@ describe 'OpenConstructor' do
|
|
10
10
|
t = Test.new.set(name: 'name', value: 'value')
|
11
11
|
[t.name, t.value].should == ['name', 'value']
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
it 'should initialize atributes from any Object' do
|
15
15
|
t = Test.new.set(name: 'name', value: 'value')
|
16
16
|
t2 = Test.new.set t
|
17
17
|
[t2.name, t2.value].should == ['name', 'value']
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
it 'restrict copied values' do
|
21
21
|
t = Test.new.set(name: 'name', value: 'value')
|
22
22
|
t2 = Test.new.set t, [:name]
|
23
23
|
[t2.name, t2.value].should == ['name', nil]
|
24
|
-
|
24
|
+
|
25
25
|
t = {name: 'name', value: 'value'}
|
26
26
|
t2 = Test.new.set t, [:name]
|
27
27
|
[t2.name, t2.value].should == ['name', nil]
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
it 'to_hash' do
|
31
31
|
h = {name: 'name', value: 'value'}
|
32
32
|
t = Test.new.set h
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-08-
|
12
|
+
date: 2011-08-20 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description:
|
15
15
|
email:
|
@@ -25,14 +25,10 @@ files:
|
|
25
25
|
- lib/rspec_ext.rb
|
26
26
|
- lib/ruby_ext/core/array.rb
|
27
27
|
- lib/ruby_ext/core/basic_object.rb
|
28
|
-
- lib/ruby_ext/core/class.rb
|
29
28
|
- lib/ruby_ext/core/deep_clone.rb
|
30
29
|
- lib/ruby_ext/core/enumerable.rb
|
31
30
|
- lib/ruby_ext/core/false_class.rb
|
32
|
-
- lib/ruby_ext/core/file.rb
|
33
31
|
- lib/ruby_ext/core/hash.rb
|
34
|
-
- lib/ruby_ext/core/kernel.rb
|
35
|
-
- lib/ruby_ext/core/miscellaneous.rb
|
36
32
|
- lib/ruby_ext/core/module.rb
|
37
33
|
- lib/ruby_ext/core/multiple_inheritance.rb
|
38
34
|
- lib/ruby_ext/core/must.rb
|
@@ -46,11 +42,11 @@ files:
|
|
46
42
|
- lib/ruby_ext/core.rb
|
47
43
|
- lib/ruby_ext/fixes.rb
|
48
44
|
- lib/ruby_ext/gems.rb
|
45
|
+
- lib/ruby_ext/more/callbacks.rb
|
49
46
|
- lib/ruby_ext/more/declarative_cache.rb
|
50
47
|
- lib/ruby_ext/more/miscellaneous.rb
|
51
|
-
- lib/ruby_ext/more/
|
48
|
+
- lib/ruby_ext/more/observable.rb
|
52
49
|
- lib/ruby_ext/more/open_constructor.rb
|
53
|
-
- lib/ruby_ext/more/synchronize.rb
|
54
50
|
- lib/ruby_ext/more/tuple.rb
|
55
51
|
- lib/ruby_ext/more.rb
|
56
52
|
- lib/ruby_ext.rb
|
@@ -58,21 +54,17 @@ files:
|
|
58
54
|
- spec/core/array_spec.rb
|
59
55
|
- spec/core/deep_clone_spec.rb
|
60
56
|
- spec/core/enumerable.rb
|
61
|
-
- spec/core/kernel_spec/another_class.rb
|
62
|
-
- spec/core/kernel_spec/the_namespace/class_b.rb
|
63
|
-
- spec/core/kernel_spec/TheNamespace/ClassA.rb
|
64
|
-
- spec/core/kernel_spec.rb
|
65
57
|
- spec/core/module_spec.rb
|
66
58
|
- spec/core/multiple_inheritance_spec.rb
|
67
59
|
- spec/core/must_spec.rb
|
60
|
+
- spec/core/object_spec.rb
|
68
61
|
- spec/core/open_object_spec.rb
|
69
62
|
- spec/core/spec_helper.rb
|
63
|
+
- spec/more/callbacks_spec.rb
|
70
64
|
- spec/more/declarative_cache_spec.rb
|
71
|
-
- spec/more/
|
72
|
-
- spec/more/observable2_spec.rb
|
65
|
+
- spec/more/observable_spec.rb
|
73
66
|
- spec/more/open_constructor_spec.rb
|
74
67
|
- spec/more/spec_helper.rb
|
75
|
-
- spec/more/synchronize_spec.rb
|
76
68
|
homepage: http://github.com/alexeypetrushin/ruby_ext
|
77
69
|
licenses: []
|
78
70
|
post_install_message:
|
data/lib/ruby_ext/core/class.rb
DELETED
File without changes
|
data/lib/ruby_ext/core/file.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
|
3
|
-
File.class_eval do
|
4
|
-
def file_name
|
5
|
-
File.basename path
|
6
|
-
end
|
7
|
-
|
8
|
-
class << self
|
9
|
-
def write(path, data)
|
10
|
-
File.open(path, "wb") do |file|
|
11
|
-
return file.write(data)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
# def create_directory dir
|
16
|
-
# FileUtils.mkdir_p dir unless File.exist? dir
|
17
|
-
# end
|
18
|
-
#
|
19
|
-
# def delete_directory dir
|
20
|
-
# FileUtils.rm_r dir, force: true if File.exist? dir
|
21
|
-
# end
|
22
|
-
end
|
23
|
-
end
|
data/lib/ruby_ext/core/kernel.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
Kernel.class_eval do
|
2
|
-
def respond_to sym, *args
|
3
|
-
return nil if not respond_to? sym
|
4
|
-
send sym, *args
|
5
|
-
end
|
6
|
-
|
7
|
-
# def _ &b
|
8
|
-
# raise "Block isn't provided!" unless b
|
9
|
-
# return b
|
10
|
-
# end
|
11
|
-
|
12
|
-
def singleton_class(&block)
|
13
|
-
if block_given?
|
14
|
-
(class << self; self; end).class_eval(&block)
|
15
|
-
self
|
16
|
-
else
|
17
|
-
(class << self; self; end)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
alias_method :metaclass, :singleton_class
|
21
|
-
alias_method :metaclass_eval, :singleton_class
|
22
|
-
|
23
|
-
# Removes the namespace (exact match and underscored) of given class (or self) from stacktrace
|
24
|
-
def raise_without_self *args
|
25
|
-
error, message, klasses = nil
|
26
|
-
if args.size == 1
|
27
|
-
error = RuntimeError
|
28
|
-
message = args[0]
|
29
|
-
klasses = [self]
|
30
|
-
elsif args.size == 2
|
31
|
-
message, klasses = args
|
32
|
-
error = RuntimeError
|
33
|
-
|
34
|
-
klasses = Array(klasses)
|
35
|
-
klasses << self
|
36
|
-
elsif args.size == 3
|
37
|
-
error, message, klasses = args
|
38
|
-
|
39
|
-
klasses = Array(klasses)
|
40
|
-
klasses << self
|
41
|
-
else
|
42
|
-
raise RuntimeError, "Invalid arguments!", caller
|
43
|
-
end
|
44
|
-
|
45
|
-
klasses.collect!{|c| (c.class == Class or c.class == Module or c.class == String) ? c : c.class}
|
46
|
-
|
47
|
-
# obtaining the namespace of each class
|
48
|
-
klasses.collect! do |c|
|
49
|
-
if c.respond_to? :namespace
|
50
|
-
c = c.namespace while c.namespace
|
51
|
-
c
|
52
|
-
else
|
53
|
-
c
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
# building regexp
|
58
|
-
skip = []
|
59
|
-
klasses.each do |c|
|
60
|
-
skip.push(/\/#{c.to_s}/) # exact match
|
61
|
-
skip.push(/\/#{c.to_s.underscore}/) # underscored
|
62
|
-
end
|
63
|
-
|
64
|
-
# cleaning stacktrace
|
65
|
-
stack = caller.select{|path| !skip.any?{|re| re =~ path}}
|
66
|
-
|
67
|
-
raise error, message, stack
|
68
|
-
end
|
69
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'monitor'
|
2
|
-
|
3
|
-
Module.class_eval do
|
4
|
-
def synchronize_method *methods
|
5
|
-
methods.each do |method|
|
6
|
-
raise "can't synchronize system method #{method}" if method =~ /^__/
|
7
|
-
|
8
|
-
als = "sync_#{escape_method(method)}".to_sym
|
9
|
-
|
10
|
-
raise "can't synchronize the '#{method}' twice!" if instance_methods.include?(als)
|
11
|
-
|
12
|
-
alias_method als, method
|
13
|
-
script = "\
|
14
|
-
def #{method} *p, &b
|
15
|
-
@monitor ||= Monitor.new
|
16
|
-
@monitor.synchronize{#{als} *p, &b}
|
17
|
-
end"
|
18
|
-
class_eval script, __FILE__, __LINE__
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def synchronize_all_methods include_super = false
|
23
|
-
methods = self.instance_methods(include_super).collect{|m| m}
|
24
|
-
synchronize_method *methods
|
25
|
-
end
|
26
|
-
end
|
data/spec/core/kernel_spec.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
require "core/spec_helper"
|
2
|
-
|
3
|
-
describe 'Kernel' do
|
4
|
-
class Respond
|
5
|
-
def test; 2 end
|
6
|
-
end
|
7
|
-
|
8
|
-
after :all do
|
9
|
-
[:TheNamespace, :AnotherClass].each{|c| Object.send :remove_const, c if Object.const_defined? c}
|
10
|
-
end
|
11
|
-
|
12
|
-
it "respond_to" do
|
13
|
-
r = Respond.new
|
14
|
-
r.respond_to(:not_exist).should be_nil
|
15
|
-
r.respond_to(:test).should == 2
|
16
|
-
end
|
17
|
-
|
18
|
-
it "raise_without_self" do
|
19
|
-
require "#{spec_dir}/TheNamespace/ClassA"
|
20
|
-
require "#{spec_dir}/the_namespace/class_b"
|
21
|
-
require "#{spec_dir}/another_class"
|
22
|
-
|
23
|
-
begin
|
24
|
-
TheNamespace::ClassA.problem_method
|
25
|
-
rescue StandardError => e
|
26
|
-
e.message.should =~ /Some problem/
|
27
|
-
stack = e.backtrace
|
28
|
-
stack.any?{|line| line =~ /ClassA/}.should be_false
|
29
|
-
stack.any?{|line| line =~ /kernel_spec/}.should be_true
|
30
|
-
end
|
31
|
-
|
32
|
-
begin
|
33
|
-
TheNamespace::ClassB.problem_method
|
34
|
-
rescue StandardError => e
|
35
|
-
e.message.should =~ /Some problem/
|
36
|
-
stack = e.backtrace
|
37
|
-
stack.any?{|line| line =~ /class_b/}.should be_false
|
38
|
-
stack.any?{|line| line =~ /kernel_spec/}.should be_true
|
39
|
-
end
|
40
|
-
|
41
|
-
begin
|
42
|
-
AnotherClass.exclude_multiple_classes
|
43
|
-
rescue StandardError => e
|
44
|
-
e.message.should =~ /Some problem/
|
45
|
-
stack = e.backtrace
|
46
|
-
stack.any?{|line| line =~ /class_b/}.should be_false
|
47
|
-
stack.any?{|line| line =~ /another_class/}.should be_false
|
48
|
-
stack.any?{|line| line =~ /kernel_spec/}.should be_true
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require "more/spec_helper"
|
2
|
-
|
3
|
-
describe "Miscellaneous" do
|
4
|
-
it "ARGV parsing" do
|
5
|
-
{
|
6
|
-
%(:a a 'a' 2 3.4 /a/) => [:a, 'a', 'a', 2, 3.4, /a/, {}],
|
7
|
-
%(a, b) => ['a', 'b', {}],
|
8
|
-
%(k: v) => [{k: 'v'}],
|
9
|
-
%(k: v, k2: 2, k3: nil) => [{k: 'v', k2: 2, k3: nil}]
|
10
|
-
}.each do |input, result|
|
11
|
-
RubyExt.argv(input.split(/\s/)).should == result
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,79 +0,0 @@
|
|
1
|
-
require "more/spec_helper"
|
2
|
-
|
3
|
-
describe "Synchronize" do
|
4
|
-
it "synchronize_method" do
|
5
|
-
class SAccount
|
6
|
-
attr_reader :from, :to
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
super
|
10
|
-
@from, @to = 0, 0
|
11
|
-
end
|
12
|
-
|
13
|
-
def transfer
|
14
|
-
@from -= 1
|
15
|
-
@to += 1
|
16
|
-
end
|
17
|
-
synchronize_method :transfer
|
18
|
-
end
|
19
|
-
|
20
|
-
a, threads = SAccount.new, []
|
21
|
-
100.times do
|
22
|
-
t = Thread.new do
|
23
|
-
100.times{a.transfer}
|
24
|
-
end
|
25
|
-
threads << t
|
26
|
-
end
|
27
|
-
threads.each{|t| t.join}
|
28
|
-
|
29
|
-
a.from.should == -10_000
|
30
|
-
a.to.should == 10_000
|
31
|
-
end
|
32
|
-
|
33
|
-
it "synchronize_all_methods" do
|
34
|
-
class SAccount2
|
35
|
-
attr_reader :from, :to
|
36
|
-
|
37
|
-
def initialize
|
38
|
-
super
|
39
|
-
@from, @to = 0, 0
|
40
|
-
end
|
41
|
-
|
42
|
-
def transfer
|
43
|
-
@from -= 1
|
44
|
-
@to += 1
|
45
|
-
end
|
46
|
-
synchronize_all_methods
|
47
|
-
end
|
48
|
-
|
49
|
-
a, threads = SAccount2.new, []
|
50
|
-
100.times do
|
51
|
-
t = Thread.new do
|
52
|
-
100.times{a.transfer}
|
53
|
-
end
|
54
|
-
threads << t
|
55
|
-
end
|
56
|
-
threads.each{|t| t.join}
|
57
|
-
|
58
|
-
a.from.should == -10_000
|
59
|
-
a.to.should == 10_000
|
60
|
-
end
|
61
|
-
|
62
|
-
it "singleton" do
|
63
|
-
class SAccount3
|
64
|
-
class << self
|
65
|
-
def a; end
|
66
|
-
synchronize_method :a
|
67
|
-
end
|
68
|
-
end
|
69
|
-
SAccount3.a
|
70
|
-
end
|
71
|
-
|
72
|
-
it "shouldn't allow to synchronize twice" do
|
73
|
-
class SAccount4
|
74
|
-
def a; end
|
75
|
-
end
|
76
|
-
SAccount4.synchronize_method :a
|
77
|
-
-> {SAccount4.synchronize_method :a}.should raise_error(/twice/)
|
78
|
-
end
|
79
|
-
end
|