needle 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. data/benchmarks/instantiability.rb +26 -0
  2. data/benchmarks/instantiation.rb +33 -0
  3. data/benchmarks/interceptors.rb +42 -0
  4. data/benchmarks/interceptors2.rb +70 -0
  5. data/doc/README +3 -1
  6. data/doc/di-in-ruby.rdoc +201 -0
  7. data/doc/images/di_classdiagram.jpg +0 -0
  8. data/doc/manual/manual.yml +4 -0
  9. data/doc/manual/parts/01_alternatives.txt +11 -0
  10. data/doc/manual/parts/02_creating.txt +20 -0
  11. data/doc/manual/parts/02_namespaces.txt +1 -1
  12. data/doc/manual/parts/02_services.txt +15 -3
  13. data/doc/manual-html/chapter-1.html +34 -7
  14. data/doc/manual-html/chapter-2.html +43 -9
  15. data/doc/manual-html/chapter-3.html +6 -4
  16. data/doc/manual-html/chapter-4.html +6 -4
  17. data/doc/manual-html/chapter-5.html +6 -4
  18. data/doc/manual-html/chapter-6.html +6 -4
  19. data/doc/manual-html/chapter-7.html +6 -4
  20. data/doc/manual-html/index.html +19 -4
  21. data/lib/needle/container.rb +104 -66
  22. data/{test/tc_models.rb → lib/needle/lifecycle/deferred.rb} +14 -20
  23. data/lib/needle/lifecycle/initialize.rb +49 -0
  24. data/lib/needle/{models → lifecycle}/proxy.rb +16 -8
  25. data/lib/needle/lifecycle/singleton.rb +63 -0
  26. data/lib/needle/lifecycle/threaded.rb +58 -0
  27. data/lib/needle/pipeline/collection.rb +133 -0
  28. data/lib/needle/pipeline/element.rb +85 -0
  29. data/lib/needle/pipeline/interceptor.rb +46 -0
  30. data/lib/needle/registry.rb +48 -8
  31. data/lib/needle/service-point.rb +36 -39
  32. data/lib/needle/thread.rb +87 -0
  33. data/lib/needle/version.rb +1 -1
  34. data/{lib/needle/models/prototype.rb → test/lifecycle/tc_deferred.rb} +15 -17
  35. data/test/lifecycle/tc_initialize.rb +62 -0
  36. data/test/{models → lifecycle}/tc_proxy.rb +5 -5
  37. data/test/lifecycle/tc_singleton.rb +32 -0
  38. data/{lib/needle/models/prototype-deferred.rb → test/lifecycle/tc_threaded.rb} +24 -18
  39. data/test/models/model_test.rb +131 -0
  40. data/test/models/tc_prototype.rb +9 -30
  41. data/test/models/tc_prototype_deferred.rb +9 -31
  42. data/test/models/tc_prototype_deferred_initialize.rb +32 -0
  43. data/test/models/tc_prototype_initialize.rb +32 -0
  44. data/test/models/tc_singleton.rb +8 -29
  45. data/test/models/tc_singleton_deferred.rb +8 -30
  46. data/test/models/tc_singleton_deferred_initialize.rb +32 -0
  47. data/test/models/tc_singleton_initialize.rb +32 -0
  48. data/test/models/tc_threaded.rb +32 -0
  49. data/test/models/tc_threaded_deferred.rb +32 -0
  50. data/test/models/tc_threaded_deferred_initialize.rb +32 -0
  51. data/test/models/tc_threaded_initialize.rb +32 -0
  52. data/test/pipeline/tc_collection.rb +116 -0
  53. data/test/pipeline/tc_element.rb +72 -0
  54. data/test/tc_container.rb +77 -36
  55. data/test/tc_logger.rb +5 -0
  56. data/test/tc_registry.rb +39 -1
  57. data/test/tc_service_point.rb +43 -7
  58. metadata +39 -12
  59. data/lib/needle/models/singleton-deferred.rb +0 -57
  60. data/lib/needle/models/singleton.rb +0 -56
  61. data/lib/needle/models.rb +0 -44
