存根问题和 rspec 旧语法

issue with stubs and rspec old syntax

我正在编写一些代码并使用 rspec,但收到一条警告,提示语法过时,我不太清楚应该如何编写它?

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

错误信息如下:Using stub from rspec-mocks' old :should syntax without explicitly enabled the syntax is deprecated.使用新的 :expect 语法或显式启用 :should

改为这样做:

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

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