RSpec - mocking a class method
        Posted  
        
            by Chris Kilmer
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Chris Kilmer
        
        
        
        Published on 2010-05-09T13:32:33Z
        Indexed on 
            2010/05/09
            13:38 UTC
        
        
        Read the original article
        Hit count: 219
        
I'm trying to mock a class method with rspec:
lib/db.rb
class Db
  def self.list(options)
    Db::Payload.list(options)
  end
end
lib/db/payload.rb
class Db::Payload
  def self.list(options={})
  end
end
In my spec, I'm trying to setup the expectation Db::Payload.list will be called when I call Db.list:
describe Db do
  before(:each) do
    @options = {}
    Db::Payload.should_receive(:list).with(@options)
  end
  it 'should build the LIST payload' do
    Db.list(@options)
  end
end
The problem is that I am always receiving the following error:
undefined method `should_receive' for Db::Payload:Class
Any help understanding this error would be most appreciated :-)
© Stack Overflow or respective owner