@@ -16,39 +16,17 @@
16
16
 
17
17
  $:.unshift "../../lib"
18
18
 
19
- require "needle/models/singleton-deferred"
19
+ require "needle"
20
20
  require "test/unit"
21
+ require File.join( File.dirname( __FILE__ ), "model_test" )
21
22
 
22
- class TC_ModelsSingletonDeferred < Test::Unit::TestCase
23
+ class TC_Model_Singleton_Deferred < Test::Unit::TestCase
24
+ include ModelTest
23
25
 
24
- def test_instance
25
- instantiated = false
26
- model = Needle::Models::SingletonDeferred.new( nil ) {
27
- instantiated = true
28
- Hash.new
29
- }
26
+ use :singleton_deferred
30
27
 
31
- assert !instantiated
32
- proto = model.instance
33
- assert !instantiated
34
- proto[:test] = :value
35
- assert instantiated
36
- assert_equal :value, proto[:test]
37
- end
38
-
39
- def test_container
40
- model = Needle::Models::SingletonDeferred.new( :container ) { |c|
41
- assert_equal :container, c
42
- Hash.new
43
- }
44
- model.instance[:test] = :value
45
- end
46
-
47
- def test_model
48
- model = Needle::Models::SingletonDeferred.new( nil ) { Hash.new }
49
- p1 = model.instance
50
- p2 = model.instance
51
- assert_same p1, p2
52
- end
28
+ assert_singleton
29
+ assert_deferred
30
+ assert_no_init
53
31
 
54
32
  end
