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
I want to mock to Model.to_xml but not his block. How to do it? Here is what I have (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 p "INTERVENANT ADRESSES" 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 end So I want to run specs within some blocks like that. Any recipes? Thank you R?mi -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090208/82615c56/attachment.html>
On Sun, Feb 8, 2009 at 6:44 AM, Remi Gagnon <rem.gagnon at gmail.com> wrote:> I want to mock to Model.to_xml but not his block. How to do it? > > Here is what I have (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 > p "INTERVENANT ADRESSES" > 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 > end > > So I want to run specs within some blocks like that. > > Any recipes? > > Thank youI''m not sure I understand your goal here. Can you show us what the spec you''d like to be able to write?> > R?mi > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >
On 08/02/2009, at 7:44 AM, Remi Gagnon wrote:> I want to mock to Model.to_xml but not his block. How to do it? > > Here is what I have (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 > p "INTERVENANT ADRESSES" > 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 > end > So I want to run specs within some blocks like that. > > Any recipes? > > Thank you > > R?miHi R?mi. If you show us what you''ve written so far, we can give you some tips. Cheers, Nick
On Sat, Feb 7, 2009 at 3:47 AM, rgagnon <rem.gagnon at gmail.com> 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
It works thanks for the hints R?mi On Wed, Feb 11, 2009 at 8:21 PM, Pat Maddox <pergesu at gmail.com> wrote:> On Sat, Feb 7, 2009 at 3:47 AM, rgagnon <rem.gagnon at gmail.com> 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 > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20090211/c810b9a3/attachment-0001.html>