callbacks 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.
@@ -0,0 +1,55 @@
1
+ # $Id$
2
+
3
+ if HAVE_SPEC_RAKE_SPECTASK
4
+ require 'spec/rake/verify_rcov'
5
+
6
+ namespace :spec do
7
+
8
+ desc 'Run all specs with basic output'
9
+ Spec::Rake::SpecTask.new(:run) do |t|
10
+ t.ruby_opts = PROJ.ruby_opts
11
+ t.spec_opts = PROJ.spec.opts
12
+ t.spec_files = PROJ.spec.files
13
+ t.libs += PROJ.libs
14
+ end
15
+
16
+ desc 'Run all specs with text output'
17
+ Spec::Rake::SpecTask.new(:specdoc) do |t|
18
+ t.ruby_opts = PROJ.ruby_opts
19
+ t.spec_opts = PROJ.spec.opts + ['--format', 'specdoc']
20
+ t.spec_files = PROJ.spec.files
21
+ t.libs += PROJ.libs
22
+ end
23
+
24
+ if HAVE_RCOV
25
+ desc 'Run all specs with RCov'
26
+ Spec::Rake::SpecTask.new(:rcov) do |t|
27
+ t.ruby_opts = PROJ.ruby_opts
28
+ t.spec_opts = PROJ.spec.opts
29
+ t.spec_files = PROJ.spec.files
30
+ t.libs += PROJ.libs
31
+ t.rcov = true
32
+ t.rcov_dir = PROJ.rcov.dir
33
+ t.rcov_opts = PROJ.rcov.opts + ['--exclude', 'spec']
34
+ end
35
+
36
+ RCov::VerifyTask.new(:verify) do |t|
37
+ t.threshold = PROJ.rcov.threshold
38
+ t.index_html = File.join(PROJ.rcov.dir, 'index.html')
39
+ t.require_exact_threshold = PROJ.rcov.threshold_exact
40
+ end
41
+
42
+ task :verify => :rcov
43
+ remove_desc_for_task %w(spec:clobber_rcov)
44
+ end
45
+
46
+ end # namespace :spec
47
+
48
+ desc 'Alias to spec:run'
49
+ task :spec => 'spec:run'
50
+
51
+ task :clobber => 'spec:clobber_rcov' if HAVE_RCOV
52
+
53
+ end # if HAVE_SPEC_RAKE_SPECTASK
54
+
55
+ # EOF
@@ -0,0 +1,48 @@
1
+ # $Id$
2
+
3
+ if HAVE_SVN
4
+
5
+ unless PROJ.svn.root
6
+ info = %x/svn info ./
7
+ m = %r/^Repository Root:\s+(.*)$/.match(info)
8
+ PROJ.svn.root = (m.nil? ? '' : m[1])
9
+ end
10
+ PROJ.svn.root = File.join(PROJ.svn.root, PROJ.svn.path) unless PROJ.svn.path.empty?
11
+
12
+ namespace :svn do
13
+
14
+ # A prerequisites task that all other tasks depend upon
15
+ task :prereqs
16
+
17
+ desc 'Show tags from the SVN repository'
18
+ task :show_tags => 'svn:prereqs' do |t|
19
+ tags = %x/svn list #{File.join(PROJ.svn.root, PROJ.svn.tags)}/
20
+ tags.gsub!(%r/\/$/, '')
21
+ tags = tags.split("\n").sort {|a,b| b <=> a}
22
+ puts tags
23
+ end
24
+
25
+ desc 'Create a new tag in the SVN repository'
26
+ task :create_tag => 'svn:prereqs' do |t|
27
+ v = ENV['VERSION'] or abort 'Must supply VERSION=x.y.z'
28
+ abort "Versions don't match #{v} vs #{PROJ.version}" if v != PROJ.version
29
+
30
+ svn = PROJ.svn
31
+ trunk = File.join(svn.root, svn.trunk)
32
+ tag = "%s-%s" % [PROJ.name, PROJ.version]
33
+ tag = File.join(svn.root, svn.tags, tag)
34
+ msg = "Creating tag for #{PROJ.name} version #{PROJ.version}"
35
+
36
+ puts "Creating SVN tag '#{tag}'"
37
+ unless system "svn cp -m '#{msg}' #{trunk} #{tag}"
38
+ abort "Tag creation failed"
39
+ end
40
+ end
41
+
42
+ end # namespace :svn
43
+
44
+ task 'gem:release' => 'svn:create_tag'
45
+
46
+ end # if PROJ.svn.path
47
+
48
+ # EOF
@@ -0,0 +1,38 @@
1
+ # $Id$
2
+
3
+ require 'rake/testtask'
4
+
5
+ namespace :test do
6
+
7
+ Rake::TestTask.new(:run) do |t|
8
+ t.libs = PROJ.libs
9
+ t.test_files = if test(?f, PROJ.test.file) then [PROJ.test.file]
10
+ else PROJ.test.files end
11
+ t.ruby_opts += PROJ.ruby_opts
12
+ t.ruby_opts += PROJ.test.opts
13
+ end
14
+
15
+ if HAVE_RCOV
16
+ desc 'Run rcov on the unit tests'
17
+ task :rcov => :clobber_rcov do
18
+ opts = PROJ.rcov.opts.dup << '-o' << PROJ.rcov.dir
19
+ opts = opts.join(' ')
20
+ files = if test(?f, PROJ.test.file) then [PROJ.test.file]
21
+ else PROJ.test.files end
22
+ files = files.join(' ')
23
+ sh "#{RCOV} #{files} #{opts}"
24
+ end
25
+
26
+ task :clobber_rcov do
27
+ rm_r 'coverage' rescue nil
28
+ end
29
+ end
30
+
31
+ end # namespace :test
32
+
33
+ desc 'Alias to test:run'
34
+ task :test => 'test:run'
35
+
36
+ task :clobber => 'test:clobber_rcov' if HAVE_RCOV
37
+
38
+ # EOF
@@ -0,0 +1,16 @@
1
+ $: << '../lib'
2
+ $: << 'lib'
3
+ $: << 'test'
4
+ require 'tester_class.rb'
5
+
6
+ Tester.add_callback_methods :boot, :exit
7
+ Tester.before_boot do
8
+ p 'before boot'
9
+ end
10
+
11
+ Tester.after_boot 'p "after_boot"'
12
+
13
+ Tester.after_exit Proc.new {self.test}
14
+
15
+ t = Tester.new
16
+ p t.boot
@@ -0,0 +1,168 @@
1
+ class CallbacksTest < Test::Unit::TestCase
2
+
3
+ def setup
4
+ Object.send(:remove_const, :Tester) if defined? Tester
5
+ load 'test/tester_class.rb'
6
+ $tests_run = []
7
+ end
8
+
9
+ def test_class_should_return_values
10
+ t = Tester.new
11
+ assert_equal 'booting', t.boot
12
+ assert_equal 'exiting', t.exit
13
+ end
14
+
15
+ def test_should_create_methods_in_class
16
+ Tester.add_callback_methods :boot
17
+
18
+ assert_nothing_raised { Tester.new.boot }
19
+ assert_nothing_raised { Tester.new.boot_without_callbacks }
20
+ assert_nothing_raised { Tester.before_boot('p "ehlo"') }
21
+ assert_nothing_raised { Tester.after_boot('p "ehlo"') }
22
+ end
23
+
24
+ def test_remove_callback
25
+ Tester.add_callback_methods :boot, :exit
26
+ Tester.remove_callback_method :boot
27
+ Tester.remove_callback_method :exit
28
+
29
+ assert_equal [], Tester.callback_methods
30
+ assert_raise(NoMethodError) { Tester.before_boot }
31
+ assert_raise(NoMethodError) { Tester.after_boot }
32
+
33
+ end
34
+
35
+ def test_should_create_callback_methods_in_class
36
+ Tester.add_callback_methods :boot, :exit
37
+ assert_equal [:boot, :exit], Tester.callback_methods
38
+ end
39
+
40
+ def test_class_should_create_before_and_after_method
41
+ Tester.add_callback_methods :boot
42
+ methods = Tester.methods.grep(/(^before_.+$|^after_.+$)/)
43
+
44
+ assert methods.include?('before_boot')
45
+ assert methods.include?('after_boot')
46
+ end
47
+
48
+ def test_class_callbacks_should_run_callbacks
49
+ Tester.add_callback_methods :boot, :exit
50
+
51
+ Tester.before_boot do
52
+ $tests_run << 'before_boot'
53
+ end
54
+
55
+ Tester.after_exit do
56
+ $tests_run << 'after_exit'
57
+ end
58
+
59
+ t = Tester.new
60
+ assert_equal 'booting', t.boot
61
+ assert $tests_run.include?('before_boot')
62
+
63
+ assert_equal 'exiting', t.exit
64
+ assert $tests_run.include?('after_exit')
65
+ end
66
+
67
+ def test_class_callbacks_should_run_symbol
68
+ Tester.add_callback_methods :exit
69
+ Tester.before_exit :fill_globalvar_tests_run
70
+ t = Tester.new
71
+ t.exit
72
+
73
+ assert_equal 'fill_globalvar_tests_run', $tests_run.first
74
+ end
75
+
76
+ def test_class_callbacks_should_run_block_in_self
77
+ Tester.add_callback_methods :exit
78
+
79
+ Tester.before_exit do
80
+ $tests_run << self.boot
81
+ end
82
+
83
+ t = Tester.new
84
+ assert_equal 'exiting', t.exit
85
+
86
+ assert_equal 'booting', $tests_run.first
87
+ end
88
+
89
+ def test_class_callbacks_should_run_string
90
+ Tester.add_callback_methods :boot
91
+ Tester.after_boot '$tests_run << "after_test"'
92
+ t = Tester.new
93
+ t.boot
94
+
95
+ assert_equal 'after_test', $tests_run.first
96
+ end
97
+
98
+ def test_class_callbacks_should_run_method
99
+
100
+ end
101
+
102
+ def test_class_callbacks_should_raise_when_wrong_argument
103
+
104
+ end
105
+
106
+ def test_class_without_actions_should_not_give_exception
107
+ Tester.add_callback_methods :boot, :exit
108
+ t = Tester.new
109
+ assert_nothing_raised do
110
+ t.boot
111
+ end
112
+ end
113
+
114
+ def test_class_without_actions_should_return_original_retval
115
+ Tester.add_callback_methods :boot, :exit
116
+ t = Tester.new
117
+ assert_equal 'booting', t.boot
118
+ end
119
+
120
+ def test_callback_methods_of_two_classes_should_be_kept_seperate
121
+ tester_two_class = Tester.dup
122
+ tester_three_class = Tester.dup
123
+ Tester.add_callback_methods :exit
124
+ tester_two_class.add_callback_methods :boot
125
+
126
+ assert_equal [], tester_three_class.callback_methods
127
+ assert_equal [:exit], Tester.callback_methods
128
+ assert_equal [:boot], tester_two_class.callback_methods
129
+
130
+ end
131
+
132
+ def test_callback_actions_of_two_classes_should_be_kept_seperate
133
+ Tester.add_callback_methods :exit
134
+ tester_two_class = Tester.dup
135
+ tester_three_class = Tester.dup
136
+
137
+ tester_two_class.before_exit do
138
+ $tests_run << 'before_exit'
139
+ end
140
+
141
+ Tester.after_exit do
142
+ $tests_run << 'after_exit'
143
+ end
144
+
145
+ assert_equal({}, tester_three_class.callback_actions)
146
+
147
+ Tester.new.exit
148
+ assert_equal ['after_exit'], $tests_run
149
+
150
+ $tests_run = []
151
+
152
+ tester_two_class.new.exit
153
+ assert_equal ['before_exit'], $tests_run
154
+ end
155
+
156
+ # def test_callbacks_created_in_class_should_be_vissible_in_instance
157
+ # Tester.add_callback_methods :boot, :exit
158
+ # t = Tester.new
159
+ # assert_equal [:boot, :exit], t.callbacks
160
+ # end
161
+
162
+ # def test_callback_created_in_instance_should_not_be_vissible_in_class
163
+ # t = Tester.new
164
+ # t.add_callback :boot
165
+ # assert_equal [], Tester.callbacks
166
+ # end
167
+
168
+ end
@@ -0,0 +1,4 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+
4
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
@@ -0,0 +1,23 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
2
+ require 'callbacks'
3
+
4
+ class Tester
5
+
6
+ def boot
7
+ return "booting"
8
+ end
9
+
10
+ def exit
11
+ return "exiting"
12
+ end
13
+
14
+ def testing
15
+ return "testing"
16
+ end
17
+
18
+ def fill_globalvar_tests_run
19
+ $tests_run << 'fill_globalvar_tests_run'
20
+ end
21
+
22
+ include Callbacks
23
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: callbacks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Leon Bogaert
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-05-20 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: This package makes it simple to add callbacks a.k.a. "hooks" to ruby classes
17
+ email: leon@vanutsteen.nl
18
+ executables:
19
+ - callbacks
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - History.txt
24
+ - README.txt
25
+ - bin/callbacks
26
+ files:
27
+ - History.txt
28
+ - Manifest.txt
29
+ - README.txt
30
+ - Rakefile
31
+ - Version.txt
32
+ - bin/callbacks
33
+ - ext/metaid.rb
34
+ - lib/callback.rb
35
+ - lib/callbacks.rb
36
+ - lib/classmethods.rb
37
+ - lib/instancemethods.rb
38
+ - spec/callbacks_spec.rb
39
+ - spec/spec_helper.rb
40
+ - tasks/ann.rake
41
+ - tasks/bones.rake
42
+ - tasks/gem.rake
43
+ - tasks/manifest.rake
44
+ - tasks/notes.rake
45
+ - tasks/post_load.rake
46
+ - tasks/rdoc.rake
47
+ - tasks/rubyforge.rake
48
+ - tasks/setup.rb
49
+ - tasks/spec.rake
50
+ - tasks/svn.rake
51
+ - tasks/test.rake
52
+ - test/profile.rb
53
+ - test/test_callbacks.rb
54
+ - test/test_helper.rb
55
+ - test/tester_class.rb
56
+ has_rdoc: true
57
+ homepage: www.vanutsteen.nl
58
+ post_install_message:
59
+ rdoc_options:
60
+ - --main
61
+ - README.txt
62
+ require_paths:
63
+ - lib
64
+ - ext
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: "0"
70
+ version:
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: "0"
76
+ version:
77
+ requirements: []
78
+
79
+ rubyforge_project: callbacks
80
+ rubygems_version: 1.1.1
81
+ signing_key:
82
+ specification_version: 2
83
+ summary: This package makes it simple to add callbacks a
84
+ test_files:
85
+ - test/test_helper.rb
86
+ - test/test_callbacks.rb