@@ -0,0 +1,32 @@
1
+ #--
2
+ # =============================================================================
3
+ # Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
4
+ # All rights reserved.
5
+ #
6
+ # This source file is distributed as part of the Needle dependency injection
7
+ # library for Ruby. This file (and the library as a whole) may be used only as
8
+ # allowed by either the BSD license, or the Ruby license (or, by association
9
+ # with the Ruby license, the GPL). See the "doc" subdirectory of the Needle
10
+ # distribution for the texts of these licenses.
11
+ # -----------------------------------------------------------------------------
12
+ # needle website : http://needle.rubyforge.org
13
+ # project website: http://rubyforge.org/projects/needle
14
+ # =============================================================================
15
+ #++
16
+
17
+ $:.unshift "../../lib"
18
+
19
+ require "needle"
20
+ require "test/unit"
21
+ require File.join( File.dirname( __FILE__ ), "model_test" )
22
+
23
+ class TC_Model_Singleton_Deferred_Initialize < Test::Unit::TestCase
24
+ include ModelTest
25
+
26
+ use :singleton_deferred_initialize
27
+
28
+ assert_singleton
29
+ assert_deferred
30
+ assert_init
31
+
32
+ end
@@ -0,0 +1,32 @@
1
+ #--
2
+ # =============================================================================
3
+ # Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
4
+ # All rights reserved.
5
+ #
6
+ # This source file is distributed as part of the Needle dependency injection
7
+ # library for Ruby. This file (and the library as a whole) may be used only as
8
+ # allowed by either the BSD license, or the Ruby license (or, by association
9
+ # with the Ruby license, the GPL). See the "doc" subdirectory of the Needle
10
+ # distribution for the texts of these licenses.
11
+ # -----------------------------------------------------------------------------
12
+ # needle website : http://needle.rubyforge.org
13
+ # project website: http://rubyforge.org/projects/needle
14
+ # =============================================================================
15
+ #++
16
+
17
+ $:.unshift "../../lib"
18
+
19
+ require "needle"
20
+ require "test/unit"
21
+ require File.join( File.dirname( __FILE__ ), "model_test" )
22
+
23
+ class TC_Model_Singleton_Initialize < Test::Unit::TestCase
24
+ include ModelTest
25
+
26
+ use :singleton_initialize
27
+
28
+ assert_singleton
29
+ assert_immediate
30
+ assert_init
31
+
32
+ end
@@ -0,0 +1,32 @@
1
+ #--
2
+ # =============================================================================
3
+ # Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
4
+ # All rights reserved.
5
+ #
6
+ # This source file is distributed as part of the Needle dependency injection
7
+ # library for Ruby. This file (and the library as a whole) may be used only as
8
+ # allowed by either the BSD license, or the Ruby license (or, by association
9
+ # with the Ruby license, the GPL). See the "doc" subdirectory of the Needle
10
+ # distribution for the texts of these licenses.
11
+ # -----------------------------------------------------------------------------
12
+ # needle website : http://needle.rubyforge.org
13
+ # project website: http://rubyforge.org/projects/needle
14
+ # =============================================================================
15
+ #++
16
+
17
+ $:.unshift "../../lib"
18
+
19
+ require "needle"
20
+ require "test/unit"
21
+ require File.join( File.dirname( __FILE__ ), "model_test" )
22
+
23
+ class TC_Model_Threaded < Test::Unit::TestCase
24
+ include ModelTest
25
+
26
+ use :threaded
27
+
28
+ assert_threaded
29
+ assert_immediate
30
+ assert_no_init
31
+
32
+ end
@@ -0,0 +1,32 @@
1
+ #--
2
+ # =============================================================================
3
+ # Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
4
+ # All rights reserved.
5
+ #
6
+ # This source file is distributed as part of the Needle dependency injection
7
+ # library for Ruby. This file (and the library as a whole) may be used only as
8
+ # allowed by either the BSD license, or the Ruby license (or, by association
9
+ # with the Ruby license, the GPL). See the "doc" subdirectory of the Needle
10
+ # distribution for the texts of these licenses.
11
+ # -----------------------------------------------------------------------------
12
+ # needle website : http://needle.rubyforge.org
13
+ # project website: http://rubyforge.org/projects/needle
14
+ # =============================================================================
15
+ #++
16
+
17
+ $:.unshift "../../lib"
18
+
19
+ require "needle"
20
+ require "test/unit"
21
+ require File.join( File.dirname( __FILE__ ), "model_test" )
22
+
23
+ class TC_Model_Threaded_Deferred < Test::Unit::TestCase
24
+ include ModelTest
25
+
26
+ use :threaded_deferred
27
+
28
+ assert_threaded
29
+ assert_deferred
30
+ assert_no_init
31
+
32
+ end
@@ -0,0 +1,32 @@
1
+ #--
2
+ # =============================================================================
3
+ # Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
4
+ # All rights reserved.
5
+ #
6
+ # This source file is distributed as part of the Needle dependency injection
7
+ # library for Ruby. This file (and the library as a whole) may be used only as
8
+ # allowed by either the BSD license, or the Ruby license (or, by association
9
+ # with the Ruby license, the GPL). See the "doc" subdirectory of the Needle
10
+ # distribution for the texts of these licenses.
11
+ # -----------------------------------------------------------------------------
12
+ # needle website : http://needle.rubyforge.org
13
+ # project website: http://rubyforge.org/projects/needle
14
+ # =============================================================================
15
+ #++
16
+
17
+ $:.unshift "../../lib"
18
+
19
+ require "needle"
20
+ require "test/unit"
21
+ require File.join( File.dirname( __FILE__ ), "model_test" )
22
+
23
+ class TC_Model_Threaded_Deferred_Initialize < Test::Unit::TestCase
24
+ include ModelTest
25
+
26
+ use :threaded_deferred_initialize
27
+
28
+ assert_threaded
29
+ assert_deferred
30
+ assert_init
31
+
32
+ end
@@ -0,0 +1,32 @@
1
+ #--
2
+ # =============================================================================
3
+ # Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
4
+ # All rights reserved.
5
+ #
6
+ # This source file is distributed as part of the Needle dependency injection
7
+ # library for Ruby. This file (and the library as a whole) may be used only as
8
+ # allowed by either the BSD license, or the Ruby license (or, by association
9
+ # with the Ruby license, the GPL). See the "doc" subdirectory of the Needle
10
+ # distribution for the texts of these licenses.
11
+ # -----------------------------------------------------------------------------
12
+ # needle website : http://needle.rubyforge.org
13
+ # project website: http://rubyforge.org/projects/needle
14
+ # =============================================================================
15
+ #++
16
+
17
+ $:.unshift "../../lib"
18
+
19
+ require "needle"
20
+ require "test/unit"
21
+ require File.join( File.dirname( __FILE__ ), "model_test" )
22
+
23
+ class TC_Model_Threaded_Initialize < Test::Unit::TestCase
24
+ include ModelTest
25
+
26
+ use :threaded_initialize
27
+
28
+ assert_threaded
29
+ assert_immediate
30
+ assert_init
31
+
32
+ end
@@ -0,0 +1,116 @@
1
+ #--
2
+ # =============================================================================
3
+ # Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
4
+ # All rights reserved.
5
+ #
6
+ # This source file is distributed as part of the Needle dependency injection
7
+ # library for Ruby. This file (and the library as a whole) may be used only as
8
+ # allowed by either the BSD license, or the Ruby license (or, by association
9
+ # with the Ruby license, the GPL). See the "doc" subdirectory of the Needle
10
+ # distribution for the texts of these licenses.
11
+ # -----------------------------------------------------------------------------
12
+ # needle website : http://needle.rubyforge.org
13
+ # project website: http://rubyforge.org/projects/needle
14
+ # =============================================================================
15
+ #++
16
+
17
+ $:.unshift "../../lib"
18
+
19
+ require 'needle/pipeline/collection'
20
+ require 'test/unit'
21
+
22
+ class TC_Pipeline_Collection < Test::Unit::TestCase
23
+
24
+ class MockElement
25
+ attr_reader :service_point
26
+ attr_reader :name
27
+ attr_reader :priority
28
+ attr_accessor :succ
29
+
30
+ def initialize( point, name, priority, options )
31
+ @service_point = point
32
+ @name, @priority = name, priority
33
+ end
34
+
35
+ def call( *args )
36
+ args.first << "|Mock"
37
+ succ.call *args
38
+ args.first << "|Done"
39
+ end
40
+
41
+ def <=>( element )
42
+ priority <=> element.priority
43
+ end
44
+ end
45
+
46
+ def setup
47
+ elements = { :pipeline_elements => { :mock => MockElement } }
48
+ point = Struct.new( :container ).new( elements )
49
+ @collection = Needle::Pipeline::Collection.new( point )
50
+ end
51
+
52
+ def test_add_anonymous_block
53
+ @collection.add do |me,*args|
54
+ args.first << "|A"
55
+ result = me.succ.call( *args )
56
+ args.first << "|B"
57
+ result
58
+ end
59
+
60
+ chain = @collection.chain_to( proc { |a| a << "|tail" } )
61
+ b = ""
62
+ chain.call( b )
63
+ assert_equal b, "|A|tail|B"
64
+ end
65
+
66
+ def test_add_named_block
67
+ @collection.add( "block" ) do |chain,*args|
68
+ args.first << "|A"
69
+ result = chain.call( *args )
70
+ args.first << "|B"
71
+ result
72
+ end
73
+
74
+ assert_not_nil @collection.get( :block )
75
+ end
76
+
77
+ def test_add_named_element
78
+ @collection.add :mock
79
+
80
+ chain = @collection.chain_to( proc { |a| a << "|tail" } )
81
+ b = ""
82
+ chain.call( b )
83
+ assert_equal b, "|Mock|tail|Done"
84
+ end
85
+
86
+ def test_add_prioritize
87
+ @collection.add :mock, 50
88
+ @collection.add 25 do |me,*args|
89
+ args.first << "|proc"
90
+ r = me.succ.call( *args )
91
+ args.first << "|end"
92
+ r
93
+ end
94
+
95
+ chain = @collection.chain_to( proc { |a| a << "|tail" } )
96
+ b = ""
97
+ chain.call( b )
98
+ assert_equal b, "|Mock|proc|tail|end|Done"
99
+ end
100
+
101
+ def test_add_prioritize_reverse
102
+ @collection.add :mock, 25
103
+ @collection.add 50 do |me,*args|
104
+ args.first << "|proc"
105
+ r = me.succ.call( *args )
106
+ args.first << "|end"
107
+ r
108
+ end
109
+
110
+ chain = @collection.chain_to( proc { |a| a << "|tail" } )
111
+ b = ""
112
+ chain.call( b )
113
+ assert_equal b, "|proc|Mock|tail|Done|end"
114
+ end
115
+
116
+ end
@@ -0,0 +1,72 @@
1
+ #--
2
+ # =============================================================================
3
+ # Copyright (c) 2004, Jamis Buck (jgb3@email.byu.edu)
4
+ # All rights reserved.
5
+ #
6
+ # This source file is distributed as part of the Needle dependency injection
7
+ # library for Ruby. This file (and the library as a whole) may be used only as
8
+ # allowed by either the BSD license, or the Ruby license (or, by association
9
+ # with the Ruby license, the GPL). See the "doc" subdirectory of the Needle
10
+ # distribution for the texts of these licenses.
11
+ # -----------------------------------------------------------------------------
12
+ # needle website : http://needle.rubyforge.org
13
+ # project website: http://rubyforge.org/projects/needle
14
+ # =============================================================================
15
+ #++
16
+
17
+ $:.unshift "../../lib"
18
+
19
+ require 'needle/pipeline/element'
20
+ require 'test/unit'
21
+
22
+ class TC_Pipeline_Element < Test::Unit::TestCase
23
+
24
+ def test_default_priority
25
+ assert_equal 0, Needle::Pipeline::Element.default_priority
26
+ element = Needle::Pipeline::Element.new nil
27
+ assert_equal Needle::Pipeline::Element.default_priority, element.priority
28
+ end
29
+
30
+ def test_default_name
31
+ element = Needle::Pipeline::Element.new nil
32
+ assert_nil element.name
33
+ end
34
+
35
+ def test_name
36
+ element = Needle::Pipeline::Element.new nil, :test
37
+ assert_equal :test, element.name
38
+ end
39
+
40
+ def test_priority
41
+ element = Needle::Pipeline::Element.new nil, :test, 50
42
+ assert_equal 50, element.priority
43
+ end
44
+
45
+ def test_index_operator
46
+ element = Needle::Pipeline::Element.new nil
47
+ assert_raise( NotImplementedError ) { element[:arg] }
48
+ end
49
+
50
+ def test_call
51
+ element = Needle::Pipeline::Element.new nil
52
+ assert_raise( NotImplementedError ) { element.call( :arg ) }
53
+ end
54
+
55
+ def test_ordering
56
+ element1 = Needle::Pipeline::Element.new( nil, :test1, 25 )
57
+ element2 = Needle::Pipeline::Element.new( nil, :test2, 75 )
58
+
59
+ assert_equal -1, element1 <=> element2
60
+ assert_equal 1, element2 <=> element1
61
+ end
62
+
63
+ def test_comparable
64
+ element1 = Needle::Pipeline::Element.new( nil, :test1, 25 )
65
+ element2 = Needle::Pipeline::Element.new( nil, :test2, 75 )
66
+
67
+ assert element1 < element2
68
+ assert element2 > element1
69
+ assert element1 != element2
70
+ end
71
+
72
+ end
data/test/tc_container.rb CHANGED
@@ -17,11 +17,12 @@
17
17
  $:.unshift "../lib"
