title: RSpec - mocking a class method
body: <p>I'm trying to mock a class method with rspec:</p>
  
  <p><b>lib/db.rb</b></p>
  
  <pre>
  class Db
    def self.list(options)
      Db::Payload.list(options)
    end
  end
  </pre>
  
  <p><b>lib/db/payload.rb</b></p>
  
  <pre>
  class Db::Payload
    def self.list(options={})
    end
  end
  </pre>
  
  <p>In my spec, I'm trying to setup the expectation Db::Payload.list will be called when I call Db.list:</p>
  
  <pre>
  require 'db/payload'
  
  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
  </pre>
  
  <p>The problem is that I am always receiving the following error:</p>
  
  <pre>
  undefined method `should_receive' for Db::Payload:Class
  </pre>
  
  <p>Any help understanding this error would be most appreciated :-)</p>