ruby_ex 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +693 -0
- data/NEWS +74 -0
- data/SPEC.dyn.yml +6 -6
- data/SPEC.gemspec +14 -0
- data/SPEC.yml +4 -4
- data/lib/abstract.rb +2 -4
- data/lib/abstract_node.rb +1 -2
- data/lib/algorithms/simulated_annealing.rb +50 -29
- data/lib/attributed_class.rb +50 -21
- data/lib/auto_object.rb +102 -0
- data/lib/blank_slate.rb +102 -0
- data/lib/cache.rb +1 -2
- data/lib/choose.rb +165 -163
- data/lib/commands.rb +2 -3
- data/lib/commands/command.rb +47 -20
- data/lib/commands/datas.rb +1 -1
- data/lib/commands/datas/composite.rb +5 -1
- data/lib/commands/datas/data.rb +102 -5
- data/lib/commands/datas/factory.rb +13 -6
- data/lib/commands/datas/temp.rb +3 -5
- data/lib/commands/factory.rb +1 -1
- data/lib/commands/helpers.rb +1 -1
- data/lib/commands/pipe.rb +10 -1
- data/lib/commands/runners.rb +1 -1
- data/lib/commands/runners/exec.rb +1 -1
- data/lib/commands/runners/fork.rb +3 -16
- data/lib/commands/runners/mock.rb +67 -0
- data/lib/commands/runners/runner.rb +5 -3
- data/lib/commands/runners/system.rb +1 -1
- data/lib/commands/seq.rb +2 -1
- data/lib/config_file.rb +10 -2
- data/lib/const_regexp.rb +1 -2
- data/lib/{dlogger.rb → d_logger.rb} +1 -2
- data/lib/daemon.rb +1 -2
- data/lib/diff.rb +1 -2
- data/lib/drb/drb_observable.rb +1 -2
- data/lib/drb/drb_observable_pool.rb +2 -2
- data/lib/drb/drb_service.rb +1 -2
- data/lib/drb/drb_undumped_attributes.rb +1 -2
- data/lib/drb/drb_undumped_indexed_object.rb +1 -2
- data/lib/drb/insecure_protected_methods.rb +1 -2
- data/lib/drb_ex.rb +2 -2
- data/lib/file_type.rb +466 -0
- data/lib/generate_id.rb +12 -6
- data/lib/genpasswd.rb +22 -0
- data/lib/hash_eval.rb +83 -0
- data/lib/histogram.rb +1 -2
- data/lib/hookable.rb +3 -4
- data/lib/hooker.rb +1 -3
- data/lib/html_encode.rb +191 -0
- data/lib/indexed_node.rb +0 -1
- data/lib/io_marshal.rb +4 -2
- data/lib/ioo.rb +3 -2
- data/lib/kill_all.rb +46 -0
- data/lib/labeled_node.rb +0 -1
- data/lib/logger_observer.rb +8 -4
- data/lib/md5sum.rb +3 -3
- data/lib/meta_factory.rb +99 -0
- data/lib/method_call.rb +87 -0
- data/lib/mocks.rb +12 -0
- data/lib/mocks/assertions.rb +50 -0
- data/lib/mocks/method_logger.rb +40 -0
- data/lib/mocks/mock.rb +64 -0
- data/lib/mocks/object.rb +47 -0
- data/lib/mocks/observer.rb +38 -0
- data/lib/module/autoload_tree.rb +30 -29
- data/lib/module/hierarchy.rb +176 -171
- data/lib/module/instance_method_visibility.rb +39 -38
- data/lib/node.rb +0 -1
- data/lib/object_monitor.rb +1 -2
- data/lib/object_monitor_activity.rb +1 -2
- data/lib/observable.rb +1 -2
- data/lib/observable_pool.rb +1 -2
- data/lib/{orderedhash.rb → ordered_hash.rb} +41 -5
- data/lib/pp_hierarchy.rb +7 -2
- data/lib/r_path.rb +307 -0
- data/lib/random_generators.rb +7 -20
- data/lib/random_generators/random_generator.rb +2 -4
- data/lib/random_generators/ruby.rb +4 -2
- data/lib/regex_path.rb +124 -0
- data/lib/ruby_ex.rb +28 -98
- data/lib/safe_eval.rb +1 -2
- data/lib/sendmail.rb +14 -17
- data/lib/service_manager.rb +1 -2
- data/lib/shuffle.rb +6 -2
- data/lib/spring.rb +1 -2
- data/lib/spring_set.rb +1 -2
- data/lib/{symtbl.rb → sym_tbl.rb} +90 -5
- data/lib/sym_tbl_gsub.rb +227 -0
- data/lib/{synflow.rb → syn_flow.rb} +1 -2
- data/lib/text.rb +218 -0
- data/lib/timeout_ex.rb +1 -2
- data/lib/trace.rb +9 -8
- data/lib/uri/druby.rb +1 -2
- data/lib/uri/file.rb +1 -1
- data/lib/uri/ftp_ex.rb +1 -1
- data/lib/uri/http_ex.rb +1 -1
- data/lib/uri/mysql.rb +121 -0
- data/lib/uri/pgsql.rb +19 -38
- data/lib/uri/svn.rb +1 -2
- data/lib/uri_ex.rb +45 -3
- data/lib/verbose_object.rb +181 -38
- data/lib/yaml/chop_header.rb +19 -11
- data/lib/yaml/transform.rb +17 -11
- data/lib/yaml/yregexpath.rb +11 -5
- data/test/algorithms/simulated_annealing_test.rb +2 -2
- data/test/resources/foo.tar.gz +0 -0
- data/test/resources/tar.gz.log +49 -0
- data/test/sanity-suite.yml +5 -7
- data/test/sanity/multiple-requires.yml +17 -7
- data/test/sanity/single-requires.yml +38 -20
- data/test/stress-tests/threads_and_exceptions.yml +13 -0
- data/test/test-unit-setup.rb +3 -1
- data/test/unit-suite.yml +7 -8
- metadata +42 -31
- data/lib/algorithms.rb +0 -12
- data/lib/ask.rb +0 -100
- data/lib/checkout.rb +0 -12
- data/lib/dumpable_proc.rb +0 -57
- data/lib/filetype.rb +0 -229
- data/lib/thread_mutex.rb +0 -11
- data/lib/yaml/basenode_ext.rb +0 -63
data/lib/labeled_node.rb
CHANGED
data/lib/logger_observer.rb
CHANGED
@@ -3,14 +3,12 @@
|
|
3
3
|
# License: Gnu General Public License.
|
4
4
|
|
5
5
|
# $LastChangedBy: ertai $
|
6
|
-
# $Id: logger_observer.rb
|
6
|
+
# $Id: logger_observer.rb 339 2005-09-06 23:27:27Z ertai $
|
7
7
|
|
8
8
|
|
9
|
-
require 'ruby_ex'
|
10
9
|
require 'logger'
|
11
10
|
|
12
|
-
|
13
|
-
class Logger
|
11
|
+
module LoggerObserver
|
14
12
|
|
15
13
|
def update(*args, &block)
|
16
14
|
severity = UNKNOWN
|
@@ -20,5 +18,11 @@ class Logger
|
|
20
18
|
add(severity, "#{args.inspect} #{block.inspect if block}", $PROGRAME_NAME)
|
21
19
|
end
|
22
20
|
|
21
|
+
end # module LoggerObserver
|
22
|
+
|
23
|
+
class Logger
|
24
|
+
|
25
|
+
include LoggerObserver
|
26
|
+
|
23
27
|
end # class Logger
|
24
28
|
|
data/lib/md5sum.rb
CHANGED
@@ -3,12 +3,13 @@
|
|
3
3
|
# License: Gnu General Public License.
|
4
4
|
|
5
5
|
# $LastChangedBy: ertai $
|
6
|
-
# $Id: md5sum.rb
|
6
|
+
# $Id: md5sum.rb 339 2005-09-06 23:27:27Z ertai $
|
7
7
|
|
8
8
|
|
9
|
-
require 'ruby_ex'
|
10
9
|
require 'md5'
|
11
10
|
|
11
|
+
module Md5sum
|
12
|
+
end # module Md5sum
|
12
13
|
|
13
14
|
class File
|
14
15
|
|
@@ -44,7 +45,6 @@ end # class Pathname
|
|
44
45
|
test_section __FILE__ do
|
45
46
|
|
46
47
|
|
47
|
-
require 'ruby_ex'
|
48
48
|
|
49
49
|
|
50
50
|
class MD5SumTest < Test::Unit::TestCase
|
data/lib/meta_factory.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
2
|
+
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
3
|
+
# License:: Gnu General Public License.
|
4
|
+
# Revision:: $Id: meta_factory.rb 349 2005-09-12 07:59:21Z ertai $
|
5
|
+
|
6
|
+
|
7
|
+
class MetaFactory
|
8
|
+
|
9
|
+
def initialize ( aClass, *a, &b )
|
10
|
+
@record = nil
|
11
|
+
@class, @args, @block = aClass, a, b
|
12
|
+
end
|
13
|
+
|
14
|
+
def create ( prefix_args=[], postfix_args=[], &block )
|
15
|
+
args = prefix_args + @args + postfix_args
|
16
|
+
block = @block if block.nil?
|
17
|
+
anObject = @class.new(*args, &block)
|
18
|
+
@record[anObject] unless @record.nil?
|
19
|
+
anObject
|
20
|
+
end
|
21
|
+
|
22
|
+
alias_method :new, :create
|
23
|
+
|
24
|
+
# Record a block of actions which will be applied on the created object
|
25
|
+
#
|
26
|
+
# Example:
|
27
|
+
# factory = MetaFactory.new(MyClass, some, args, ...)
|
28
|
+
# factory.record do |o|
|
29
|
+
# o.foo = bar
|
30
|
+
# o.flou!
|
31
|
+
# ...
|
32
|
+
# end
|
33
|
+
# factory.create([some, args, to, prepend], [some, to append])
|
34
|
+
def record ( &block )
|
35
|
+
@record = block
|
36
|
+
end
|
37
|
+
|
38
|
+
end # class MetaFactory
|
39
|
+
|
40
|
+
|
41
|
+
|
42
|
+
test_section __FILE__ do
|
43
|
+
|
44
|
+
class TestMetaFactory < ::Test::Unit::TestCase
|
45
|
+
include Mocks::Assertions
|
46
|
+
|
47
|
+
module Mocks
|
48
|
+
class Class < ::Mocks::Object # FIXME ::Mocks:: const_missing issue
|
49
|
+
def initialize ( *a, &b )
|
50
|
+
super
|
51
|
+
@objects = []
|
52
|
+
end
|
53
|
+
def new ( *a, &b )
|
54
|
+
super
|
55
|
+
obj = ::Mocks::Object.new
|
56
|
+
@objects << obj
|
57
|
+
obj
|
58
|
+
end
|
59
|
+
end # class Class
|
60
|
+
end # module Mocks
|
61
|
+
|
62
|
+
def setup
|
63
|
+
@proc = Proc.new { 42 }
|
64
|
+
@proc2 = Proc.new { 43 }
|
65
|
+
@mock_class = Mocks::Class.new
|
66
|
+
self.mock_object = @mock_class
|
67
|
+
assert_nothing_raised { @factory = MetaFactory.new(@mock_class, 42, :foo => :bar, &@proc) }
|
68
|
+
assert_empty_mock
|
69
|
+
end
|
70
|
+
|
71
|
+
def teardown
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_create
|
75
|
+
10.times do
|
76
|
+
assert_nothing_raised { @instance = @factory.create }
|
77
|
+
assert_last_mock_call [:new, [42, {:foo=>:bar}], @proc]
|
78
|
+
end
|
79
|
+
assert_mock_size 10
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_create_with_args
|
83
|
+
assert_nothing_raised { @instance = @factory.create([43], [:boo]) }
|
84
|
+
assert_last_mock_call [:new, [43, 42, {:foo=>:bar}, :boo], @proc]
|
85
|
+
assert_nothing_raised { @instance = @factory.create([45], &@proc2) }
|
86
|
+
assert_last_mock_call [:new, [45, 42, {:foo=>:bar}], @proc2]
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_record
|
90
|
+
assert_nothing_raised { @factory.record { |o| o.foo(:bar, :qux) } }
|
91
|
+
assert_nothing_raised { @instance = @factory.create([43], [:boo]) }
|
92
|
+
assert_last_mock_call [:new, [43, 42, {:foo=>:bar}, :boo], @proc]
|
93
|
+
self.mock_object = @instance
|
94
|
+
assert_mock_calls [[:foo, [:bar, :qux]]]
|
95
|
+
end
|
96
|
+
|
97
|
+
end # class TestMetaFactory
|
98
|
+
|
99
|
+
end
|
data/lib/method_call.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
2
|
+
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
3
|
+
# License:: Gnu General Public License.
|
4
|
+
# Revision:: $Id: method_call.rb 339 2005-09-06 23:27:27Z ertai $
|
5
|
+
|
6
|
+
|
7
|
+
class MethodCall
|
8
|
+
attr_accessor :name, :args, :block
|
9
|
+
|
10
|
+
def initialize ( name, *args, &block )
|
11
|
+
@name, @args, @block = name, args, block
|
12
|
+
end
|
13
|
+
|
14
|
+
def recall ( anObject )
|
15
|
+
anObject.__send__(@name, *@args, &@block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_a
|
19
|
+
ary = [@name]
|
20
|
+
unless @args.empty? and @block.nil?
|
21
|
+
if @args.size == 1
|
22
|
+
ary << @args.first
|
23
|
+
else
|
24
|
+
ary << @args
|
25
|
+
end
|
26
|
+
end
|
27
|
+
ary << @block unless @block.nil?
|
28
|
+
ary
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_ruby ( caller )
|
32
|
+
case @name.to_s
|
33
|
+
when /^\w/
|
34
|
+
result = "#{caller}.#@name"
|
35
|
+
unless @args.empty?
|
36
|
+
args = @args.map { |arg| arg.inspect }.join(', ')
|
37
|
+
result += "(#{args})"
|
38
|
+
end
|
39
|
+
result += " { ... }" unless @block.nil?
|
40
|
+
result
|
41
|
+
when /([><=]=[>~=]?|[-+%^*\/&|])/
|
42
|
+
raise ArgumentError, "too many arguments" if @args.size != 1
|
43
|
+
"(#{caller} #@name #{@args.first.inspect})"
|
44
|
+
else raise ArgumentError, "unhandled method #@name"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end # class MethodCall
|
49
|
+
|
50
|
+
|
51
|
+
test_section __FILE__ do
|
52
|
+
|
53
|
+
class TestMethodCall < ::Test::Unit::TestCase
|
54
|
+
|
55
|
+
def setup
|
56
|
+
@proc = proc { 42 }
|
57
|
+
assert_nothing_raised do
|
58
|
+
@obj1 = MethodCall.new(:foo, 3, [4], &@proc)
|
59
|
+
@obj2 = MethodCall.new(:split, /:/)
|
60
|
+
@obj3 = MethodCall.new(:foo)
|
61
|
+
@obj4 = MethodCall.new(:foo, &@proc)
|
62
|
+
@obj5 = MethodCall.new(:foo, :bar)
|
63
|
+
@obj6 = MethodCall.new(:foo, 3, [4])
|
64
|
+
@obj7 = MethodCall.new(:foo, :bar, &@proc)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_init
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_recall
|
72
|
+
assert_equal(%w[a b c], @obj2.recall("a:b:c"))
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_to_a
|
76
|
+
assert_equal([:foo, [3, [4]], @proc], @obj1.to_a)
|
77
|
+
assert_equal([:split, /:/], @obj2.to_a)
|
78
|
+
assert_equal([:foo], @obj3.to_a)
|
79
|
+
assert_equal([:foo, [], @proc], @obj4.to_a)
|
80
|
+
assert_equal([:foo, :bar], @obj5.to_a)
|
81
|
+
assert_equal([:foo, [3, [4]]], @obj6.to_a)
|
82
|
+
assert_equal([:foo, :bar, @proc], @obj7.to_a)
|
83
|
+
end
|
84
|
+
|
85
|
+
end # class TestMethodCall
|
86
|
+
|
87
|
+
end
|
data/lib/mocks.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
2
|
+
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
3
|
+
# License:: GNU General Public License (GPL).
|
4
|
+
# Revision:: $Id: mocks.rb 344 2005-09-08 01:44:18Z ertai $
|
5
|
+
|
6
|
+
AutoloadTree.import!
|
7
|
+
|
8
|
+
module Mocks
|
9
|
+
|
10
|
+
autoloaded_module(__FILE__, false)
|
11
|
+
|
12
|
+
end # module Mocks
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
2
|
+
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
3
|
+
# License:: Gnu General Public License.
|
4
|
+
# Revision:: $Id: assertions.rb 339 2005-09-06 23:27:27Z ertai $
|
5
|
+
|
6
|
+
|
7
|
+
module Mocks
|
8
|
+
|
9
|
+
module Assertions
|
10
|
+
|
11
|
+
attr_accessor :mock_object
|
12
|
+
|
13
|
+
def assert_mock ( *ref )
|
14
|
+
if ref.size == 1 and (f = ref.first).is_a? Array and f.first.is_a? Array
|
15
|
+
ref = f
|
16
|
+
end
|
17
|
+
assert_equal(ref, mock_object.mock_args)
|
18
|
+
end
|
19
|
+
|
20
|
+
def assert_mock_calls ( ref, comment='' )
|
21
|
+
assert_equal(ref, mock_object.mock_calls_array, comment)
|
22
|
+
end
|
23
|
+
|
24
|
+
def assert_mock_args ( ref, comment='' )
|
25
|
+
assert_equal(ref, mock_object.mock_args, comment)
|
26
|
+
end
|
27
|
+
|
28
|
+
def assert_empty_mock ( comment='' )
|
29
|
+
assert_mock_calls [], (comment.empty?)? 'not empty' : comment
|
30
|
+
end
|
31
|
+
|
32
|
+
def assert_last_mock ( *ref )
|
33
|
+
assert_equal(ref, mock_object.mock_calls.last.args)
|
34
|
+
end
|
35
|
+
|
36
|
+
def assert_last_mock_args ( ref, comment='' )
|
37
|
+
assert_equal(ref, mock_object.mock_calls_array.last.args, comment)
|
38
|
+
end
|
39
|
+
|
40
|
+
def assert_last_mock_call ( ref, comment='' )
|
41
|
+
assert_equal(ref, mock_object.mock_calls_array.last, comment)
|
42
|
+
end
|
43
|
+
|
44
|
+
def assert_mock_size ( size, comment='' )
|
45
|
+
assert_equal(size, mock_object.mock_size, comment)
|
46
|
+
end
|
47
|
+
|
48
|
+
end # module Assertions
|
49
|
+
|
50
|
+
end # module Mocks
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
2
|
+
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
3
|
+
# License:: Gnu General Public License.
|
4
|
+
# Revision:: $Id: method_logger.rb 339 2005-09-06 23:27:27Z ertai $
|
5
|
+
|
6
|
+
require 'mocks'
|
7
|
+
|
8
|
+
module Mocks
|
9
|
+
|
10
|
+
class MethodLogger < Mock
|
11
|
+
concrete
|
12
|
+
|
13
|
+
def log ( *args, &block )
|
14
|
+
mock_add MethodCall.new(*args, &block)
|
15
|
+
end
|
16
|
+
|
17
|
+
end # class MethodLogger
|
18
|
+
|
19
|
+
test_section __FILE__ do
|
20
|
+
|
21
|
+
class TestMethodLogger < ::Test::Unit::TestCase
|
22
|
+
include Mocks::Assertions
|
23
|
+
|
24
|
+
def setup
|
25
|
+
@proc = proc { 43 }
|
26
|
+
@mock_object = Mocks::MethodLogger.new
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_simple
|
30
|
+
@mock_object.log(:foo, :bar, 42, &@proc)
|
31
|
+
@mock_object.log(:bar)
|
32
|
+
assert_mock_calls [[:foo, [:bar, 42], @proc], [:bar]]
|
33
|
+
assert_mock [:bar, 42], []
|
34
|
+
end
|
35
|
+
|
36
|
+
end # class TestMethodLogger
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end # module Mocks
|
data/lib/mocks/mock.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
2
|
+
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
3
|
+
# License:: Gnu General Public License.
|
4
|
+
# Revision:: $Id: mock.rb 344 2005-09-08 01:44:18Z ertai $
|
5
|
+
|
6
|
+
require 'mocks'
|
7
|
+
|
8
|
+
module Mocks
|
9
|
+
|
10
|
+
class Mock
|
11
|
+
include Abstract
|
12
|
+
|
13
|
+
attr_accessor :mock_calls
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@mock_calls = []
|
17
|
+
end
|
18
|
+
|
19
|
+
def mock_recall ( anObject )
|
20
|
+
result = nil
|
21
|
+
@mock_calls.each do |call|
|
22
|
+
result = call.recall anObject
|
23
|
+
end
|
24
|
+
result
|
25
|
+
end
|
26
|
+
|
27
|
+
def mock_calls_array
|
28
|
+
@mock_calls.map { |call| call.to_a }
|
29
|
+
end
|
30
|
+
|
31
|
+
def mock_args
|
32
|
+
@mock_calls.map { |call| call.args }
|
33
|
+
end
|
34
|
+
|
35
|
+
def mock_add ( elt )
|
36
|
+
@mock_calls << elt unless @mock_calls.frozen?
|
37
|
+
end
|
38
|
+
|
39
|
+
def mock_freeze
|
40
|
+
@mock_calls.freeze
|
41
|
+
end
|
42
|
+
|
43
|
+
def mock_clear
|
44
|
+
@mock_calls.clear
|
45
|
+
end
|
46
|
+
|
47
|
+
def mock_size
|
48
|
+
@mock_calls.size
|
49
|
+
end
|
50
|
+
|
51
|
+
end # class Mock
|
52
|
+
|
53
|
+
test_section __FILE__ do
|
54
|
+
class TestMock < ::Test::Unit::TestCase
|
55
|
+
|
56
|
+
def test_abstract
|
57
|
+
assert_raise(TypeError) { Mocks::Mock.new }
|
58
|
+
end
|
59
|
+
|
60
|
+
end # class TestMock
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end # module Mocks
|
data/lib/mocks/object.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# Copyright:: Copyright (c) 2005 Nicolas Pouillard. All rights reserved.
|
2
|
+
# Author:: Nicolas Pouillard <ertai@lrde.epita.fr>.
|
3
|
+
# License:: Gnu General Public License.
|
4
|
+
# Revision:: $Id: object.rb 339 2005-09-06 23:27:27Z ertai $
|
5
|
+
|
6
|
+
require 'mocks'
|
7
|
+
require 'blank_slate'
|
8
|
+
|
9
|
+
module Mocks
|
10
|
+
|
11
|
+
class Object < Mock
|
12
|
+
concrete
|
13
|
+
|
14
|
+
def self.blank_slate_ignore ( name )
|
15
|
+
super or name =~ /^(mock_|nil\?$)/
|
16
|
+
end
|
17
|
+
|
18
|
+
include BlankSlate
|
19
|
+
|
20
|
+
def method_missing ( meth, *args, &block )
|
21
|
+
mock_add MethodCall.new(meth, *args, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
end # class Object
|
25
|
+
|
26
|
+
test_section __FILE__ do
|
27
|
+
|
28
|
+
class TestObject < ::Test::Unit::TestCase
|
29
|
+
|
30
|
+
def setup
|
31
|
+
@proc = proc { 43 }
|
32
|
+
@obj = Mocks::Object.new
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_simple
|
36
|
+
@obj.foo(:bar, 42, &@proc)
|
37
|
+
@obj.bar
|
38
|
+
@obj << 42
|
39
|
+
assert_equal([[:foo, [:bar, 42], @proc],
|
40
|
+
[:bar], [:<<, 42]], @obj.mock_calls_array)
|
41
|
+
end
|
42
|
+
|
43
|
+
end # class TestObject
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end # module Mocks
|