18
18
 
19
19
  require 'needle/container'
20
+ require 'needle/registry'
20
21
  require 'test/unit'
21
22
 
22
23
  class TC_Container < Test::Unit::TestCase
23
24
 
24
- class TC_RegistrationContext < Test::Unit::TestCase
25
+ class TC_DefinitionContext < Test::Unit::TestCase
25
26
  class MockContainer
26
27
  attr_reader :events
27
28
  def initialize; @events = []; end
@@ -32,7 +33,7 @@ class TC_Container < Test::Unit::TestCase
32
33
 
33
34
  def setup
34
35
  @container = MockContainer.new
35
- @ctx = Needle::Container::RegistrationContext.new( @container )
36
+ @ctx = Needle::Container::DefinitionContext.new( @container )
36
37
  end
37
38
 
38
39
  def test_register
@@ -68,17 +69,10 @@ class TC_Container < Test::Unit::TestCase
68
69
  assert_nil @container.events[0][:block]
69
70
  end
70
71
 
71
- end
72
-
73
- class Model
74
- def initialize( container, opts={}, &callback )
75
- @container, @callback = container, callback
76
- @inst = nil
77
- end
78
- def instance
79
- return @inst if @inst
80
- @inst = @callback.call( @container )
72
+ def test_this_container
73
+ assert_equal @container, @ctx.this_container
81
74
  end
