Rails PayPal IPN activemerchant 控制器 rspec 测试

Posted

技术标签:

【中文标题】Rails PayPal IPN activemerchant 控制器 rspec 测试【英文标题】:Rails PayPal IPN activemerchant controller rspec test 【发布时间】:2014-01-26 04:33:47 【问题描述】:

我在我的系统中使用 activemerchant gem 实现了一个 PayPal API,我想编写一些规范来测试它,我已经搜索了很多示例但我没有找到任何示例,我想完全测试创建操作一条虚假的 PayPal 消息,我试过这个:

ActiveMerchant::Billing::Integrations::Paypal::Notification.any_instance.stub('acknowledge').and_return(true)

但随后测试进入了无限循环并返回了这个错误:

 Api::PaypalIpnController GET create update the order from pending to complete
 Failure/Error: Unable to find matching line from backtrace
 SystemStackError:
   stack level too deep

我在互联网上搜索了很多次,但没有找到有关如何模拟 PayPal 消息的示例或参考,我们将不胜感激。 谢谢。

【问题讨论】:

【参考方案1】:

我找到了一个解决方案,我唯一的错误是我没有使用符号命名来存根方法,我错误地使用了这个:

  any_instance.stub('acknowledge')

而不是这个:

  any_instance.stub(:acknowledge)

我还写了how to test IPN in Rspec的例子

【讨论】:

以上是关于Rails PayPal IPN activemerchant 控制器 rspec 测试的主要内容,如果未能解决你的问题,请参考以下文章