1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
require 'rubygems'
gem 'mocha'
require 'mocha'
class Driver < Mocha::Mock
def initialize
super
stubs( :open ).returns([0, 'cookie'])
stubs( :close ).returns(0)
stubs( :complete? ).returns(0)
stubs( :errmsg ).returns('')
stubs( :errcode ).returns(0)
stubs( :trace ).returns(nil)
stubs( :set_authorizer ).returns(0)
stubs( :prepare ).returns([0, 'stmt', 'remainder'])
stubs( :finalize ).returns(0)
stubs( :changes ).returns(14)
stubs( :total_changes ).returns(28)
stubs( :interrupt ).returns(0)
end
end
class MockResultSet < Mocha::Mock
def initialize
super
stubs( :each ).yields(['foo'])
stubs( :columns ).returns(['name'])
end
end
class Statement < Mocha::Mock
attr_reader :handle
attr_reader :sql
attr_reader :last_result
def initialize( handle, sql )
super()
@handle = handle
@sql = sql
stubs( :close ).returns(0)
stubs( :remainder ).returns('')
stubs( :execute ).returns(MockResultSet.new)
end
end
|