[rspec-users] Expectations on Class Methods

Scott Taylor mailing_lists at railsnewbie.com
Tue Nov 27 15:23:33 EST 2007

On Nov 27, 2007, at 3:13 PM, s.ross wrote:

> Sorry about the non-specific subject. Here's what I'm trying to do. I
> have a method:
> DataMapper::Database.setup
> That I want to create an expectation on. I wrote:
> DataMapper::Database.should_receive(:setup).once.and_return
> (connection_hash)
> The call to setup is invoked in the "Object" namespace. I.e., it is
> setup code, and not in any method or class.

Try using "load" to load the file *after* the expectation (not with  
require, before the expectation, as you would usually do).  (see this  
blog post by Jay Fields, which is about validations, but uses the  
load trick:  http://blog.jayfields.com/2006/12/rails-unit-testing- 

Or, you could also do some sort of behaviour verification.  What do  
you expect this DatabaseMapper setup should do?  Why is it in your  
code? If you can answer these questions, then you can probably write  
a test for it (but without stubbing)


More information about the rspec-users mailing list