rcapture 1.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,38 @@
1
+ #
2
+ # (c) Christoph Heindl, 2010
3
+ # http://cheind.wordpress.com
4
+ #
5
+
6
+ require 'test/unit'
7
+ require 'test/unit/testee'
8
+
9
+ class TestReturnValue < Test::Unit::TestCase
10
+
11
+ def test_correct_return
12
+ t = Testee.new
13
+ t.capture_pre :methods => :x do
14
+ end
15
+ t.capture_post :methods => :x do
16
+ end
17
+
18
+ assert_equal(:x, t.x)
19
+ end
20
+
21
+ def test_modify_return
22
+ t = Testee.new
23
+ t.capture_post :methods => :y do |ci|
24
+ ci.return = :yy
25
+ end
26
+ assert_equal(:yy, t.y)
27
+ end
28
+
29
+ def test_modify_argument
30
+ t = Testee.new
31
+ t.capture_pre :methods => :y= do |ci|
32
+ ci.a[0] = :yyy
33
+ end
34
+
35
+ t.y = :abc
36
+ assert_equal(:yyy, t.y)
37
+ end
38
+ end
@@ -0,0 +1,40 @@
1
+ #
2
+ # (c) Christoph Heindl, 2010
3
+ # http://cheind.wordpress.com
4
+ #
5
+
6
+ require 'test/unit'
7
+
8
+ require 'test/unit/testee'
9
+
10
+
11
+ class TestSelfInterception < Test::Unit::TestCase
12
+
13
+ def test_self_intercept
14
+ count_class = 0
15
+ Testee.capture :class_methods => [:capture, :capture_pre, :capture_post] do
16
+ count_class += 1
17
+ end
18
+
19
+ t = Testee.new
20
+ count_obj = 0
21
+ t.capture :methods => [:capture, :capture_pre, :capture_post] do
22
+ count_obj += 1
23
+ end
24
+
25
+
26
+ assert_equal(0, count_class)
27
+ assert_equal(0, count_obj)
28
+
29
+ Testee.capture :methods => :x do
30
+ end
31
+
32
+ t.capture :methods => :x do
33
+ end
34
+ t.capture_pre :methods => :y= do
35
+ end
36
+
37
+ assert_equal(1, count_class)
38
+ assert_equal(2, count_obj)
39
+ end
40
+ end
@@ -0,0 +1,37 @@
1
+ #
2
+ # (c) Christoph Heindl, 2010
3
+ # http://cheind.wordpress.com
4
+ #
5
+
6
+ require 'test/unit'
7
+
8
+ require 'rcapture'
9
+
10
+ class Array
11
+ include RCapture::Interceptable
12
+ end
13
+
14
+ class TestSingletonVsClass < Test::Unit::TestCase
15
+
16
+ def test_singleton_class
17
+ count = 0
18
+ ccount = 0
19
+ Array.capture :methods => :<< do
20
+ count += 1
21
+ end
22
+
23
+ x = []
24
+ x.capture :methods => :<< do
25
+ ccount += 1
26
+ end
27
+
28
+ x << 1
29
+ assert_equal(1, count)
30
+ assert_equal(1, ccount)
31
+
32
+ y = []
33
+ y << 2
34
+ assert_equal(2, count)
35
+ assert_equal(1, ccount)
36
+ end
37
+ end
@@ -0,0 +1,69 @@
1
+ #
2
+ # (c) Christoph Heindl, 2010
3
+ # http://cheind.wordpress.com
4
+ #
5
+
6
+ require 'test/unit'
7
+
8
+ require 'test/unit/testee'
9
+ require 'thread'
10
+
11
+ class TestThreading < Test::Unit::TestCase
12
+
13
+ def spawn_thread(nr)
14
+ Thread.new do
15
+ t = Testee.new
16
+ nr.times do
17
+ t.x
18
+ end
19
+ end
20
+ end
21
+
22
+ def test_multiple_threads
23
+ count = 0
24
+ m = Mutex.new
25
+
26
+ Testee.capture :methods => :x do
27
+ m.synchronize do # ouch! that mutex will slow down everything radically
28
+ count += 1
29
+ end
30
+ end
31
+
32
+ threads = []
33
+ 5.times do
34
+ threads << spawn_thread(10000)
35
+ end
36
+ threads.each do |t|
37
+ t.join
38
+ end
39
+
40
+ assert_equal(count, 10000 * 5)
41
+ end
42
+
43
+ def test_status_multiple_threads
44
+
45
+ threads = []
46
+ count = 0
47
+ m = Mutex.new
48
+ RCapture::Internal.capture_post(Fixnum, :methods => :+) do
49
+ m.synchronize do
50
+ count = count + 1 # notice that op + has been captured
51
+ end
52
+ end
53
+
54
+ 5.times do
55
+ threads << Thread.new do
56
+ 10000.times do
57
+ x = 1+1
58
+ end
59
+ end
60
+ end
61
+
62
+ threads.each do |t|
63
+ t.join
64
+ end
65
+
66
+ assert_equal(10000*5, count)
67
+ end
68
+
69
+ end
@@ -0,0 +1,29 @@
1
+ #
2
+ # (c) Christoph Heindl, 2010
3
+ # http://cheind.wordpress.com
4
+ #
5
+
6
+ require 'test/unit'
7
+
8
+ require 'test/unit/testee'
9
+
10
+ class TestVisibility < Test::Unit::TestCase
11
+
12
+ def test_public
13
+ t = Testee.new
14
+ t.capture :methods => :x do
15
+ end
16
+ sym = "x"
17
+ sym = :x if RUBY_VERSION >= "1.9"
18
+ assert(RCapture::Internal.singleton_class(t).public_instance_methods.include?(sym))
19
+ end
20
+
21
+ def test_private
22
+ t = Testee.new
23
+ t.capture :methods => :prv do
24
+ end
25
+ sym = "prv"
26
+ sym = :prv if RUBY_VERSION >= "1.9"
27
+ assert(RCapture::Internal.singleton_class(t).private_instance_methods.include?(sym))
28
+ end
29
+ end
@@ -0,0 +1,27 @@
1
+ #
2
+ # (c) Christoph Heindl, 2010
3
+ # http://cheind.wordpress.com
4
+ #
5
+
6
+ require 'rcapture'
7
+
8
+ class Testee
9
+ include RCapture::Interceptable
10
+
11
+ attr_reader :x
12
+ attr_accessor :y
13
+
14
+ def initialize
15
+ @x = :x; @y = :y
16
+ end
17
+
18
+ def Testee.z
19
+ :z
20
+ end
21
+
22
+ private
23
+
24
+ def prv
25
+ end
26
+ end
27
+
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rcapture
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Christoph Heindl
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-01-07 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: RCapture allows placing hooks on methods using a convenient interface. RCapture allows pre and post invocation capturing as well as modifying input and return arguments. RCapture can thus be used as a building block in aspect oriented programming.
17
+ email: christoph.heindl@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ - License
25
+ files:
26
+ - rcapture.rb
27
+ - License
28
+ - README
29
+ - Rakefile
30
+ - rcapture/capture.rb
31
+ - rcapture/captured_info.rb
32
+ - rcapture/capture_18x.rb
33
+ - rcapture/capture_19x.rb
34
+ - rcapture/capture_status.rb
35
+ - rcapture/interceptable.rb
36
+ - rcapture/module_doc.rb
37
+ - rcapture/singleton_class.rb
38
+ - rcapture/symbol.rb
39
+ - test/acceptance/acc_array.rb
40
+ - test/acceptance/acc_inheritance.rb
41
+ - test/acceptance/acc_modify_arguments.rb
42
+ - test/acceptance/acc_new_with_block.rb
43
+ - test/acceptance/acc_policies.rb
44
+ - test/benchmark/benchmark_capture.rb
45
+ - test/unit/testee.rb
46
+ - test/unit/test_captured_info.rb
47
+ - test/unit/test_capture_status.rb
48
+ - test/unit/test_method_with_blocks.rb
49
+ - test/unit/test_modify_arguments.rb
50
+ - test/unit/test_return_value.rb
51
+ - test/unit/test_self_capture.rb
52
+ - test/unit/test_singleton_vs_class.rb
53
+ - test/unit/test_thread.rb
54
+ - test/unit/test_visibility.rb
55
+ - example/class_methods.rb
56
+ - example/filter_method_calls.rb
57
+ - example/hello_world.rb
58
+ - example/inheritance.rb
59
+ - example/modify_arguments.rb
60
+ - example/multithreaded.rb
61
+ - example/new_with_block.rb
62
+ - example/no_endless_recursion.rb
63
+ has_rdoc: true
64
+ homepage: http://rcapture.googlecode.com
65
+ licenses: []
66
+
67
+ post_install_message:
68
+ rdoc_options:
69
+ - --title
70
+ - RCapture -- Capturing Method Calls
71
+ - --main
72
+ - README
73
+ - -x
74
+ - test/*
75
+ - -x
76
+ - example/*
77
+ require_paths:
78
+ - .
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: "0"
90
+ version:
91
+ requirements: []
92
+
93
+ rubyforge_project:
94
+ rubygems_version: 1.3.5
95
+ signing_key:
96
+ specification_version: 3
97
+ summary: Capture and modify method invocations.
98
+ test_files:
99
+ - test/unit/testee.rb
100
+ - test/unit/test_captured_info.rb
101
+ - test/unit/test_capture_status.rb
102
+ - test/unit/test_method_with_blocks.rb
103
+ - test/unit/test_modify_arguments.rb
104
+ - test/unit/test_return_value.rb
105
+ - test/unit/test_self_capture.rb
106
+ - test/unit/test_singleton_vs_class.rb
107
+ - test/unit/test_thread.rb
108
+ - test/unit/test_visibility.rb