好像我理解错了什么。我有一堂课
module Spree
class OmnikassaPaymentResponse
#...
# Finds a payment with provided parameters trough ActiveRecord.
def payment(state = :processing)
Spree::Payment.find(:first, :conditions => { :amount => @amount, :order_id => @order_id, :state => state } ) || raise(ActiveRecord::RecordNotFound)
end
end
end
在 Rspec 中指定:
describe "#payment" do
it 'should try to find a Spree::Payment' do
Spree::Payment.any_instance.stub(:find).and_return(Spree::Payment.new)
Spree::Payment.any_instance.should_receive(:find)
Spree::OmnikassaPaymentResponse.new(@seal, @data).payment
end
end
然而,这总是抛出ActiveRecord::RecordNotFound
. 我希望any_instance.stub(:find).and_return()
确保无论何时,无论我#find
在什么地方调用一个 Spree::Payment 实例,它都会返回一些东西。
换句话说:我希望 thestub.and_return
会避免到达|| raise(ActiveRecord::RecordNotFound)
. 但事实并非如此。
我的假设是错误的吗,我的代码?还有什么?