I use rspec on rails. I want to test model. My model has this method: class My def self.blabla(url) open(url) {|f| #processing } end end open is Kernel method. How do I mock it? Kernel.expects and Kernel.should_receive and Kernel.stub! do no good. To make it more clear, I am looking for something like this: it "should processing rails.com" do Kernel.expects(:open).with(''rails.com'').returns(''blue'') My.blabla(''rails.com'').should == ''result of self.blabla'' end --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 13/12/2007, rinda <akbarhome-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I use rspec on rails. I want to test model. > > My model has this method: > > class My > def self.blabla(url) > open(url) {|f| > #processing > } > end > end > > open is Kernel method. How do I mock it? Kernel.expects and > Kernel.should_receive and Kernel.stub! do no good. > > To make it more clear, I am looking for something like this: > it "should processing rails.com" do > Kernel.expects(:open).with(''rails.com'').returns(''blue'') > My.blabla(''rails.com'').should == ''result of self.blabla'' > endI don''t know if it''s the same, but with Mocha you can do... My.expects(:open).with(''rails.com'').returns(''blue'') I hope that helps. -- James. http://blog.floehopper.org http://tumble.floehopper.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 14 Des, 00:48, "James Mead" <jamesmea...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I don''t know if it''s the same, but with Mocha you can do... > > My.expects(:open).with(''rails.com'').returns(''blue'') > > I hope that helps. > > -- > James.http://blog.floehopper.orghttp://tumble.floehopper.orgYes, I have tried that in simple unit testing file. It works, but I can not figure out integrate that with rspec on rails even using mocha. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 13/12/2007, rinda <akbarhome-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Yes, I have tried that in simple unit testing file. It works, but I > can not figure out integrate that with rspec on rails even using mocha.Strange. Have you tried the rspec mailing list [1]? -- James. http://blog.floehopper.org http://tumble.floehopper.org [1] http://rubyforge.org/mail/?group_id=797 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 14 Des, 03:30, "James Mead" <jamesmea...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 13/12/2007, rinda <akbarh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Yes, I have tried that in simple unit testing file. It works, but I > > can not figure out integrate that with rspec on rails even using mocha. > > Strange. Have you tried the rspec mailing list [1]? >Not yet. Maybe I should. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---