Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions blackjack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def value
end

def to_s
"#{@value}-#{suit}"
"#{suit[0].upcase}#{@value}"
end

end
Expand Down Expand Up @@ -75,6 +75,9 @@ def initialize

def hit
@player_hand.hit!(@deck)
if @player_hand.value > 21
self.stand
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to call self here --- if you just say stand, it'll call the local method on the current object

end
end

def stand
Expand Down Expand Up @@ -135,7 +138,7 @@ def inspect

it "should be formatted nicely" do
card = Card.new(:diamonds, "A")
card.to_s.should eq("A-diamonds")
card.to_s.should eq("DA")
end
end

Expand Down Expand Up @@ -225,6 +228,14 @@ def inspect
game.status[:winner].should_not be_nil
end

it "should stand if the player busts" do
game = Game.new
unless game.status[:player_value] < 21
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a test, you probably don't want to seem wishy-washy... this "unless" makes it seem like you don't KNOW what's going on. You'll probably want to setup the test that you do know what's going on (because you set the environment beforehand),

game.hit
end
game.status[:winner].should_not nil
end

describe "#determine_winner" do
it "should have dealer win when player busts" do
Game.new.determine_winner(22, 15).should eq(:dealer)
Expand Down