Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
18 changes: 9 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
GEM
remote: http://rubygems.org/
specs:
diff-lcs (1.1.3)
rspec (2.11.0)
rspec-core (~> 2.11.0)
rspec-expectations (~> 2.11.0)
rspec-mocks (~> 2.11.0)
rspec-core (2.11.1)
rspec-expectations (2.11.2)
diff-lcs (~> 1.1.3)
rspec-mocks (2.11.1)
diff-lcs (1.2.4)
rspec (2.13.0)
rspec-core (~> 2.13.0)
rspec-expectations (~> 2.13.0)
rspec-mocks (~> 2.13.0)
rspec-core (2.13.1)
rspec-expectations (2.13.0)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.13.1)

PLATFORMS
ruby
Expand Down
22 changes: 19 additions & 3 deletions blackjack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ def value
end

def to_s
"#{@value}-#{suit}"
abbrev = {
clubs: "C",
diamonds: "D",
spades: "S",
hearts: "H"
}
"#{@value}#{abbrev[@suit]}"
end

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

def hit
@player_hand.hit!(@deck)
stand if @player_hand.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.

Just a detail of blackjack, but you'll also want to stand if you're exactly 21 as well.

end

def stand
Expand Down Expand Up @@ -133,9 +140,9 @@ def inspect
card.value.should eq(11)
end

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

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


it "should stand for the player if a player busts" do
game = Game.new
while game.player_hand.value <= 21
game.hit
end
game.status[:winner].should_not be_nil
Copy link
Member

Choose a reason for hiding this comment

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

In this case, I'd think "well, I want to tell if a game is finished, (or if it has a winner)." So, you could add:

def finished?
  @winner != nil?
end

Then, it would make your spec a little easier to reason about:

game.finished?.should be_true

Or, you could:

attr_reader :winner

Then, it's as easy as:

game.winner.should be_present

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