存根和rspec旧语法的问题

时间:2015-01-20 16:21:57

标签: ruby rspec stubs

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

错误消息如下:在不明确启用语法的情况下,使用rspec-mocks的旧stub语法中的:should已弃用。使用新的:expect语法或明确启用:should

1 个答案:

答案 0 :(得分:4)

请改为:

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

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