问题
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