Forum: RSpec How to spec within a block?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Rémi G. (Guest)
on 2009-02-10 22:02
(Received via mailing list)
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
Pat M. (Guest)
on 2009-02-12 03:25
(Received via mailing list)
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
Rémi G. (Guest)
on 2009-02-12 05:14
(Received via mailing list)
It works thanks for the hints

Rémi
This topic is locked and can not be replied to.