Sha256: df450b05fc2df4bdf035129bfe952c4e30f86a6c460acf9fd2522682fc94e9b6

Contents?: true

Size: 1.53 KB

Versions: 2

Compression:

Stored size: 1.53 KB

Contents

require "twenty_one/dealer"
require "twenty_one/player"
require "twenty_one/deck"
require "twenty_one/card"
require "twenty_one/ace_card"
require "twenty_one/face_card"

include TwentyOne

describe Dealer do
	before(:each) do
		shoe = []
		4.times do
				shoe.concat Deck.new.cards
		end

		@dealer = Dealer.new "Ken Thompson", shoe
		@player = Player.new "Dennis Ritchie"
	end

	it "should start with a pretty big selection of cards" do
		expect(@dealer.shoe.size).to be >= 52
	end	

	describe "#showdown(player)" do
		it "should push if there is a tie" do
			@player.make_bet 100

			@player.hand.cards.concat [Card.new(:diamonds, 2), Card.new(:spades, 3)]
			@dealer.hand.cards.concat [Card.new(:hearts, 2), Card.new(:clubs, 3)]

			result = @dealer.showdown @player

			expect(result).to eq(:push)
		end

		it "should report a bust if the player loses" do
			@player.make_bet 100
			
			ace_card = AceCard.new :clubs

			ace_card.use_upper

			@dealer.hit @player
			@dealer.hand.cards.concat [ace_card, Card.new(:clubs, 6)]

			result = @dealer.showdown @player

			expect(result).to eq(:bust)
		end	

		it "should report a win if the player wins" do
			@player.make_bet 100

			ace_card = AceCard.new :clubs

			ace_card.use_upper

			@player.hand.cards.concat [ace_card, Card.new(:spade, 5)]
			@dealer.hit(@dealer)

			result = @dealer.showdown @player

			expect(result).to eq(:win)
		end
	end

	describe "#hit(player)" do
		it "should add a card to the player's hand" do
			@dealer.hit @player

			expect(@player.hand.cards.size).to be > 0
		end
	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
twenty_one-0.1.1 spec/lib/dealer_spec.rb
twenty_one-0.1.0 spec/lib/dealer_spec.rb