kagemusha 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/History.ja.txt +11 -0
- data/History.txt +8 -0
- data/examples/date.rb +2 -2
- data/examples/datetime.rb +2 -2
- data/examples/first.rb +2 -2
- data/examples/rand.rb +2 -2
- data/examples/style.rb +5 -5
- data/examples/time.rb +2 -2
- data/lib/kagemusha.rb +2 -1
- data/lib/kagemusha/composite.rb +2 -1
- data/lib/kagemusha/core.rb +21 -16
- data/lib/kagemusha/date.rb +2 -1
- data/lib/kagemusha/datetime.rb +2 -1
- data/lib/kagemusha/rand.rb +3 -2
- data/lib/kagemusha/time.rb +2 -1
- data/lib/kagemusha/version.rb +3 -2
- data/script/console.cmd +0 -0
- data/script/destroy.cmd +0 -0
- data/script/generate.cmd +0 -0
- data/script/txt2html.cmd +0 -0
- data/test/test_bugs.rb +18 -9
- data/test/test_complex_cases.rb +12 -3
- data/test/test_composite.rb +2 -1
- data/test/test_date.rb +2 -1
- data/test/test_datetime.rb +2 -1
- data/test/test_helper.rb +2 -4
- data/test/test_kagemusha.rb +3 -2
- data/test/test_rand.rb +2 -1
- data/test/test_time.rb +2 -1
- metadata +8 -8
data/History.ja.txt
CHANGED
@@ -1,4 +1,15 @@
|
|
1
1
|
|
2
|
+
== 0.0.8 2009-02-09
|
3
|
+
|
4
|
+
* Ruby 1.9.1対応
|
5
|
+
* マジックコメントを追加
|
6
|
+
* ブロック引数のチェックが厳しくなった変更に対応
|
7
|
+
* メソッド一覧を取得するメソッド(methods等)がシンボルの配列を返すようになった変更に対応
|
8
|
+
|
9
|
+
== 0.0.7 2008-07-19
|
10
|
+
|
11
|
+
* lib/kagemusha/composite.rb、test/test_composite.rbがgemに格納されていなかったのを修正 :-(
|
12
|
+
|
2
13
|
== 0.0.6 2008-07-17
|
3
14
|
|
4
15
|
* Kagemusha::Compositeクラスを追加
|
data/History.txt
CHANGED
data/examples/date.rb
CHANGED
data/examples/datetime.rb
CHANGED
data/examples/first.rb
CHANGED
data/examples/rand.rb
CHANGED
data/examples/style.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
|
2
|
-
# $Id: style.rb
|
1
|
+
# coding: utf-8
|
2
|
+
# $Id: style.rb 120 2009-02-09 08:22:25Z yuyakato $
|
3
3
|
|
4
4
|
require "rubygems"
|
5
5
|
require "kagemusha"
|
@@ -12,7 +12,7 @@ p one_plus_one #=> 2
|
|
12
12
|
|
13
13
|
# Normal Style.
|
14
14
|
musha = Kagemusha.new(Fixnum)
|
15
|
-
musha.def(:+) { 1 }
|
15
|
+
musha.def(:+) { |x| 1 }
|
16
16
|
musha.swap {
|
17
17
|
p one_plus_one #=> 1
|
18
18
|
}
|
@@ -21,7 +21,7 @@ p one_plus_one #=> 2
|
|
21
21
|
|
22
22
|
# Block Style.
|
23
23
|
Kagemusha.new(Fixnum) { |m|
|
24
|
-
m.def(:+) { 1 }
|
24
|
+
m.def(:+) { |x| 1 }
|
25
25
|
m.swap {
|
26
26
|
p one_plus_one #=> 1
|
27
27
|
}
|
@@ -31,7 +31,7 @@ p one_plus_one #=> 2
|
|
31
31
|
|
32
32
|
# Chain Style.
|
33
33
|
Kagemusha.new(Fixnum).
|
34
|
-
def(:+) { 1 }.
|
34
|
+
def(:+) { |x| 1 }.
|
35
35
|
swap {
|
36
36
|
p one_plus_one #=> 1
|
37
37
|
}
|
data/examples/time.rb
CHANGED
data/lib/kagemusha.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
|
2
3
|
#==============================================================================#
|
3
|
-
# $Id: kagemusha.rb
|
4
|
+
# $Id: kagemusha.rb 120 2009-02-09 08:22:25Z yuyakato $
|
4
5
|
#==============================================================================#
|
5
6
|
|
6
7
|
require File.join(File.dirname(__FILE__), "kagemusha", "version")
|
data/lib/kagemusha/composite.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
|
2
3
|
#==============================================================================#
|
3
|
-
# $Id: composite.rb
|
4
|
+
# $Id: composite.rb 120 2009-02-09 08:22:25Z yuyakato $
|
4
5
|
#==============================================================================#
|
5
6
|
|
6
7
|
class Kagemusha
|
data/lib/kagemusha/core.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
|
2
3
|
#==============================================================================#
|
3
|
-
# $Id: core.rb
|
4
|
+
# $Id: core.rb 120 2009-02-09 08:22:25Z yuyakato $
|
4
5
|
#==============================================================================#
|
5
6
|
|
6
7
|
require File.join(File.dirname(__FILE__), "composite")
|
@@ -20,25 +21,25 @@ class Kagemusha #:nodoc:
|
|
20
21
|
end
|
21
22
|
|
22
23
|
def define_class_method(name, &block) #:nodoc:
|
23
|
-
@class_methods[name.to_s.
|
24
|
+
@class_methods[name.to_s.to_sym] = block
|
24
25
|
return self
|
25
26
|
end
|
26
27
|
alias :defs :define_class_method
|
27
28
|
|
28
29
|
def undefine_class_method(name) #:nodoc:
|
29
|
-
@class_methods[name.to_s.
|
30
|
+
@class_methods[name.to_s.to_sym] = false
|
30
31
|
return self
|
31
32
|
end
|
32
33
|
alias :undefs :undefine_class_method
|
33
34
|
|
34
35
|
def define_instance_method(name, &block) #:nodoc:
|
35
|
-
@instance_methods[name.to_s.
|
36
|
+
@instance_methods[name.to_s.to_sym] = block
|
36
37
|
return self
|
37
38
|
end
|
38
39
|
alias :def :define_instance_method
|
39
40
|
|
40
41
|
def undefine_instance_method(name) #:nodoc:
|
41
|
-
@instance_methods[name.to_s.
|
42
|
+
@instance_methods[name.to_s.to_sym] = false
|
42
43
|
return self
|
43
44
|
end
|
44
45
|
alias :undef :undefine_instance_method
|
@@ -48,16 +49,16 @@ class Kagemusha #:nodoc:
|
|
48
49
|
if proc
|
49
50
|
begin
|
50
51
|
# replace method
|
51
|
-
attr = get_accessibility(@meta, name
|
52
|
+
attr = get_accessibility(@meta, name)
|
52
53
|
|
53
|
-
methods = @klass.singleton_methods(false)
|
54
|
+
methods = to_symbols(@klass.singleton_methods(false))
|
54
55
|
|
55
56
|
method = @meta.instance_method(name)
|
56
57
|
|
57
58
|
@meta.instance_eval { define_method(name, proc) }
|
58
59
|
@meta.instance_eval { private(name) } if attr == :private
|
59
60
|
|
60
|
-
(methods.include?(name
|
61
|
+
(methods.include?(name) ? [name, :define, nil, method] : [name, :remove])
|
61
62
|
rescue NameError
|
62
63
|
# insert method
|
63
64
|
@meta.instance_eval { define_method(name, proc) }
|
@@ -79,11 +80,11 @@ class Kagemusha #:nodoc:
|
|
79
80
|
if proc
|
80
81
|
begin
|
81
82
|
# replace method
|
82
|
-
attr = get_accessibility(@klass, name
|
83
|
+
attr = get_accessibility(@klass, name)
|
83
84
|
|
84
|
-
methods = @klass.public_instance_methods(false)
|
85
|
-
methods += @klass.protected_instance_methods(false)
|
86
|
-
methods += @klass.private_instance_methods(false)
|
85
|
+
methods = to_symbols(@klass.public_instance_methods(false))
|
86
|
+
methods += to_symbols(@klass.protected_instance_methods(false))
|
87
|
+
methods += to_symbols(@klass.private_instance_methods(false))
|
87
88
|
|
88
89
|
method = @klass.instance_method(name)
|
89
90
|
|
@@ -91,7 +92,7 @@ class Kagemusha #:nodoc:
|
|
91
92
|
@klass.instance_eval { protected(name) } if attr == :protected
|
92
93
|
@klass.instance_eval { private(name) } if attr == :private
|
93
94
|
|
94
|
-
(methods.include?(name
|
95
|
+
(methods.include?(name) ? [name, :define, attr, method] : [name, :remove])
|
95
96
|
rescue NameError
|
96
97
|
# insert method
|
97
98
|
@klass.instance_eval { define_method(name, proc) }
|
@@ -144,11 +145,15 @@ class Kagemusha #:nodoc:
|
|
144
145
|
private
|
145
146
|
|
146
147
|
def get_accessibility(target, name)
|
147
|
-
return :public if target.public_instance_methods(true).include?(name)
|
148
|
-
return :protected if target.protected_instance_methods(true).include?(name)
|
149
|
-
return :private if target.private_instance_methods(true).include?(name)
|
148
|
+
return :public if to_symbols(target.public_instance_methods(true)).include?(name)
|
149
|
+
return :protected if to_symbols(target.protected_instance_methods(true)).include?(name)
|
150
|
+
return :private if to_symbols(target.private_instance_methods(true)).include?(name)
|
150
151
|
return nil
|
151
152
|
end
|
153
|
+
|
154
|
+
def to_symbols(array)
|
155
|
+
return array.map { |item| item.to_sym }
|
156
|
+
end
|
152
157
|
end
|
153
158
|
|
154
159
|
#==============================================================================#
|
data/lib/kagemusha/date.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
|
2
3
|
#==============================================================================#
|
3
|
-
# $Id: date.rb
|
4
|
+
# $Id: date.rb 120 2009-02-09 08:22:25Z yuyakato $
|
4
5
|
#==============================================================================#
|
5
6
|
|
6
7
|
require File.join(File.dirname(__FILE__), "core")
|
data/lib/kagemusha/datetime.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
|
2
3
|
#==============================================================================#
|
3
|
-
# $Id: datetime.rb
|
4
|
+
# $Id: datetime.rb 120 2009-02-09 08:22:25Z yuyakato $
|
4
5
|
#==============================================================================#
|
5
6
|
|
6
7
|
require File.join(File.dirname(__FILE__), "date")
|
data/lib/kagemusha/rand.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
|
2
3
|
#==============================================================================#
|
3
|
-
# $Id: rand.rb
|
4
|
+
# $Id: rand.rb 120 2009-02-09 08:22:25Z yuyakato $
|
4
5
|
#==============================================================================#
|
5
6
|
|
6
7
|
require File.join(File.dirname(__FILE__), "core")
|
@@ -15,7 +16,7 @@ class Kagemusha #:nodoc:
|
|
15
16
|
end
|
16
17
|
|
17
18
|
musha = Kagemusha.new(Kernel)
|
18
|
-
musha.def(:rand) { num }
|
19
|
+
musha.def(:rand) { |*x| num }
|
19
20
|
|
20
21
|
return musha
|
21
22
|
end
|
data/lib/kagemusha/time.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
|
2
3
|
#==============================================================================#
|
3
|
-
# $Id: time.rb
|
4
|
+
# $Id: time.rb 120 2009-02-09 08:22:25Z yuyakato $
|
4
5
|
#==============================================================================#
|
5
6
|
|
6
7
|
require File.join(File.dirname(__FILE__), "core")
|
data/lib/kagemusha/version.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
|
2
3
|
#==============================================================================#
|
3
|
-
# $Id: version.rb
|
4
|
+
# $Id: version.rb 120 2009-02-09 08:22:25Z yuyakato $
|
4
5
|
#==============================================================================#
|
5
6
|
|
6
7
|
class Kagemusha #:nodoc:
|
7
8
|
module VERSION #:nodoc:
|
8
9
|
MAJOR = 0
|
9
10
|
MINOR = 0
|
10
|
-
TINY =
|
11
|
+
TINY = 8
|
11
12
|
|
12
13
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
13
14
|
end
|
data/script/console.cmd
CHANGED
File without changes
|
data/script/destroy.cmd
CHANGED
File without changes
|
data/script/generate.cmd
CHANGED
File without changes
|
data/script/txt2html.cmd
CHANGED
File without changes
|
data/test/test_bugs.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
|
2
3
|
#==============================================================================#
|
3
|
-
# $Id: test_bugs.rb
|
4
|
+
# $Id: test_bugs.rb 120 2009-02-09 08:22:25Z yuyakato $
|
4
5
|
#==============================================================================#
|
5
6
|
|
6
7
|
require File.dirname(__FILE__) + "/test_helper.rb"
|
@@ -56,11 +57,19 @@ class TestBugs < Test::Unit::TestCase
|
|
56
57
|
|
57
58
|
assert_equal(:replaced, child_c.target)
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
if RUBY_VERSION < "1.9.0"
|
61
|
+
child_m.instance_eval { define_method(name, old_method) }
|
62
|
+
|
63
|
+
# @1.8.6 TypeError: singleton method bound for a different object
|
64
|
+
assert_raise(TypeError) {
|
65
|
+
child_c.target
|
66
|
+
}
|
67
|
+
else
|
68
|
+
# @1.9.1 TypeError: can't bind singleton method to a different class
|
69
|
+
assert_raise(TypeError) {
|
70
|
+
child_m.instance_eval { define_method(name, old_method) }
|
71
|
+
}
|
72
|
+
end
|
64
73
|
end
|
65
74
|
|
66
75
|
def test_report01_correct_mechanism
|
@@ -77,20 +86,20 @@ class TestBugs < Test::Unit::TestCase
|
|
77
86
|
new_method = proc { :replaced }
|
78
87
|
old_method = child_m.instance_method(name)
|
79
88
|
|
80
|
-
assert_equal(false, child_c.singleton_methods(false).include?(name
|
89
|
+
assert_equal(false, child_c.singleton_methods(false).map { |n| n.to_sym }.include?(name))
|
81
90
|
|
82
91
|
child_m.instance_eval { define_method(name, new_method) }
|
83
92
|
|
84
93
|
assert_equal(:replaced, child_c.target)
|
85
94
|
|
86
|
-
child_m.instance_eval { remove_method(name) }
|
95
|
+
child_m.instance_eval { remove_method(name) } # define_method -> remove_method
|
87
96
|
|
88
97
|
assert_equal(:original, child_c.target)
|
89
98
|
end
|
90
99
|
|
91
100
|
def test_report02
|
92
101
|
musha = Kagemusha.new(Kernel)
|
93
|
-
musha.def(:Integer) { :replaced }
|
102
|
+
musha.def(:Integer) { |x| :replaced }
|
94
103
|
|
95
104
|
assert(1, Integer("1"))
|
96
105
|
|
data/test/test_complex_cases.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
|
2
3
|
#==============================================================================#
|
3
|
-
# $Id: test_complex_cases.rb
|
4
|
+
# $Id: test_complex_cases.rb 120 2009-02-09 08:22:25Z yuyakato $
|
4
5
|
#==============================================================================#
|
5
6
|
|
6
7
|
require File.dirname(__FILE__) + "/test_helper.rb"
|
@@ -210,8 +211,16 @@ class TestComplexCases < Test::Unit::TestCase
|
|
210
211
|
}
|
211
212
|
|
212
213
|
assert_equal(old_value, C1.c1_class)
|
213
|
-
|
214
|
-
|
214
|
+
|
215
|
+
if RUBY_VERSION < "1.9.0"
|
216
|
+
# @1.8.6 TypeError: singleton method bound for a different object
|
217
|
+
assert_raise(TypeError) { C2.c1_class }
|
218
|
+
assert_raise(TypeError) { C3.c1_class }
|
219
|
+
else
|
220
|
+
# @1.9.1 No Error
|
221
|
+
assert_equal(old_value, C2.c1_class)
|
222
|
+
assert_equal(old_value, C3.c1_class)
|
223
|
+
end
|
215
224
|
end
|
216
225
|
|
217
226
|
def test_replace_private_class_method_defined_on_self_class
|
data/test/test_composite.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
|
2
3
|
#==============================================================================#
|
3
|
-
# $Id: test_composite.rb
|
4
|
+
# $Id: test_composite.rb 120 2009-02-09 08:22:25Z yuyakato $
|
4
5
|
#==============================================================================#
|
5
6
|
|
6
7
|
require File.dirname(__FILE__) + "/test_helper.rb"
|
data/test/test_date.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
|
2
3
|
#==============================================================================#
|
3
|
-
# $Id: test_date.rb
|
4
|
+
# $Id: test_date.rb 120 2009-02-09 08:22:25Z yuyakato $
|
4
5
|
#==============================================================================#
|
5
6
|
|
6
7
|
require File.dirname(__FILE__) + "/test_helper.rb"
|
data/test/test_datetime.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
|
2
3
|
#==============================================================================#
|
3
|
-
# $Id: test_datetime.rb
|
4
|
+
# $Id: test_datetime.rb 120 2009-02-09 08:22:25Z yuyakato $
|
4
5
|
#==============================================================================#
|
5
6
|
|
6
7
|
require File.dirname(__FILE__) + "/test_helper.rb"
|
data/test/test_helper.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
|
2
3
|
#==============================================================================#
|
3
|
-
# $Id: test_helper.rb
|
4
|
+
# $Id: test_helper.rb 120 2009-02-09 08:22:25Z yuyakato $
|
4
5
|
#==============================================================================#
|
5
6
|
|
6
7
|
require "test/unit"
|
7
8
|
require File.dirname(__FILE__) + "/../lib/kagemusha"
|
8
9
|
|
9
|
-
require "rubygems"
|
10
|
-
require "redgreen"
|
11
|
-
|
12
10
|
#==============================================================================#
|
13
11
|
#==============================================================================#
|
data/test/test_kagemusha.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
|
2
3
|
#==============================================================================#
|
3
|
-
# $Id: test_kagemusha.rb
|
4
|
+
# $Id: test_kagemusha.rb 120 2009-02-09 08:22:25Z yuyakato $
|
4
5
|
#==============================================================================#
|
5
6
|
|
6
7
|
require File.dirname(__FILE__) + "/test_helper.rb"
|
@@ -132,7 +133,7 @@ class TestKagemusha < Test::Unit::TestCase
|
|
132
133
|
|
133
134
|
def test_swap_class_method
|
134
135
|
@musha = Kagemusha.new(Regexp)
|
135
|
-
@musha.defs(:compile) { /bar/ }
|
136
|
+
@musha.defs(:compile) { |string| /bar/ }
|
136
137
|
|
137
138
|
assert_equal(/foo/, Regexp.compile("foo"))
|
138
139
|
|
data/test/test_rand.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
|
2
3
|
#==============================================================================#
|
3
|
-
# $Id: test_rand.rb
|
4
|
+
# $Id: test_rand.rb 120 2009-02-09 08:22:25Z yuyakato $
|
4
5
|
#==============================================================================#
|
5
6
|
|
6
7
|
require File.dirname(__FILE__) + "/test_helper.rb"
|
data/test/test_time.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
|
2
3
|
#==============================================================================#
|
3
|
-
# $Id: test_time.rb
|
4
|
+
# $Id: test_time.rb 120 2009-02-09 08:22:25Z yuyakato $
|
4
5
|
#==============================================================================#
|
5
6
|
|
6
7
|
require File.dirname(__FILE__) + "/test_helper.rb"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kagemusha
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuya Kato
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2009-02-09 00:00:00 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -115,12 +115,12 @@ signing_key:
|
|
115
115
|
specification_version: 2
|
116
116
|
summary: Kagemusha is a library of helper functions for testing Ruby scripts.
|
117
117
|
test_files:
|
118
|
-
- test/test_kagemusha.rb
|
119
|
-
- test/test_helper.rb
|
120
|
-
- test/test_datetime.rb
|
121
|
-
- test/test_time.rb
|
122
|
-
- test/test_rand.rb
|
123
|
-
- test/test_date.rb
|
124
118
|
- test/test_bugs.rb
|
125
119
|
- test/test_complex_cases.rb
|
126
120
|
- test/test_composite.rb
|
121
|
+
- test/test_date.rb
|
122
|
+
- test/test_datetime.rb
|
123
|
+
- test/test_helper.rb
|
124
|
+
- test/test_kagemusha.rb
|
125
|
+
- test/test_rand.rb
|
126
|
+
- test/test_time.rb
|