test/tc_service_point.rb in needle-0.5.0 vs test/tc_service_point.rb in needle-0.6.0

- old
+ new

@@ -15,31 +15,46 @@ #++ $:.unshift "../lib" require 'needle/interceptor' +require 'needle/pipeline/interceptor' require 'needle/service-point' require 'test/unit' class TC_ServicePoint < Test::Unit::TestCase class Model - def initialize(container,opts={},&callback) - @callback = callback + attr_reader :service_point + attr_reader :name + attr_reader :priority + attr_accessor :succ + + def initialize(point,name,priority,opts={},&callback) + @point = point + @priority = priority || 0 end - def instance - @callback.call + def call( *args ) + succ.call( *args ) end + def <=>( item ) + priority <=> item.priority + end end class Container def root self end - def service_models - { :mock => Model } + def []( name ) + case name + when :service_models + { :mock => [ :mock ] } + when :pipeline_elements + { :mock => Model, :interceptor => Needle::Pipeline::InterceptorElement } + end end def fullname "container" end @@ -69,11 +84,11 @@ assert_equal "test", point.name assert_equal "container.test", point.fullname assert_nothing_raised do point = - Needle::ServicePoint.new( @container, "test", :model => Model ) { + Needle::ServicePoint.new( @container, "test", :pipeline => [] ) { Hash.new } end end def test_instance @@ -81,9 +96,30 @@ Needle::ServicePoint.new( @container, "test", :model => :mock ) { Hash.new } inst = point.instance assert_instance_of Hash, inst + end + + def test_constructor_parms_single + point = + Needle::ServicePoint.new( @container, "test", :model => :mock ) do |c,p| + assert_equal @container, c + Hash.new + end + + point.instance + end + + def test_constructor_parms_multiple + point = + Needle::ServicePoint.new( @container, "test", :model => :mock ) do |c,p| + assert_equal @container, c + assert_equal point, p + Hash.new + end + + point.instance end def test_interceptor point = Needle::ServicePoint.new( @container, "test", :model => :mock ) {