75
+
82
76
  end
83
77
 
84
78
  def test_default
@@ -128,7 +122,7 @@ class TC_Container < Test::Unit::TestCase
128
122
 
129
123
  def test_register
130
124
  container = Needle::Container.new
131
- container.register( :test, :model=>Model ) { Hash.new }
125
+ container.register( :test, :pipeline=>[] ) { Hash.new }
132
126
 
133
127
  assert_nothing_raised { container[:test] }
134
128
  assert_nothing_raised { container.test }
@@ -139,13 +133,21 @@ class TC_Container < Test::Unit::TestCase
139
133
  assert container.respond_to?(:test)
140
134
  end
141
135
 
142
- def test_register!
136
+ def test_builder
143
137
  container = Needle::Container.new
138
+ b1 = container.builder
139
+ b2 = container.builder
140
+
141
+ assert_same b1.__id__, b2.__id__
142
+ end
144
143
 
145
- container.register! do
146
- test( :model=>Model ) { Hash.new }
147
- namespace :subitem, :model=>Model do
148
- test2( :model=>Model ) { Hash.new }
144
+ def test_define_block
145
+ container = Needle::Container.new
146
+
147
+ container.define do |b|
148
+ b.test( :pipeline=>[] ) { Hash.new }
149
+ b.namespace :subitem, :pipeline=>[] do |b2|
150
+ b2.test2( :pipeline=>[] ) { Hash.new }
149
151
  end
