kagemusha 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -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クラスを追加
@@ -1,4 +1,12 @@
1
1
 
2
+ == 0.0.8 2009-02-09
3
+
4
+ ...
5
+
6
+ == 0.0.7 2008-07-19
7
+
8
+ ...
9
+
2
10
  == 0.0.6 2008-07-17
3
11
 
4
12
  ...
@@ -1,5 +1,5 @@
1
-
2
- # $Id: date.rb 40 2007-08-27 13:21:13Z yuyakato $
1
+ # coding: utf-8
2
+ # $Id: date.rb 120 2009-02-09 08:22:25Z yuyakato $
3
3
 
4
4
  require "rubygems"
5
5
  require "kagemusha/date"
@@ -1,5 +1,5 @@
1
-
2
- # $Id: datetime.rb 40 2007-08-27 13:21:13Z yuyakato $
1
+ # coding: utf-8
2
+ # $Id: datetime.rb 120 2009-02-09 08:22:25Z yuyakato $
3
3
 
4
4
  require "rubygems"
5
5
  require "kagemusha/datetime"
@@ -1,5 +1,5 @@
1
-
2
- # $Id: first.rb 40 2007-08-27 13:21:13Z yuyakato $
1
+ # coding: utf-8
2
+ # $Id: first.rb 120 2009-02-09 08:22:25Z yuyakato $
3
3
 
4
4
  require "rubygems"
5
5
  require "kagemusha"
@@ -1,5 +1,5 @@
1
-
2
- # $Id: rand.rb 40 2007-08-27 13:21:13Z yuyakato $
1
+ # coding: utf-8
2
+ # $Id: rand.rb 120 2009-02-09 08:22:25Z yuyakato $
3
3
 
4
4
  require "rubygems"
5
5
  require "kagemusha/rand"
@@ -1,5 +1,5 @@
1
-
2
- # $Id: style.rb 38 2007-08-27 13:03:39Z yuyakato $
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
  }
@@ -1,5 +1,5 @@
1
-
2
- # $Id: time.rb 40 2007-08-27 13:21:13Z yuyakato $
1
+ # coding: utf-8
2
+ # $Id: time.rb 120 2009-02-09 08:22:25Z yuyakato $
3
3
 
4
4
  require "rubygems"
5
5
  require "kagemusha/time"
@@ -1,6 +1,7 @@
1
+ # coding: utf-8
1
2
 
2
3
  #==============================================================================#
3
- # $Id: kagemusha.rb 44 2007-09-07 02:32:58Z yuyakato $
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")
@@ -1,6 +1,7 @@
1
+ # coding: utf-8
1
2
 
2
3
  #==============================================================================#
3
- # $Id: composite.rb 99 2008-07-17 13:56:26Z yuyakato $
4
+ # $Id: composite.rb 120 2009-02-09 08:22:25Z yuyakato $
4
5
  #==============================================================================#
5
6
 
6
7
  class Kagemusha
@@ -1,6 +1,7 @@
1
+ # coding: utf-8
1
2
 
2
3
  #==============================================================================#
3
- # $Id: core.rb 97 2008-07-17 13:40:55Z yuyakato $
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.intern] = block
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.intern] = false
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.intern] = block
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.intern] = false
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.to_s)
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.to_s) ? [name, :define, nil, method] : [name, :remove])
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.to_s)
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.to_s) ? [name, :define, attr, method] : [name, :remove])
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
  #==============================================================================#
@@ -1,6 +1,7 @@
1
+ # coding: utf-8
1
2
 
2
3
  #==============================================================================#
3
- # $Id: date.rb 44 2007-09-07 02:32:58Z yuyakato $
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")
@@ -1,6 +1,7 @@
1
+ # coding: utf-8
1
2
 
2
3
  #==============================================================================#
3
- # $Id: datetime.rb 99 2008-07-17 13:56:26Z yuyakato $
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")
@@ -1,6 +1,7 @@
1
+ # coding: utf-8
1
2
 
2
3
  #==============================================================================#
3
- # $Id: rand.rb 44 2007-09-07 02:32:58Z yuyakato $
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
@@ -1,6 +1,7 @@
1
+ # coding: utf-8
1
2
 
2
3
  #==============================================================================#
3
- # $Id: time.rb 44 2007-09-07 02:32:58Z yuyakato $
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")
@@ -1,13 +1,14 @@
1
+ # coding: utf-8
1
2
 
2
3
  #==============================================================================#
3
- # $Id: version.rb 103 2008-07-19 06:13:27Z yuyakato $
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 = 7
11
+ TINY = 8
11
12
 
12
13
  STRING = [MAJOR, MINOR, TINY].join('.')
13
14
  end
File without changes
File without changes
File without changes
File without changes
@@ -1,6 +1,7 @@
1
+ # coding: utf-8
1
2
 
2
3
  #==============================================================================#
3
- # $Id: test_bugs.rb 66 2008-07-16 03:04:32Z yuyakato $
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
- child_m.instance_eval { define_method(name, old_method) }
60
-
61
- assert_raise(TypeError) {
62
- child_c.target
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.to_s))
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
 
@@ -1,6 +1,7 @@
1
+ # coding: utf-8
1
2
 
2
3
  #==============================================================================#
3
- # $Id: test_complex_cases.rb 84 2008-07-17 05:37:11Z yuyakato $
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
- assert_equal(old_value, C2.c1_class) # FIXME: TypeError: singleton method bound for a different object
214
- assert_equal(old_value, C3.c1_class) # FIXME: TypeError: singleton method bound for a different object
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
@@ -1,6 +1,7 @@
1
+ # coding: utf-8
1
2
 
2
3
  #==============================================================================#
3
- # $Id: test_composite.rb 99 2008-07-17 13:56:26Z yuyakato $
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"
@@ -1,6 +1,7 @@
1
+ # coding: utf-8
1
2
 
2
3
  #==============================================================================#
3
- # $Id: test_date.rb 37 2007-08-27 13:02:39Z yuyakato $
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"
@@ -1,6 +1,7 @@
1
+ # coding: utf-8
1
2
 
2
3
  #==============================================================================#
3
- # $Id: test_datetime.rb 37 2007-08-27 13:02:39Z yuyakato $
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"
@@ -1,13 +1,11 @@
1
+ # coding: utf-8
1
2
 
2
3
  #==============================================================================#
3
- # $Id: test_helper.rb 90 2008-07-17 12:31:43Z yuyakato $
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
  #==============================================================================#
@@ -1,6 +1,7 @@
1
+ # coding: utf-8
1
2
 
2
3
  #==============================================================================#
3
- # $Id: test_kagemusha.rb 97 2008-07-17 13:40:55Z yuyakato $
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
 
@@ -1,6 +1,7 @@
1
+ # coding: utf-8
1
2
 
2
3
  #==============================================================================#
3
- # $Id: test_rand.rb 68 2008-07-16 04:17:33Z yuyakato $
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"
@@ -1,6 +1,7 @@
1
+ # coding: utf-8
1
2
 
2
3
  #==============================================================================#
3
- # $Id: test_time.rb 37 2007-08-27 13:02:39Z yuyakato $
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.7
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: 2008-07-19 00:00:00 +09:00
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