issue with stubs and rspec old syntax

こ雲淡風輕ζ 提交于 2019-12-24 04:54:08

问题


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

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.


回答1:


Do it like this instead:

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

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



来源:https://stackoverflow.com/questions/28050261/issue-with-stubs-and-rspec-old-syntax

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!