kagemusha 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,4 +1,8 @@
1
1
 
2
+ == 0.0.3 2007-09-10
3
+
4
+ ...
5
+
2
6
  == 0.0.2 2007-08-27
3
7
 
4
8
  ...
@@ -1,6 +1,6 @@
1
1
 
2
2
  #==============================================================================#
3
- # $Id: core.rb 35 2007-08-27 12:59:31Z yuyakato $
3
+ # $Id: core.rb 45 2007-09-07 04:49:51Z yuyakato $
4
4
  #==============================================================================#
5
5
 
6
6
  class Kagemusha #:nodoc:
@@ -22,7 +22,7 @@ class Kagemusha #:nodoc:
22
22
  alias :defs :define_class_method
23
23
 
24
24
  def undefine_class_method(name) #:nodoc:
25
- @class_methods.delete(name.to_s.intern)
25
+ @class_methods[name.to_s.intern] = false
26
26
  return self
27
27
  end
28
28
  alias :undefs :undefine_class_method
@@ -34,7 +34,7 @@ class Kagemusha #:nodoc:
34
34
  alias :def :define_instance_method
35
35
 
36
36
  def undefine_instance_method(name) #:nodoc:
37
- @instance_methods.delete(name.to_s.intern)
37
+ @instance_methods[name.to_s.intern] = false
38
38
  return self
39
39
  end
40
40
  alias :undef :undefine_instance_method
@@ -44,24 +44,72 @@ class Kagemusha #:nodoc:
44
44
  original_instance_methods = {}
45
45
 
46
46
  @class_methods.each { |name, proc|
47
- method = @meta.instance_method(name)
48
- @meta.instance_eval { define_method(name, proc) }
49
- original_class_methods[name] = method
47
+ if proc
48
+ begin
49
+ # replace method
50
+ method = @meta.instance_method(name)
51
+ @meta.instance_eval { define_method(name, proc) }
52
+ original_class_methods[name] = method
53
+ rescue NameError
54
+ # insert method
55
+ @meta.instance_eval { define_method(name, proc) }
56
+ original_class_methods[name] = false
57
+ end
58
+ else
59
+ begin
60
+ # remove method
61
+ method = @meta.instance_method(name)
62
+ @meta.instance_eval { undef_method(name) }
63
+ original_class_methods[name] = method
64
+ rescue NameError
65
+ # nop
66
+ end
67
+ end
50
68
  }
51
69
 
52
70
  @instance_methods.each { |name, proc|
53
- method = @klass.instance_method(name)
54
- @klass.instance_eval { define_method(name, proc) }
55
- original_instance_methods[name] = method
71
+ if proc
72
+ begin
73
+ # replace method
74
+ method = @klass.instance_method(name)
75
+ @klass.instance_eval { define_method(name, proc) }
76
+ original_instance_methods[name] = method
77
+ rescue NameError
78
+ # insert method
79
+ @klass.instance_eval { define_method(name, proc) }
80
+ original_instance_methods[name] = false
81
+ end
82
+ else
83
+ begin
84
+ # remove method
85
+ method = @klass.instance_method(name)
86
+ @klass.instance_eval { undef_method(name) }
87
+ original_instance_methods[name] = method
88
+ rescue NameError
89
+ # nop
90
+ end
91
+ end
56
92
  }
57
93
 
58
94
  return yield
59
95
  ensure
60
96
  original_class_methods.each { |name, method|
61
- @meta.instance_eval { define_method(name, method) }
97
+ if method
98
+ # replace method
99
+ @meta.instance_eval { define_method(name, method) }
100
+ else
101
+ # remove method
102
+ @meta.instance_eval { undef_method(name) }
103
+ end
62
104
  }
63
105
  original_instance_methods.each { |name, method|
64
- @klass.instance_eval { define_method(name, method) }
106
+ if method
107
+ # replace method
108
+ @klass.instance_eval { define_method(name, method) }
109
+ else
110
+ # remove method
111
+ @klass.instance_eval { undef_method(name) }
112
+ end
65
113
  }
66
114
  end
67
115
  end
@@ -1,9 +1,9 @@
1
1
 
2
2
  #==============================================================================#
3
- # $Id: date.rb 37 2007-08-27 13:02:39Z yuyakato $
3
+ # $Id: date.rb 44 2007-09-07 02:32:58Z yuyakato $
4
4
  #==============================================================================#
5
5
 
6
- require "kagemusha"
6
+ require File.join(File.dirname(__FILE__), "core")
7
7
  require "date"
8
8
 
9
9
  #==============================================================================#
@@ -1,10 +1,10 @@
1
1
 
2
2
  #==============================================================================#
