【发布时间】:2012-05-06 23:06:32
【问题描述】:
我好像理解错了。我有课
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() 确保无论何时何地我在 Spree::Payment 的任何实例上调用 #find,它都会返回一些东西。
换句话说:我希望stub.and_return 会避免访问|| raise(ActiveRecord::RecordNotFound)。但事实并非如此。
我的假设错了吗,我的代码?还有什么?
【问题讨论】: