RSpec - mocking a class method
- by Chris Kilmer
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 :-)