3
- # $Id: datetime.rb 37 2007-08-27 13:02:39Z yuyakato $
3
+ # $Id: datetime.rb 44 2007-09-07 02:32:58Z yuyakato $
4
4
  #==============================================================================#
5
5
 
6
- require "kagemusha/date"
7
- require "kagemusha/time"
6
+ require File.join(File.dirname(__FILE__), "date")
7
+ require File.join(File.dirname(__FILE__), "time")
8
8
 
9
9
  #==============================================================================#
10
10
 
@@ -1,9 +1,9 @@
1
1
 
2
2
  #==============================================================================#
3
- # $Id: rand.rb 33 2007-08-27 12:25:50Z yuyakato $
3
+ # $Id: rand.rb 44 2007-09-07 02:32:58Z yuyakato $
4
4
  #==============================================================================#
5
5
 
6
- require "kagemusha"
6
+ require File.join(File.dirname(__FILE__), "core")
7
7
 
8
8
  #==============================================================================#
9
9
 
@@ -1,9 +1,9 @@
1
1
 
2
2
  #==============================================================================#
3
- # $Id: time.rb 33 2007-08-27 12:25:50Z yuyakato $
3
+ # $Id: time.rb 44 2007-09-07 02:32:58Z yuyakato $
4
4
  #==============================================================================#
5
5
 
6
- require "kagemusha"
6
+ require File.join(File.dirname(__FILE__), "core")
7
7
 
8
8
  #==============================================================================#
9
9
 
@@ -1,13 +1,13 @@
1
1
 
2
2
  #==============================================================================#
3
- # $Id: version.rb 33 2007-08-27 12:25:50Z yuyakato $
3
+ # $Id: version.rb 44 2007-09-07 02:32:58Z yuyakato $
4
4
  #==============================================================================#
5
5
 
6
6
  class Kagemusha #:nodoc:
7
7
  module VERSION #:nodoc:
8
8
  MAJOR = 0
9
9
  MINOR = 0
10
- TINY = 2
10
+ TINY = 3
11
11
 
12
12
  STRING = [MAJOR, MINOR, TINY].join('.')
13
13
  end
data/lib/kagemusha.rb CHANGED
@@ -1,10 +1,10 @@
1
1
 
2
2
  #==============================================================================#
3
- # $Id: kagemusha.rb 4 2007-08-15 08:10:42Z yuyakato $
3
+ # $Id: kagemusha.rb 44 2007-09-07 02:32:58Z yuyakato $
4
4
  #==============================================================================#
5
5
 
6
- require "kagemusha/version"
7
- require "kagemusha/core"
6
+ require File.join(File.dirname(__FILE__), "kagemusha", "version")
7
+ require File.join(File.dirname(__FILE__), "kagemusha", "core")
8
8
 
9
9
  #==============================================================================#
10
10
  #==============================================================================#
@@ -1,6 +1,6 @@
1
1
 
2
2
  #==============================================================================#
3
- # $Id: test_kagemusha.rb 35 2007-08-27 12:59:31Z yuyakato $
3
+ # $Id: test_kagemusha.rb 45 2007-09-07 04:49:51Z yuyakato $
4
4
  #==============================================================================#
5
5
 
6
6
  require File.dirname(__FILE__) + "/test_helper.rb"
@@ -56,14 +56,14 @@ class TestKagemusha < Test::Unit::TestCase
56
56
  ret = @musha.undefine_class_method("foo")
57
57
 
58
58
  assert_same(ret, @musha)
59
- assert_equal(nil, @musha.instance_eval { @class_methods[:foo] })
59
+ assert_equal(false, @musha.instance_eval { @class_methods[:foo] })
60
60
  assert_equal(block2, @musha.instance_eval { @class_methods[:bar] })
61
61
 
62
62
  ret = @musha.undefine_class_method(:bar)
63
63
 
64
64
  assert_same(ret, @musha)
65
- assert_equal(nil, @musha.instance_eval { @class_methods[:foo] })
66
- assert_equal(nil, @musha.instance_eval { @class_methods[:bar] })
65
+ assert_equal(false, @musha.instance_eval { @class_methods[:foo] })
66
+ assert_equal(false, @musha.instance_eval { @class_methods[:bar] })
67
67
  end
68
68
 
69
69
  def test_defs_and_undefs
@@ -79,7 +79,7 @@ class TestKagemusha < Test::Unit::TestCase
79
79
  ret = @musha.undefs(:foo)
80
80
 
81
81
  assert_same(ret, @musha)
82
- assert_equal(nil, @musha.instance_eval { @class_methods[:foo] })
82
+ assert_equal(false, @musha.instance_eval { @class_methods[:foo] })
83
83
  end
84
84
 
85
85
  def test_define_instance_method_and_undefine
