存根和 rspec 旧语法的问题 [英] issue with stubs and rspec old syntax

查看:58
本文介绍了存根和 rspec 旧语法的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一些代码并使用 rspec,但收到一个警告,提示该语法很旧,我无法弄清楚我应该如何编写它?

I am writing some code and using rspec but received a warning that the syntax is old and i can't quite figure out how i should be writing it instead?

it "should calculate the value correctly" do 
        mock_cards = [Card.new(:clubs, 5), Card.new(:diamonds, 10)]
        hand = Hand.new
        hand.stub(:cards) { cards } #stub out cards and have it return cards
        expect(hand.value).to eq (15)
    end

错误信息如下:不推荐使用来自 rspec-mocks 的旧 :should 语法的 stub 而没有显式启用该语法.使用新的 :expect 语法或显式启用 :should 代替.

The error message is as follows: Using stub from rspec-mocks' old :should syntax without explicitly enabling the syntax is deprecated. Use the new :expect syntax or explicitly enable :should instead.

推荐答案

改为这样:

allow(hand).to receive(:cards) { cards }

https://github.com/rspec/rspec-mocks#method-stubs

这篇关于存根和 rspec 旧语法的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