我在测试中引入了模拟和存根,一切进展顺利。我遇到了一些问题,因为自从更改代码以进一步测试后,我在 rspec 中收到以下错误,但我不明白为什么会出现错误。当我刚刚测试它应该低于 16 时,一切都很好,但是当我引入测试时它应该达到 16 以上,我得到以下错误。
undefined method `double' for RSpec::ExampleGroups::Hand::PlayAsDealer:Class (NoMethodError)
有问题的代码如下:
describe "#play_as_dealer" do
it "should hit below 16" do
deck = double(:deck, :cards => [Card.new(:clubs, 4), Card.new(:diamonds, 4), Card.new(:clubs, 2), Card.new(:hearts, 6)])
hand = Hand.new
2.times { hand.hit!(deck) }
hand.play_as_dealer(deck)
expect(hand.value).to eq(16)
end
it "should hit above 16"
deck = double(:deck, :cards => [Card.new(:clubs, 4), Card.new(:diamonds, 4)])
hand = Hand.new
2.times { hand.hit!(deck) }
hand.play_as_dealer(deck)
expect(hand.value).to eq(17)