issue with stubs and rspec old syntax

2019-07-21 10:52发布

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.

标签: ruby rspec stubs
1条回答
够拽才男人
2楼-- · 2019-07-21 11:25

Do it like this instead:

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

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

查看更多
登录 后发表回答