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
22 changes: 18 additions & 4 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}"
return "#{suit[0].upcase}#{@value}"
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 have to use 'return' in Ruby... the last executed code in a method will always return. You can use returns to early return a method, something like this:

attr_reader :my_tent

def default_tent
  return 5 if my_tent.nil?
  calculate_tent
end

end

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

def hit
@player_hand.hit!(@deck)
stand if @player_hand.value > 21
status
end

def stand
Expand Down Expand Up @@ -134,8 +136,8 @@ def inspect
end

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

Expand Down Expand Up @@ -175,7 +177,7 @@ def inspect
end

describe "#play_as_dealer" do
it "should hit blow 16" do
it "should hit below 16" do
deck = mock(: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) }
Expand Down Expand Up @@ -225,6 +227,18 @@ def inspect
game.status[:winner].should_not be_nil
end


it "should stand for player if hand value is over 21" do
Copy link
Member

Choose a reason for hiding this comment

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

Excellent job on this spec; it looks great.

game = Game.new
deck = mock(:deck, :cards => [Card.new(:clubs, 11), Card.new(:diamonds, 11)])
hand = Hand.new
2.times { hand.hit!(deck) }
hand.value.should eq(22)
game.stand
game.status[:winner].should_not be_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