2014-02-06 97 views
0

我想测试我的支付过程,我只能坚持磕碰订阅的问题,这是错误消息我得到:成株条纹订阅错误

Double "Stripe::Customer" received unexpected message :[] with ("subscription") 

这是相关的部分对于磕碰申购代码:

@subscription = double('Stripe::Subscription') 
@subscription.stub(:id) { 1234 } 
@customer.stub(:subscription) { [@subscription] } 

当我试着使用测试卡支付和它的作品,但我想在一些情况下,改变地方的自动化测试可能影响支付

编辑:

每mcfinnigan建议我改变了他的代码最后一位:

@customer.stub(:[]).with(:subscription).and_return { [@subscription] } 

现在我得到这个错误:

Double "Stripe::Customer" received :[] with unexpected arguments 
    expected: (:subscription) 
     got: ("subscription") 
Please stub a default value first if message might be received with other args as well. 

回答

2

你没有磕碰的权利事情 - 你的错误表明有东西试图调用方法[](即数组或散列解引用)在您的双重@customer上。

检查您的代码,看看您是否向任何地方的客户对象发送[]

你肯定最后一行不应该

@customer.stub(:[]).with(:subscription).and_return { [@subscription] } 

呢?

+0

感谢您的回复,请你看看我的更新 – London

+0

@伦敦好吧,所以你收到一个字符串参数,而不是一个符号。使用(“subscription”)将存根更改为'@ customer.stub(:[])。and_return {[@subscription]}' – mcfinnigan