Here is an example from autotest: class Autotest def self.run new.run end def new ... end def run ... end ... end How would I spec out Autotest.run? Two complications come to my mind: 1. How do I spec out class methods? (please point me to docs, if any. I can only find class level specing on "partial mocks" (of rails class objects) 2. How can I tell that new.run has been called, without saying should_receive(:new) and should_receive(:run) in separate specs? Another complication: How would I spec out the (instance level) run method, which has an infinite loop? def run hook :run reset add_sigint_handler loop do # ^c handler #...stuff... end hook :quit end Thanks for all of your help, Scott Taylor PS: Sorry for my previous non-sensical emails. I was being stupid.
> 1. How do I spec out class methods? (please point me to docs, if > any. I can only find class level specing on "partial mocks" (of > rails class objects)This doesn''t work? Autotest.spec!(:run) or do you perhaps want to return a proc that gets called?> 2. How can I tell that new.run has been called, without saying > should_receive(:new) and should_receive(:run) in separate specs?If you want instance method stubs, that''s handled by mocha but AFAIK not rspec. Mocha does it something like Autotest.any_instance.stubs(:run) This''d be a great rspec feature (or maybe I just couldn''t find it). Or maybe you want to do it more like test = Autotest.new test.should_receive(:run) I don''t know about the rest, still learning :)
On Apr 13, 2007, at 2:30 PM, Courtenay wrote:>> 1. How do I spec out class methods? (please point me to docs, if >> any. I can only find class level specing on "partial mocks" (of >> rails class objects) > > This doesn''t work? > > Autotest.spec!(:run) > > or do you perhaps want to return a proc that gets called?I believe that works. But how would I do it for Kernel.exit ? Kernel is a module (which I suppose is included in Object). I want to make sure that a given method calls exit. Of course I don''t want to actually call exit - that should terminate the running of the spec''s, should it? So I''d like to spec out Kernel.exit. How would I do that?> >> 2. How can I tell that new.run has been called, without saying >> should_receive(:new) and should_receive(:run) in separate specs? > > If you want instance method stubs, that''s handled by mocha but AFAIK > not rspec. Mocha does it something likeWell I have a class method which calls new.run, so I suppose I should be stubbing new and run. I want to make sure that the class method calls both of these methods (new and run) in sequence. the class should look something like the following: class Autotest def self.run new.run end def new; ... ; end def run; ...; end end So what I really want is something like: Autotest.run.should_receive(:new).should_receive(:run) or some variation of that. Does that clarify the matter? Scott
On 4/13/07, Scott Taylor <mailing_lists at railsnewbie.com> wrote:> Autotest.run.should_receive(:new).should_receive(:run)Is this what you''re trying to do? autotest = mock(''autotest'') autotest.should_receive(:run) Autotest.should_receive(:new).and_return(autotest) -- Josh Knowles joshknowles at gmail.com http://joshknowles.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rspec-users/attachments/20070413/6da084c3/attachment.html