kagemusha 0.0.3 → 0.0.4

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.
@@ -0,0 +1 @@
1
+ @ruby script/txt2html %*
@@ -0,0 +1,34 @@
1
+ desc 'Release the website and new gem version'
2
+ task :deploy => [:check_version, :website, :release] do
3
+ puts "Remember to create SVN tag:"
4
+ puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
5
+ "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
6
+ puts "Suggested comment:"
7
+ puts "Tagging release #{CHANGES}"
8
+ end
9
+
10
+ desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
11
+ task :local_deploy => [:website_generate, :install_gem]
12
+
13
+ task :check_version do
14
+ unless ENV['VERSION']
15
+ puts 'Must pass a VERSION=x.y.z release version'
16
+ exit
17
+ end
18
+ unless ENV['VERSION'] == VERS
19
+ puts "Please update your version.rb to match the release version, currently #{VERS}"
20
+ exit
21
+ end
22
+ end
23
+
24
+ desc 'Install the package as a gem, without generating documentation(ri/rdoc)'
25
+ task :install_gem_no_doc => [:clean, :package] do
26
+ sh "#{'sudo ' unless Hoe::WINDOZE }gem install pkg/*.gem --no-rdoc --no-ri"
27
+ end
28
+
29
+ namespace :manifest do
30
+ desc 'Recreate Manifest.txt to include ALL files'
31
+ task :refresh do
32
+ `rake check_manifest | patch -p0 > Manifest.txt`
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ task :ruby_env do
2
+ RUBY_APP = if RUBY_PLATFORM =~ /java/
3
+ "jruby"
4
+ else
5
+ "ruby"
6
+ end unless defined? RUBY_APP
7
+ end
@@ -0,0 +1,17 @@
1
+ desc 'Generate website files'
2
+ task :website_generate => :ruby_env do
3
+ (Dir['website/**/*.txt'] - Dir['website/version*.txt']).each do |txt|
4
+ sh %{ #{RUBY_APP} script/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
5
+ end
6
+ end
7
+
8
+ desc 'Upload website files to rubyforge'
9
+ task :website_upload do
10
+ host = "#{rubyforge_username}@rubyforge.org"
11
+ remote_dir = "/var/www/gforge-projects/#{PATH}/"
12
+ local_dir = 'website'
13
+ sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
14
+ end
15
+
16
+ desc 'Generate and upload website files'
17
+ task :website => [:website_generate, :website_upload, :publish_docs]
data/test/test_bugs.rb ADDED
@@ -0,0 +1,93 @@
1
+
2
+ #==============================================================================#
3
+ # $Id: test_bugs.rb 52 2008-07-09 05:24:17Z yuyakato $
4
+ #==============================================================================#
5
+
6
+ require File.dirname(__FILE__) + "/test_helper.rb"
7
+
8
+ #==============================================================================#
9
+
10
+ class TestBugs < Test::Unit::TestCase
11
+ # MEMO:
12
+ # * rubyneko - KagemushaとActiveRecordの不具合
13
+ # http://ujihisa.nowa.jp/entry/6a4d5a6423
14
+ # * rubyneko - KagemushaとActiveRecordの不具合(2)
15
+ # http://ujihisa.nowa.jp/entry/c45f6db41e
16
+ # * Non free as in air - KagemushaとActiveRecordの不具合(2)
17
+ # http://www.kuwashima.org/niki/?date=20071116
18
+ # * KagemushaとActiveRecordの不具合の解消 - Hello, world! - s21g
19
+ # http://blog.s21g.com/articles/656
20
+ def test_report01
21
+ parent_c = Class.new
22
+ parent_m = class << parent_c; self; end
23
+ child_c = Class.new(parent_c)
24
+
25
+ parent_m.instance_eval { define_method(:target) { :original } }
26
+
27
+ musha = Kagemusha.new(child_c)
28
+ musha.defs(:target) { :replaced }
29
+
30
+ assert_equal(:original, child_c.target)
31
+
32
+ musha.swap {
33
+ assert_equal(:replaced, child_c.target)
34
+ }
35
+
36
+ # TypeError: singleton method bound for a different object
37
+ assert_nothing_raised {
38
+ assert_equal(:original, child_c.target)
39
+ }
40
+ end
41
+
42
+ def test_report01_failure_mechanism
43
+ parent_c = Class.new
44
+ parent_m = class << parent_c; self; end
45
+ child_c = Class.new(parent_c)
46
+ child_m = class << child_c; self; end
47
+
48
+ parent_m.instance_eval { define_method(:target) { :original } }
49
+
50
+ assert_equal(:original, child_c.target)
51
+
52
+ name = :target
53
+ new_method = proc { :replaced }
54
+ old_method = child_m.instance_method(name)
55
+ child_m.instance_eval { define_method(name, new_method) }
56
+
57
+ assert_equal(:replaced, child_c.target)
58
+
59
+ child_m.instance_eval { define_method(name, old_method) }
60
+
61
+ assert_raise(TypeError) {
62
+ child_c.target
63
+ }
64
+ end
65
+
66
+ def test_report01_correct_mechanism
67
+ parent_c = Class.new
68
+ parent_m = class << parent_c; self; end
69
+ child_c = Class.new(parent_c)
70
+ child_m = class << child_c; self; end
71
+
72
+ parent_m.instance_eval { define_method(:target) { :original } }
73
+
74
+ assert_equal(:original, child_c.target)
75
+
76
+ name = :target
77
+ new_method = proc { :replaced }
78
+ old_method = child_m.instance_method(name)
79
+
80
+ assert_equal(false, child_c.singleton_methods(false).include?(name.to_s))
81
+
82
+ child_m.instance_eval { define_method(name, new_method) }
83
+
84
+ assert_equal(:replaced, child_c.target)
85
+
86
+ child_m.instance_eval { remove_method(name) }
87
+
88
+ assert_equal(:original, child_c.target)
89
+ end
90
+ end
91
+
92
+ #==============================================================================#
93
+ #==============================================================================#
@@ -0,0 +1,308 @@
1
+
2
+ #==============================================================================#
3
+ # $Id: test_complex_cases.rb 60 2008-07-09 08:15:02Z yuyakato $
4
+ #==============================================================================#
5
+
6
+ require File.dirname(__FILE__) + "/test_helper.rb"
7
+
8
+ #==============================================================================#
9
+
10
+ class TestComplexCases < Test::Unit::TestCase
11
+ module M1
12
+ def m1_instance
13
+ return :m1_instance
14
+ end
15
+ end
16
+
17
+ module M2
18
+ def m2_class
19
+ return :m2_class
20
+ end
21
+ end
22
+
23
+ class C1
24
+ include M1
25
+ extend M2
26
+
27
+ def self.c1_class
28
+ return :c1_class
29
+ end
30
+
31
+ def c1_instance
32
+ return :c1_instance
33
+ end
34
+ end
35
+
36
+ class C2 < C1
37
+ end
38
+
39
+ class C3 < C1
40
+ end
41
+
42
+ def test_replace_instance_method_defined_on_self_class
43
+ c1 = C1.new
44
+ c2 = C2.new
45
+ c3 = C3.new
46
+
47
+ old_value = :c1_instance
48
+ new_value = :c1_instance_replaced1
49
+
50
+ musha = Kagemusha.new(C1)
51
+ musha.def(:c1_instance) { new_value }
52
+
53
+ assert_equal(old_value, c1.c1_instance)
54
+ assert_equal(old_value, c2.c1_instance)
55
+ assert_equal(old_value, c3.c1_instance)
56
+
57
+ musha.swap {
58
+ assert_equal(new_value, c1.c1_instance)
59
+ assert_equal(new_value, c2.c1_instance)
60
+ assert_equal(new_value, c3.c1_instance)
61
+ }
62
+
63
+ assert_equal(old_value, c1.c1_instance)
64
+ assert_equal(old_value, c2.c1_instance)
65
+ assert_equal(old_value, c3.c1_instance)
66
+
67
+ def c1.c1_instance
68
+ return :singleton
69
+ end
70
+
71
+ assert_equal(:singleton, c1.c1_instance)
72
+ assert_equal(old_value, c2.c1_instance)
73
+ assert_equal(old_value, c3.c1_instance)
74
+
75
+ musha.swap {
76
+ assert_equal(:singleton, c1.c1_instance)
77
+ assert_equal(new_value, c2.c1_instance)
78
+ assert_equal(new_value, c3.c1_instance)
79
+ }
80
+
81
+ assert_equal(:singleton, c1.c1_instance)
82
+ assert_equal(old_value, c2.c1_instance)
83
+ assert_equal(old_value, c3.c1_instance)
84
+ end
85
+
86
+ def test_replace_class_method_defined_on_self_class
87
+ old_value = :c1_class
88
+ new_value = :c1_class_replaced1
89
+
90
+ musha = Kagemusha.new(C1)
91
+ musha.defs(:c1_class) { new_value }
92
+
93
+ assert_equal(old_value, C1.c1_class)
94
+ assert_equal(old_value, C2.c1_class)
95
+ assert_equal(old_value, C3.c1_class)
96
+
97
+ musha.swap {
98
+ assert_equal(new_value, C1.c1_class)
99
+ assert_equal(new_value, C2.c1_class)
100
+ assert_equal(new_value, C3.c1_class)
101
+ }
102
+
103
+ assert_equal(old_value, C1.c1_class)
104
+ assert_equal(old_value, C2.c1_class) # FIXME: TypeError: singleton method bound for a different object
105
+ assert_equal(old_value, C3.c1_class) # FIXME: TypeError: singleton method bound for a different object
106
+ end
107
+
108
+ def test_replace_instance_method_defined_on_parent_class
109
+ c1 = C1.new
110
+ c2 = C2.new
111
+ c3 = C3.new
112
+
113
+ old_value = :c1_instance
114
+ new_value = :c1_instance_replaced2
115
+
116
+ musha = Kagemusha.new(C2)
117
+ musha.def(:c1_instance) { new_value }
118
+
119
+ assert_equal(old_value, c1.c1_instance)
120
+ assert_equal(old_value, c2.c1_instance)
121
+ assert_equal(old_value, c3.c1_instance)
122
+
123
+ musha.swap {
124
+ assert_equal(old_value, c1.c1_instance)
125
+ assert_equal(new_value, c2.c1_instance)
126
+ assert_equal(old_value, c3.c1_instance)
127
+ }
128
+
129
+ assert_equal(old_value, c1.c1_instance)
130
+ assert_equal(old_value, c2.c1_instance)
131
+ assert_equal(old_value, c3.c1_instance)
132
+
133
+ def c2.c1_instance
134
+ return :singleton
135
+ end
136
+
137
+ assert_equal(old_value, c1.c1_instance)
138
+ assert_equal(:singleton, c2.c1_instance)
139
+ assert_equal(old_value, c3.c1_instance)
140
+
141
+ musha.swap {
142
+ assert_equal(old_value, c1.c1_instance)
143
+ assert_equal(:singleton, c2.c1_instance)
144
+ assert_equal(old_value, c3.c1_instance)
145
+ }
146
+
147
+ assert_equal(old_value, c1.c1_instance)
148
+ assert_equal(:singleton, c2.c1_instance)
149
+ assert_equal(old_value, c3.c1_instance)
150
+ end
151
+
152
+ def test_replace_class_method_defined_on_parent_class
153
+ old_value = :c1_class
154
+ new_value = :c1_class_replaced2
155
+
156
+ musha = Kagemusha.new(C2)
157
+ musha.defs(:c1_class) { new_value }
158
+
159
+ assert_equal(old_value, C1.c1_class)
160
+ assert_equal(old_value, C2.c1_class)
161
+ assert_equal(old_value, C3.c1_class)
162
+
163
+ musha.swap {
164
+ assert_equal(old_value, C1.c1_class)
165
+ assert_equal(new_value, C2.c1_class)
166
+ assert_equal(old_value, C3.c1_class)
167
+ }
168
+
169
+ assert_equal(old_value, C1.c1_class)
170
+ assert_equal(old_value, C2.c1_class)
171
+ assert_equal(old_value, C3.c1_class)
172
+ end
173
+
174
+ def test_replace_instance_method_defined_on_self_class_including_module
175
+ c1 = C1.new
176
+ c2 = C2.new
177
+ c3 = C3.new
178
+
179
+ old_value = :m1_instance
180
+ new_value = :m1_instance_replaced1
181
+
182
+ musha = Kagemusha.new(C1)
183
+ musha.def(:m1_instance) { new_value }
184
+
185
+ assert_equal(old_value, c1.m1_instance)
186
+ assert_equal(old_value, c2.m1_instance)
187
+ assert_equal(old_value, c3.m1_instance)
188
+
189
+ musha.swap {
190
+ assert_equal(new_value, c1.m1_instance)
191
+ assert_equal(new_value, c2.m1_instance)
192
+ assert_equal(new_value, c3.m1_instance)
193
+ }
194
+
195
+ assert_equal(old_value, c1.m1_instance)
196
+ assert_equal(old_value, c2.m1_instance)
197
+ assert_equal(old_value, c3.m1_instance)
198
+
199
+ def c1.m1_instance
200
+ return :singleton
201
+ end
202
+
203
+ assert_equal(:singleton, c1.m1_instance)
204
+ assert_equal(old_value, c2.m1_instance)
205
+ assert_equal(old_value, c3.m1_instance)
206
+
207
+ musha.swap {
208
+ assert_equal(:singleton, c1.m1_instance)
209
+ assert_equal(new_value, c2.m1_instance)
210
+ assert_equal(new_value, c3.m1_instance)
211
+ }
212
+
213
+ assert_equal(:singleton, c1.m1_instance)
214
+ assert_equal(old_value, c2.m1_instance)
215
+ assert_equal(old_value, c3.m1_instance)
216
+ end
217
+
218
+ def test_replace_class_method_defined_on_self_class_extending_module
219
+ old_value = :m2_class
220
+ new_value = :m2_class_replaced1
221
+
222
+ musha = Kagemusha.new(C1)
223
+ musha.defs(:m2_class) { new_value }
224
+
225
+ assert_equal(old_value, C1.m2_class)
226
+ assert_equal(old_value, C2.m2_class)
227
+ assert_equal(old_value, C3.m2_class)
228
+
229
+ musha.swap {
230
+ assert_equal(new_value, C1.m2_class)
231
+ assert_equal(new_value, C2.m2_class)
232
+ assert_equal(new_value, C3.m2_class)
233
+ }
234
+
235
+ assert_equal(old_value, C1.m2_class)
236
+ assert_equal(old_value, C2.m2_class)
237
+ assert_equal(old_value, C3.m2_class)
238
+ end
239
+
240
+ def test_replace_instance_method_defined_on_parent_class_including_module
241
+ c1 = C1.new
242
+ c2 = C2.new
243
+ c3 = C3.new
244
+
245
+ old_value = :m1_instance
246
+ new_value = :m1_instance_replaced2
247
+
248
+ musha = Kagemusha.new(C2)
249
+ musha.def(:m1_instance) { new_value }
250
+
251
+ assert_equal(old_value, c1.m1_instance)
252
+ assert_equal(old_value, c2.m1_instance)
253
+ assert_equal(old_value, c3.m1_instance)
254
+
255
+ musha.swap {
256
+ assert_equal(old_value, c1.m1_instance)
257
+ assert_equal(new_value, c2.m1_instance)
258
+ assert_equal(old_value, c3.m1_instance)
259
+ }
260
+
261
+ assert_equal(old_value, c1.m1_instance)
262
+ assert_equal(old_value, c2.m1_instance)
263
+ assert_equal(old_value, c3.m1_instance)
264
+
265
+ def c2.m1_instance
266
+ return :singleton
267
+ end
268
+
269
+ assert_equal(old_value, c1.m1_instance)
270
+ assert_equal(:singleton, c2.m1_instance)
271
+ assert_equal(old_value, c3.m1_instance)
272
+
273
+ musha.swap {
274
+ assert_equal(old_value, c1.m1_instance)
275
+ assert_equal(:singleton, c2.m1_instance)
276
+ assert_equal(old_value, c3.m1_instance)
277
+ }
278
+
279
+ assert_equal(old_value, c1.m1_instance)
280
+ assert_equal(:singleton, c2.m1_instance)
281
+ assert_equal(old_value, c3.m1_instance)
282
+ end
283
+
284
+ def test_replace_class_method_defined_on_parent_class_extending_module
285
+ old_value = :m2_class
286
+ new_value = :m2_class_replaced2
287
+
288
+ musha = Kagemusha.new(C2)
289
+ musha.defs(:m2_class) { new_value }
290
+
291
+ assert_equal(old_value, C1.m2_class)
292
+ assert_equal(old_value, C2.m2_class)
293
+ assert_equal(old_value, C3.m2_class)
294
+
295
+ musha.swap {
296
+ assert_equal(old_value, C1.m2_class)
297
+ assert_equal(new_value, C2.m2_class)
298
+ assert_equal(old_value, C3.m2_class)
299
+ }
300
+
301
+ assert_equal(old_value, C1.m2_class)
302
+ assert_equal(old_value, C2.m2_class)
303
+ assert_equal(old_value, C3.m2_class)
304
+ end
305
+ end
306
+
307
+ #==============================================================================#
308
+ #==============================================================================#
data/website/index.html CHANGED
@@ -33,36 +33,37 @@
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.3</a>
36
+ <a href="http://rubyforge.org/projects/kagemusha" class="numbers">0.0.4</a>
37
37
  </div>
38
- <h2>What</h2>
39
-
40
-
41
- <p>Kagemusha is a library of helper functions for testing Ruby scripts.
42
- It helps you generating scoped mock-objects which overrides behavior of the class restricted in given blocks, without tainting a global area.</p>
43
-
44
-
45
- <h2>Installing</h2>
46
-
47
-
48
- <pre syntax="ruby"># gem install kagemusha</pre>
49
-
50
- <h2>The basics</h2>
51
-
52
-
53
- <h2>Demonstration of usage</h2>
54
-
55
-
56
- <h2>License</h2>
57
-
58
-
59
- <p>This code is free to use under the terms of Ruby&#8217;s license.</p>
60
-
61
-
62
- <h2>Contact</h2>
63
-
64
-
65
- <p>Comments are welcome.
38
+ <h2>What</h2>
39
+
40
+
41
+ <p>Kagemusha is a library of helper functions for testing Ruby scripts.
42
+ It helps you generating scoped mock-objects which overrides behavior of the class restricted in given blocks, without tainting a global area.</p>
43
+
44
+
45
+ <h2>Installing</h2>
46
+
47
+
48
+ <p><pre class='syntax'><span class="comment"># gem install kagemusha</span></pre></p>
49
+
50
+
51
+ <h2>The basics</h2>
52
+
53
+
54
+ <h2>Demonstration of usage</h2>
55
+
56
+
57
+ <h2>License</h2>
58
+
59
+
60
+ <p>This code is free to use under the terms of Ruby&#8217;s license.</p>
61
+
62
+
63
+ <h2>Contact</h2>
64
+
65
+
66
+ <p>Comments are welcome.
66
67
  Send an email to yuyakato at gmail dot com.</p>
67
68
  </div>
68
69
 
@@ -1,44 +1,44 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
- <head>
5
- <link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
6
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
- <title>
8
- <%= title %>
9
- </title>
10
- <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
11
- <style>
12
-
13
- </style>
14
- <script type="text/javascript">
15
- window.onload = function() {
16
- settings = {
17
- tl: { radius: 10 },
18
- tr: { radius: 10 },
19
- bl: { radius: 10 },
20
- br: { radius: 10 },
21
- antiAlias: true,
22
- autoPad: true,
23
- validTags: ["div"]
24
- }
25
- var versionBox = new curvyCorners(settings, document.getElementById("version"));
26
- versionBox.applyCornersToAll();
27
- }
28
- </script>
29
- </head>
30
- <body>
31
- <div id="main">
32
-
33
- <h1><%= title %></h1>
34
- <div id="version" class="clickable" onclick='document.location = "<%= download %>"; return false'>
35
- <p>Get Version</p>
36
- <a href="<%= download %>" class="numbers"><%= version %></a>
37
- </div>
38
- <%= body %>
39
- </div>
40
-
41
- <!-- insert site tracking codes here, like Google Urchin -->
42
-
43
- </body>
44
- </html>
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <link rel="stylesheet" href="stylesheets/screen.css" type="text/css" media="screen" />
6
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
+ <title>
8
+ <%= title %>
9
+ </title>
10
+ <script src="javascripts/rounded_corners_lite.inc.js" type="text/javascript"></script>
11
+ <style>
12
+
13
+ </style>
14
+ <script type="text/javascript">
15
+ window.onload = function() {
16
+ settings = {
17
+ tl: { radius: 10 },
18
+ tr: { radius: 10 },
19
+ bl: { radius: 10 },
20
+ br: { radius: 10 },
21
+ antiAlias: true,
22
+ autoPad: true,
23
+ validTags: ["div"]
24
+ }
25
+ var versionBox = new curvyCorners(settings, document.getElementById("version"));
26
+ versionBox.applyCornersToAll();
27
+ }
28
+ </script>
29
+ </head>
30
+ <body>
31
+ <div id="main">
32
+
33
+ <h1><%= title %></h1>
34
+ <div id="version" class="clickable" onclick='document.location = "<%= download %>"; return false'>
35
+ <p>Get Version</p>
36
+ <a href="<%= download %>" class="numbers"><%= version %></a>
37
+ </div>
38
+ <%= body %>
39
+ </div>
40
+
41
+ <!-- insert site tracking codes here, like Google Urchin -->
42
+
43
+ </body>
44
+ </html>