150
152
  end
151
153
 
@@ -155,35 +157,46 @@ class TC_Container < Test::Unit::TestCase
155
157
  assert_instance_of Hash, container.subitem.test2
156
158
  end
157
159
 
158
- def test_namespace
160
+ def test_define_noblock
159
161
  container = Needle::Container.new
160
- container.namespace( :test, :model=>Model )
161
- assert_instance_of Needle::Container, container.test
162
+ container.define.test( :pipeline=>[] ) { Hash.new }
163
+ assert container.has_key?( :test )
164
+ assert_instance_of Hash, container.test
165
+ end
162
166
 
163
- container.namespace( :test2, :model=>Model ) do |ns|
164
- assert_instance_of Needle::Container, ns
167
+ def test_define!
168
+ container = Needle::Container.new
169
+
170
+ container.define! do
171
+ test( :pipeline=>[] ) { Hash.new }
172
+ namespace! :subitem, :pipeline=>[] do
173
+ test2( :pipeline=>[] ) { Hash.new }
174
+ end
165
175
  end
166
176
 
167
- assert_instance_of Needle::Container, container.test2
177
+ assert container.has_key?( :test )
178
+ assert_instance_of Hash, container.test
179
+ assert container.subitem.has_key?( :test2 )
180
+ assert_instance_of Hash, container.subitem.test2
168
181
  end
169
182
 
170
- def test_multi_namespace
183
+ def test_namespace
171
184
  container = Needle::Container.new
172
- container.namespace( :test, :test2, :test3, :model=>Model )
185
+ container.namespace( :test, :pipeline=>[] )
173
186
  assert_instance_of Needle::Container, container.test
174
- assert_instance_of Needle::Container, container.test.test2
175
- assert_instance_of Needle::Container, container.test.test2.test3
176
187
 
177
- container.namespace( :test, :test2, :test3, :model=>Model ) do |ns|
178
- assert_same ns, container.test.test2.test3
188
+ container.namespace( :test2, :pipeline=>[] ) do |ns|
189
+ assert_instance_of Needle::Container, ns
179
190
  end