@@ -104,14 +104,14 @@ class TestKagemusha < Test::Unit::TestCase
104
104
  ret = @musha.undefine_instance_method("foo")
105
105
 
106
106
  assert_same(ret, @musha)
107
- assert_equal(nil, @musha.instance_eval { @instance_methods[:foo] })
107
+ assert_equal(false, @musha.instance_eval { @instance_methods[:foo] })
108
108
  assert_equal(block2, @musha.instance_eval { @instance_methods[:bar] })
109
109
 
110
110
  ret = @musha.undefine_instance_method(:bar)
111
111
 
112
112
  assert_same(ret, @musha)
113
- assert_equal(nil, @musha.instance_eval { @instance_methods[:foo] })
114
- assert_equal(nil, @musha.instance_eval { @instance_methods[:bar] })
113
+ assert_equal(false, @musha.instance_eval { @instance_methods[:foo] })
114
+ assert_equal(false, @musha.instance_eval { @instance_methods[:bar] })
115
115
  end
116
116
 
117
117
  def test_def_and_undef
@@ -127,7 +127,7 @@ class TestKagemusha < Test::Unit::TestCase
127
127
  ret = @musha.undef(:foo)
128
128
 
129
129
  assert_same(ret, @musha)
130
- assert_equal(nil, @musha.instance_eval { @instance_methods[:foo] })
130
+ assert_equal(false, @musha.instance_eval { @instance_methods[:foo] })
131
131
  end
132
132
 
133
133
  def test_swap_class_method
@@ -159,6 +159,86 @@ class TestKagemusha < Test::Unit::TestCase
159
159
  assert_equal(1, ret)
160
160
  assert_equal("foo", target.to_s)
161
161
  end
162
+
163
+ def test_insert_new_class_method
164
+ assert_raise(NoMethodError) {
165
+ String.foo
166
+ }
167
+
168
+ @musha.defs(:foo) { :ok }
169
+
170
+ assert_raise(NoMethodError) {
171
+ String.foo
172
+ }
173
+ assert_nothing_raised {
174
+ @musha.swap {
175
+ assert_equal(:ok, String.foo)
176
+ }
177
+ }
178
+ assert_raise(NoMethodError) {
179
+ String.foo
180
+ }
181
+ end
182
+
183
+ def test_remove_exist_class_method
184
+ assert_nothing_raised {
185
+ String.clone
186
+ }
187
+
188
+ @musha.undefs(:clone)
189
+
190
+ assert_nothing_raised {
191
+ String.clone
192
+ }
193
+ assert_raise(NoMethodError) {
194
+ @musha.swap {
195
+ String.clone
196
+ }
197
+ }
198
+ assert_nothing_raised {
199
+ String.clone
200
+ }
201
+ end
202
+
203
+ def test_insert_new_instance_method
204
+ assert_raise(NoMethodError) {
205
+ "".foo
206
+ }
207
+
208
+ @musha.def(:foo) { :ok }
209
+
210
+ assert_raise(NoMethodError) {
211
+ "".foo
212
+ }
213
+ assert_nothing_raised {
214
+ @musha.swap {
215
+ assert_equal(:ok, "".foo)
216
+ }
217
+ }
218
+ assert_raise(NoMethodError) {
219
+ "".foo
220
+ }
221
+ end
222
+
223
+ def test_remove_exist_instance_method
224
+ assert_nothing_raised {
225
+ "".clone
226
+ }
227
+
228
+ @musha.undef(:clone)
229
+
230
+ assert_nothing_raised {
231
+ "".clone
232
+ }
233
+ assert_raise(NoMethodError) {
234
+ @musha.swap {
235
+ "".clone
236
+ }
237
+ }
238
+ assert_nothing_raised {
239
+ "".clone
240
+ }
241
+ end
162
242
  end
163
243
 
164
244
  #==============================================================================#
data/website/index.html CHANGED
@@ -33,7 +33,7 @@
33
33
  <h1>Kagemusha &#8211; 影武者</h1>
34
34
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/kagemusha"; return false'>
35
35
  <p>Get Version</p>
36
- <a href="http://rubyforge.org/projects/kagemusha" class="numbers">0.0.2</a>
36
+ <a href="http://rubyforge.org/projects/kagemusha" class="numbers">0.0.3</a>
37
37
  </div>
38
38
  <h2>What</h2>
39
39
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
3
3
  specification_version: 1
4
4
  name: kagemusha
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.2
7
- date: 2007-08-27 00:00:00 +09:00
6
+ version: 0.0.3
7
+ date: 2007-09-11 00:00:00 +09:00
8
8
  summary: Kagemusha is a library of helper functions for testing Ruby scripts.
9
9
  require_paths:
10
10
  - lib