[rspec-users] Expectations on Class Methods

s.ross cwdinfo at gmail.com
Tue Nov 27 15:36:54 EST 2007

On Nov 27, 2007, at 12:23 PM, Scott Taylor wrote:

> 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)

Boy, don't I wish. Not my code, but I'd like to have a spec before I  
submit a patch. The DataMapper project is doing a great job of  
keeping specs parallel to their development, but the one thing they  
do is prepopulate a sqlite database prior to running all the tests.  
The bug I'm submitting a patch for is mysql-specific, and I'm at a  
loss how to un-sqliteize the environment without breaking all the  
other tests.

I know tests should run in isolation, but again, not my specification  
suite. They optimized for quick runs of the specs, I guess. So,  
rather than spec the behavior, I'm opting to check whether setup is  
called with the right parameters. What I'd prefer is to do something  
more like:

DataMapper::Database[:default].socket.should eql('/tmp/mysql.sock')

which is the *behavior* I want. I'm not seeing how to get from here  
to there.

The following is pretty much where I'm at, except that the  
expectation for :setup has a with(). I put out a ping to the  
DataMapper list, but so far no responses.

module DataMapper
   class Database

describe "setting up datamapper from a database.yml" do
   it "should look for database.yml" do
     Kernel::load File.dirname(__FILE__) + '/../lib/data_mapper.rb'

More information about the rspec-users mailing list