191
+
192
+ assert_instance_of Needle::Container, container.test2
180
193
  end
181
194
 
182
195
  def test_has_key
183
196
  container = Needle::Container.new
184
197
 
185
198
  assert !container.has_key?(:test)
186
- container.register( :test, :model=>Model ) { Hash.new }
199
+ container.register( :test, :pipeline=>[] ) { Hash.new }
187
200
  assert container.has_key?(:test)
188
201
  end
189
202
 
@@ -191,7 +204,7 @@ class TC_Container < Test::Unit::TestCase
191
204
  container = Needle::Container.new
192
205
 
193
206
  assert !container.knows_key?(:test)
194
- container.register( :test, :model=>Model ) { Hash.new }
207
+ container.register( :test, :pipeline=>[] ) { Hash.new }
195
208
  assert container.knows_key?(:test)
196
209
  end
197
210
 
@@ -199,7 +212,7 @@ class TC_Container < Test::Unit::TestCase
199
212
  outer = Needle::Container.new
200
213
  inner = Needle::Container.new( outer )
201
214
 
202
- outer.register( :test, :model=>Model ) { Hash.new }
215
+ outer.register( :test, :pipeline=>[] ) { Hash.new }
203
216
  assert !inner.has_key?(:test)
204
217
  assert inner.knows_key?(:test)
205
218
  end
@@ -208,7 +221,7 @@ class TC_Container < Test::Unit::TestCase
208
221
  outer = Needle::Container.new
209
222
  inner = Needle::Container.new( outer )
210
223
 
211
- outer.register( :test, :model=>Model ) { Hash.new }
224
+ outer.register( :test, :pipeline=>[] ) { Hash.new }
212
225
  assert_nothing_raised do
213
226
  inner[:test]
214
227
  end
@@ -231,8 +244,8 @@ class TC_Container < Test::Unit::TestCase
231
244
  end
232
245
 
233
246
  def test_intercept
234
- container = Needle::Container.new
235
- container.register( :test, :model=>Model ) { Hash.new }
247
+ container = Needle::Registry.new
248
+ container.register( :test ) { Hash.new }
236
249
 
237
250
  filtered = false
238
251
  container.intercept( :test ).doing { |chain,ctx| filtered = true; chain.process_next(ctx) }
@@ -243,4 +256,32 @@ class TC_Container < Test::Unit::TestCase
243
256
  assert filtered
244
257
  end
245
258
 
259
+ def test_find_definition_missing
260
+ container = Needle::Container.new
261
+ assert_nil container.find_definition( :bogus )
262
+ end
263
+
264
+ def test_find_definition_found_local
265
+ container = Needle::Container.new
266
+ container.register( :test, :pipeline=>[] ) { Object.new }
267
+ assert_not_nil container.find_definition( :test )
268
+ end
269
+
270
+ def test_find_definition_found_ancestor
271
+ outer = Needle::Container.new
272
+ inner = Needle::Container.new( outer )
273
+ outer.register( :test, :pipeline=>[] ) { Object.new }
274
+ assert_not_nil inner.find_definition( :test )
275
+ end
276
+
277
+ def test_pipeline
278
+ container = Needle::Container.new
279
+ container.register( :test, :pipeline=>[] ) { Object.new }
280
+ assert_instance_of Needle::Pipeline::Collection, container.pipeline( :test )
281
+
282
+ p1 = container.pipeline(:test)
283
+ p2 = container.pipeline(:test)
284
+ assert_same p1, p2
285
+ end
286
+
246
287
  end
data/test/tc_logger.rb CHANGED
@@ -42,6 +42,11 @@ class TC_Logger < Test::Unit::TestCase
42
42
  end
43
43
  end
44
44
 
45
+ def teardown
46
+ logs = Dir[File.join(File.dirname(__FILE__),"*.log")]
47
+ File.delete *logs unless logs.empty?
48
+ end
49
+
45
50
  def test_log_filename
46
51
  factory = Needle::LogFactory.new
47
52
  assert_equal Needle::LogFactory::DEFAULT_LOG_FILENAME,