2

我正在编写一些代码并使用 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

错误消息如下: 不推荐使用stubfrom rspec-mocks' old :shouldsyntax without显式启用该语法。改用新:expect语法或显式启用:should

4

1 回答 1

4

改为这样做:

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

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

于 2015-01-20T16:32:15.093 回答