Skip to content

Commit

Permalink
Hitting and staying
Browse files Browse the repository at this point in the history
  • Loading branch information
iandonovan committed Jun 7, 2015
1 parent 390902f commit 9d7e84b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 42 deletions.
56 changes: 30 additions & 26 deletions app/main/views/main/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,39 @@
{{ end }}

<h1>You are {{ page._game.player.wins }} and {{ page._game.player.losses }}</h1>
<div class="card-set">
<strong>
Dealer: {{ total(page._game.cards) if page._game.current_player == "computer" }}
</strong>
<ul class="playingCards simpleCards table">
<div class="hand-lineup">
{{ page._game.cards.each_with_index do |card, i| }}
{{ if i == 0 && page._game.current_player != "computer" }}
<li class="card back">*</li>
{{ else }}
<div class="dealer-cards">
<div class="card-set">
<strong>
Dealer: {{ total(page._game.cards) if page._game.current_player == "computer" }}
</strong>
<ul class="playingCards simpleCards table">
<div class="hand-lineup">
{{ page._game.cards.each_with_index do |card, i| }}
{{ if i == 0 && page._game.current_player != "computer" }}
<li class="card back">*</li>
{{ else }}
<:card rank="{{ card.rank }}"
suit="{{ card.suit }}"
/>
{{ end }}
{{ end }}
</div>
</ul>
</div>
</div>
<div class="player-cards">
<div class="card-set">
<strong>Your hand: {{ total(page._game.player.cards) }}</strong>
<ul class="playingCards simpleCards table">
<div class="hand-lineup">
{{ page._game.player.cards.each do |card| }}
<:card rank="{{ card.rank }}"
suit="{{ card.suit }}"
suit="{{ card.suit }}"
/>
{{ end }}
{{ end }}
</div>
</ul>
</div>
<div class="card-set">
<strong>Your hand: {{ total(page._game.player.cards) }}</strong>
<ul class="playingCards simpleCards table">
<div class="hand-lineup">
{{ page._game.player.cards.each do |card| }}
<:card rank="{{ card.rank }}"
suit="{{ card.suit }}"
/>
{{ end }}
</div>
</ul>
</div>
</ul>
</div>
</div>
{{ if total(page._game.player.cards) <= 21 && page._game.winner_string.blank? }}
<button class="btn btn-default" e-click="hit">Hit</button>
Expand Down
47 changes: 31 additions & 16 deletions spec/app/main/integration/games_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,47 @@
before { visit "/" }
describe "win/loss record" do
it "shows initial score" do
expect(page).to have_content("You are 0 and 0")
expect(page.text).to match(/You are \d and \d/)
end

it "tracks victories"
# the_page._game.player.wins = 1
# expect(page).to have_content("You are 1 and 0")
# end

it "tracks losses"
end

describe "dealer hand" do
it "shows the face-down card as an asterisk" do
expect(page).to have_content("*")
end

let(:dealer_cards) { find(".dealer-cards .card-set") }
it "does not display dealer's total" do
expect(page).to have_content("Dealer:")
expect(dealer_cards).to have_content("Dealer:")
# This will fail if the dealer has blackjack. Gotta stub.
expect(dealer_cards.text).to_not match(/Dealer: \d{1,2}/)
end
end

describe "player hand" do
it "shows the player's two cards"

let(:player_cards) { find(".player-cards .card-set") }
it "shows the player's total" do
expect(page.text).to match(/Your hand: \d{1,2}/)
expect(player_cards.text).to match(/Your hand: \d{1,2}/)
end
end

describe "hitting" do
let(:player_hand) { find(".player-cards .card-set .hand-lineup") }
it "gives the player a new card" do
expect{ click_button('Hit') }.
to change { player_hand.text.length }.by(4),
"Adds a space, rank, space, suit"
end
end

describe "staying" do
let(:dealer_cards) { find(".dealer-cards .card-set") }
let(:dealer_hand) { find(".dealer-cards .card-set .hand-lineup") }
it "reveals computer's hidden card" do
expect{ click_button("Stay") }.
to change{ dealer_hand.text.count("*") }.by(-1),
"The face-down card is an asterisk. On reveal, it's not."
end

it "shows the dealer total" do
click_button("Stay")
expect(dealer_cards.text).to match(/Dealer: \d{1,2}/)
end
end

Expand Down

0 comments on commit 9d7e84b

Please sign in to comment.