加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby – Rspec mocks错误:参数数量错误

发布时间:2020-12-16 22:49:14 所属栏目:百科 来源:网络整理
导读:我试图使用Rspec来存储Stripe API,而且我遇到了一个问题.这是我的代码如下: Stripe::Customer.should_receive(:create).with(any_args).and_raise(Stripe::CardError) 这是我得到的错误: Failure/Error: Stripe::Customer.should_receive(:create).with(an
我试图使用Rspec来存储Stripe API,而且我遇到了一个问题.这是我的代码如下:
Stripe::Customer.should_receive(:create).with(any_args).and_raise(Stripe::CardError)

这是我得到的错误:

Failure/Error: Stripe::Customer.should_receive(:create).with(any_args).and_raise(Stripe::CardError)
ArgumentError:
  wrong number of arguments (0 for 3..6)

解决方法

Stripe :: CardError需要3..6个参数,根据以下源代码:
class CardError < StripeError
  ...
  def initialize(message,param,code,http_status=nil,http_body=nil,json_body=nil)

以下是github中的RSpec文档的关键文档:

expect(double).to receive(:msg).and_raise(error)
  #error can be an instantiated object or a class
  #if it is a class,it must be instantiable with no args

由于你只是提供类,而类需要参数,所以它是失败的.您需要实例化(即通过新的)并提供参数.

完整定义是在https://github.com/stripe/stripe-ruby/blob/0c281891948a793e79cc997d31918ba7f987f7ae/lib/stripe/errors/card_error.rb

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读