issue with stubs and rspec old syntax
Asked Answered
E

1

2

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.

Estipulate answered 20/1, 2015 at 16:21 Comment(0)
B
4

Do it like this instead:

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

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

Blubberhead answered 20/1, 2015 at 16:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.