I have introduced mocks and and stubs into my testing and all was going well. I have hit a bit of a wall because since changing the code to test further i am getting the following error in rspec but i cannot understand why it is coming up with errors. When i was just testing it should hit below 16 everything was fine but when i introduced the test for it should hit above 16 i get the following errors.
undefined method `double' for RSpec::ExampleGroups::Hand::PlayAsDealer:Class (NoMethodError)
The piece of code in question is below:
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)
The second test was missing a do and end-problem now resolved!
it "should hit above 16" do
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)
end