How to spec within a block?


#1

I have this and I want to mock the to_xml but not his block cause this
is what I want to spec. Is there a way to do this?

Sorry for the formatting

  output = @detenteur.to_xml( :skip_types => false, :skip_instruct

=> true, :dasherize => false, :only => [:inte_no] ) do |xml_detenteur|

    p xml_detenteur.intervenant_adresses.class.to_s

    xml_detenteur.intervenant_adresses do

      get_object_xml( @detenteur.intervenant_adresses,

@detenteur.intervenant_adresses.obtenir_adresses_vigueur, {:builder =>
xml_detenteur, :skip_instruct => true, :skip_types =>
false, :dasherize => false, :except => [:inte_no]})
end

    xml_detenteur.intervenant_telephones do
      get_object_xml( @detenteur.intervenant_telephones,

@detenteur.intervenant_telephones.obtenir_tels_vigueur, {:builder =>
xml_detenteur, :skip_instruct => true, :skip_types =>
false, :dasherize => false, :except => [:inte_no]})
end

    xml_detenteur.intervenants_polices do
      @polices = polices(@detenteur, @police_no, inte_polices,

xml_detenteur)
end
end


#2

On Sat, Feb 7, 2009 at 3:47 AM, rgagnon removed_email_address@domain.invalid wrote:

I have this and I want to mock the to_xml but not his block cause this
is what I want to spec. Is there a way to do this?

Use and_yield to yield an object, and you can set expectations on it.
For example:

xml_detent = mock(‘xml detenteur’)
xml_detent.stub!(:intervenant_adresses).and_return(array_of_addresses)
detenteur.stub!(:to_xml).and_yield(xml_detent)

Does that make sense?

Pat


#3

It works thanks for the hints

Rémi