kagemusha 0.0.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/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 2007-08-15
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/License.txt ADDED
@@ -0,0 +1,54 @@
1
+
2
+ Kagemusha is copyrighted free software by Yuya Kato
3
+ <yuyakato at gmail dot com> You can redistribute it and/or modify it under
4
+ either the terms of the GPL or the conditions below:
5
+
6
+ 1. You may make and give away verbatim copies of the source form of the
7
+ software without restriction, provided that you duplicate all of the
8
+ original copyright notices and associated disclaimers.
9
+
10
+ 2. You may modify your copy of the software in any way, provided that
11
+ you do at least ONE of the following:
12
+
13
+ a) place your modifications in the Public Domain or otherwise make them
14
+ Freely Available, such as by posting said modifications to Usenet or an
15
+ equivalent medium, or by allowing the author to include your
16
+ modifications in the software.
17
+
18
+ b) use the modified software only within your corporation or
19
+ organization.
20
+
21
+ c) rename any non-standard executables so the names do not conflict with
22
+ standard executables, which must also be provided.
23
+
24
+ d) make other distribution arrangements with the author.
25
+
26
+ 3. You may distribute the software in object code or executable
27
+ form, provided that you do at least ONE of the following:
28
+
29
+ a) distribute the executables and library files of the software,
30
+ together with instructions (in the manual page or equivalent) on where
31
+ to get the original distribution.
32
+
33
+ b) accompany the distribution with the machine-readable source of the
34
+ software.
35
+
36
+ c) give non-standard executables non-standard names, with
37
+ instructions on where to get the original software distribution.
38
+
39
+ d) make other distribution arrangements with the author.
40
+
41
+ 4. You may modify and include the part of the software into any other
42
+ software (possibly commercial). But some files in the distribution
43
+ are not written by the author, so that they are not under this terms.
44
+
45
+ 5. The scripts and library files supplied as input to or produced as
46
+ output from the software do not automatically fall under the
47
+ copyright of the software, but belong to whomever generated them,
48
+ and may be sold commercially, and may be aggregated with this
49
+ software.
50
+
51
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
52
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
53
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
54
+ PURPOSE.
data/Manifest.txt ADDED
@@ -0,0 +1,31 @@
1
+ History.txt
2
+ License.txt
3
+ Manifest.txt
4
+ README.ja.txt
5
+ README.txt
6
+ Rakefile
7
+ examples/date.rb
8
+ examples/datetime.rb
9
+ examples/first.rb
10
+ examples/rand.rb
11
+ examples/time.rb
12
+ lib/kagemusha.rb
13
+ lib/kagemusha/core.rb
14
+ lib/kagemusha/date.rb
15
+ lib/kagemusha/datetime.rb
16
+ lib/kagemusha/rand.rb
17
+ lib/kagemusha/time.rb
18
+ lib/kagemusha/version.rb
19
+ scripts/txt2html
20
+ setup.rb
21
+ test/test_date.rb
22
+ test/test_datetime.rb
23
+ test/test_helper.rb
24
+ test/test_kagemusha.rb
25
+ test/test_rand.rb
26
+ test/test_time.rb
27
+ website/index.html
28
+ website/index.txt
29
+ website/javascripts/rounded_corners_lite.inc.js
30
+ website/stylesheets/screen.css
31
+ website/template.rhtml
data/README.ja.txt ADDED
@@ -0,0 +1,59 @@
1
+
2
+ 影武者 - テスト用モック作成支援ライブラリ
3
+ =========================================
4
+
5
+ これって何?
6
+ -----------
7
+
8
+ Rubyでテストコードを記述するための便利ライブラリです。
9
+
10
+ 例えば日付関係のテストを記述する際にはDate.todayなどの
11
+ 挙動を上書きするなどの手法がありますが、このやり方ですと
12
+ 無駄にグローバル領域を汚染してしまいます。
13
+
14
+ ブロックで指定された範囲内のみに限定して基本的なクラスの
15
+ 挙動を上書きするために、このライブラリを作りました。
16
+
17
+ 例:
18
+ require "kagemusha"
19
+
20
+ musha = Kagemusha.new(Time)
21
+ musha.defs(:now) { self.local(2000, 1, 1) }
22
+ musha.def(:to_s) { self.strftime("%Y-%m-%d") }
23
+
24
+ musha.swap {
25
+ p Time.now #=> Sat Jan 01 00:00:00 +0900 2000
26
+ p Time.now.to_s #=> "2000-01-01"
27
+ }
28
+
29
+ なお、よく使うと思われるDate、Time、randなどに対するモックを
30
+ いくつか標準で用意されています。
31
+
32
+ 例:
33
+ require "kagemusha/date"
34
+
35
+ musha = Kagemusha::Date.at(2000, 1, 1)
36
+ musha.swap {
37
+ p Date.today.to_s #=> "2000-01-01"
38
+ }
39
+
40
+
41
+ インストール
42
+ ------------
43
+
44
+ Gemでインストールしてください。
45
+
46
+ $ gem install kagemusha
47
+
48
+
49
+ 利用例
50
+ ------
51
+
52
+ exampleディレクトリを見てください。
53
+
54
+
55
+ サポート
56
+ --------
57
+
58
+ 何かありましたら下記までお願いします。
59
+ 加藤 勇也 (Yuya Kato) <yuyakato at gmail.com>
data/README.txt ADDED
@@ -0,0 +1,64 @@
1
+
2
+ Kagemusha - a library of testing mock-objects
3
+ =============================================
4
+
5
+ Welcome to Kagemusha
6
+ --------------------
7
+
8
+ Kagemusha is a library of helper functions
9
+ for testing Ruby scripts. It helps you generating
10
+ scoped mock-objects which overrides behavior of
11
+ the class restricted in given blocks, without
12
+ tainting a global area.
13
+
14
+ For example, if you override Date.today when you write
15
+ something about dates, then the code will taint global
16
+ areas to no purpose.
17
+
18
+ If you use Kagemusha, the test code will override
19
+ behavior of the class restricted in given block.
20
+
21
+ Example:
22
+ require "kagemusha"
23
+
24
+ musha = Kagemusha.new(Time)
25
+ musha.defs(:now) { self.local(2000, 1, 1) }
26
+ musha.def(:to_s) { self.strftime("%Y-%m-%d") }
27
+
28
+ musha.swap {
29
+ p Time.now #=> Sat Jan 01 00:00:00 +0900 2000
30
+ p Time.now.to_s #=> "2000-01-01"
31
+ }
32
+
33
+ Also, it has default useful mock-objects set Date, Time,
34
+ rand, and so on.
35
+
36
+ Example:
37
+ require "kagemusha/date"
38
+
39
+ musha = Kagemusha::Date.at(2000, 1, 1)
40
+ musha.swap {
41
+ p Date.today.to_s #=> "2000-01-01"
42
+ }
43
+
44
+
45
+ Installation
46
+ ------------
47
+
48
+ The easiest way to get started with Kagemusha is to
49
+ install it via RubyGems. You can do this easily:
50
+
51
+ $ gem install kagemusha
52
+
53
+
54
+ Examples
55
+ --------
56
+
57
+ see example directory.
58
+
59
+
60
+ Support
61
+ --------
62
+
63
+ Feel free to mail me:
64
+ Yuya Kato <yuyakato at gmail.com>
data/Rakefile ADDED
@@ -0,0 +1,123 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/rdoctask'
8
+ require 'rake/contrib/rubyforgepublisher'
9
+ require 'fileutils'
10
+ require 'hoe'
11
+
12
+ include FileUtils
13
+ require File.join(File.dirname(__FILE__), 'lib', 'kagemusha', 'version')
14
+
15
+ AUTHOR = "Yuya Kato" # can also be an array of Authors
16
+ EMAIL = "yuyakato at gmail.com"
17
+ DESCRIPTION = "Kagemusha is a library of helper functions for testing Ruby scripts."
18
+ GEM_NAME = "kagemusha" # what ppl will type to install your gem
19
+
20
+ @config_file = "~/.rubyforge/user-config.yml"
21
+ @config = nil
22
+ def rubyforge_username
23
+ unless @config
24
+ begin
25
+ @config = YAML.load(File.read(File.expand_path(@config_file)))
26
+ rescue
27
+ puts <<-EOS
28
+ ERROR: No rubyforge config file found: #{@config_file}"
29
+ Run 'rubyforge setup' to prepare your env for access to Rubyforge
30
+ - See http://newgem.rubyforge.org/rubyforge.html for more details
31
+ EOS
32
+ exit
33
+ end
34
+ end
35
+ @rubyforge_username ||= @config["username"]
36
+ end
37
+
38
+ RUBYFORGE_PROJECT = 'kagemusha' # The unix name for your project
39
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
40
+ DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
41
+
42
+ NAME = "kagemusha"
43
+ REV = nil
44
+ # UNCOMMENT IF REQUIRED:
45
+ # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
46
+ VERS = Kagemusha::VERSION::STRING + (REV ? ".#{REV}" : "")
47
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store']
48
+ RDOC_OPTS = ['--quiet', '--title', 'kagemusha documentation',
49
+ "--opname", "index.html",
50
+ "--line-numbers",
51
+ "--main", "README",
52
+ "--inline-source"]
53
+
54
+ class Hoe
55
+ def extra_deps
56
+ @extra_deps.reject { |x| Array(x).first == 'hoe' }
57
+ end
58
+ end
59
+
60
+ # Generate all the Rake tasks
61
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
62
+ hoe = Hoe.new(GEM_NAME, VERS) do |p|
63
+ p.author = AUTHOR
64
+ p.description = DESCRIPTION
65
+ p.email = EMAIL
66
+ p.summary = DESCRIPTION
67
+ p.url = HOMEPATH
68
+ p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
69
+ p.test_globs = ["test/**/test_*.rb"]
70
+ p.clean_globs |= CLEAN #An array of file patterns to delete on clean.
71
+
72
+ # == Optional
73
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
74
+ #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
75
+ #p.spec_extras = {} # A hash of extra values to set in the gemspec.
76
+ end
77
+
78
+ CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\n\n")
79
+ PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
80
+ hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
81
+
82
+ desc 'Generate website files'
83
+ task :website_generate do
84
+ Dir['website/**/*.txt'].each do |txt|
85
+ sh %{ ruby scripts/txt2html #{txt} > #{txt.gsub(/txt$/,'html')} }
86
+ end
87
+ end
88
+
89
+ desc 'Upload website files to rubyforge'
90
+ task :website_upload do
91
+ host = "#{rubyforge_username}@rubyforge.org"
92
+ remote_dir = "/var/www/gforge-projects/#{PATH}/"
93
+ local_dir = 'website'
94
+ sh %{rsync -aCv #{local_dir}/ #{host}:#{remote_dir}}
95
+ end
96
+
97
+ desc 'Generate and upload website files'
98
+ task :website => [:website_generate, :website_upload, :publish_docs]
99
+
100
+ desc 'Release the website and new gem version'
101
+ task :deploy => [:check_version, :website, :release] do
102
+ puts "Remember to create SVN tag:"
103
+ puts "svn copy svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/trunk " +
104
+ "svn+ssh://#{rubyforge_username}@rubyforge.org/var/svn/#{PATH}/tags/REL-#{VERS} "
105
+ puts "Suggested comment:"
106
+ puts "Tagging release #{CHANGES}"
107
+ end
108
+
109
+ desc 'Runs tasks website_generate and install_gem as a local deployment of the gem'
110
+ task :local_deploy => [:website_generate, :install_gem]
111
+
112
+ task :check_version do
113
+ unless ENV['VERSION']
114
+ puts 'Must pass a VERSION=x.y.z release version'
115
+ exit
116
+ end
117
+ unless ENV['VERSION'] == VERS
118
+ puts "Please update your version.rb to match the release version, currently #{VERS}"
119
+ exit
120
+ end
121
+ end
122
+
123
+
data/examples/date.rb ADDED
@@ -0,0 +1,19 @@
1
+
2
+ # $Id: date.rb 26 2007-08-15 14:22:25Z yuyakato $
3
+
4
+ require "rubygems"
5
+ require "kagemusha/date"
6
+
7
+ musha = Kagemusha::Date.on(2007, 1, 1)
8
+
9
+ p Date.today.strftime("%Y-%m-%d")
10
+
11
+ puts "---"
12
+
13
+ musha.swap {
14
+ p Date.today.strftime("%Y-%m-%d")
15
+ }
16
+
17
+ puts "---"
18
+
19
+ p Date.today.strftime("%Y-%m-%d")
@@ -0,0 +1,22 @@
1
+
2
+ # $Id: datetime.rb 26 2007-08-15 14:22:25Z yuyakato $
3
+
4
+ require "rubygems"
5
+ require "kagemusha/datetime"
6
+
7
+ musha = Kagemusha::DateTime.at(1984, 5, 11, 5, 15, 30)
8
+
9
+ p Date.today.strftime("%Y-%m-%d")
10
+ p Time.now
11
+
12
+ puts "---"
13
+
14
+ musha.swap {
15
+ p Date.today.strftime("%Y-%m-%d")
16
+ p Time.now
17
+ }
18
+
19
+ puts "---"
20
+
21
+ p Date.today.strftime("%Y-%m-%d")
22
+ p Time.now
data/examples/first.rb ADDED
@@ -0,0 +1,24 @@
1
+
2
+ # $Id: first.rb 25 2007-08-15 14:18:09Z yuyakato $
3
+
4
+ require "rubygems"
5
+ require "kagemusha"
6
+
7
+ musha = Kagemusha.new(Time)
8
+ musha.defs(:now) { self.local(1984, 5, 11) }
9
+ musha.def(:+) { |other| other }
10
+
11
+ p Time.now
12
+ p Time.now + 60 * 60 * 24
13
+
14
+ puts "---"
15
+
16
+ musha.swap {
17
+ p Time.now
18
+ p Time.now + 60 * 60 * 24
19
+ }
20
+
21
+ puts "---"
22
+
23
+ p Time.now
24
+ p Time.now + 60 * 60 * 24
data/examples/rand.rb ADDED
@@ -0,0 +1,22 @@
1
+
2
+ # $Id: rand.rb 26 2007-08-15 14:22:25Z yuyakato $
3
+
4
+ require "rubygems"
5
+ require "kagemusha/rand"
6
+
7
+ musha = Kagemusha::Rand.always(1)
8
+
9
+ p rand(5)
10
+ p rand(5)
11
+
12
+ puts "---"
13
+
14
+ musha.swap {
15
+ p rand(5)
16
+ p rand(5)
17
+ }
18
+
19
+ puts "---"
20
+
21
+ p rand(5)
22
+ p rand(5)
data/examples/time.rb ADDED
@@ -0,0 +1,19 @@
1
+
2
+ # $Id: time.rb 26 2007-08-15 14:22:25Z yuyakato $
3
+
4
+ require "rubygems"
5
+ require "kagemusha/time"
6
+
7
+ musha = Kagemusha::Time.at(2007, 1, 1)
8
+
9
+ p Time.now
10
+
11
+ puts "---"
12
+
13
+ musha.swap {
14
+ p Time.now
15
+ }
16
+
17
+ puts "---"
18
+
19
+ p Time.now