[rspec-users] specing class methods

Scott Taylor mailing_lists at railsnewbie.com
Fri Apr 13 17:05:53 EDT 2007

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 like

Well 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

  def new; ... ; end
  def run; ...; end

So what I really want is something like:


or some variation of that.

Does that clarify the matter?


More information about the rspec-users mailing list