142 lines
5.3 KiB
Ruby
142 lines
5.3 KiB
Ruby
require 'rails_helper'
|
|
include Warden::Test::Helpers
|
|
Warden.test_mode!
|
|
|
|
feature 'Play a hand', type: :feature do
|
|
after(:each) do
|
|
Warden.test_reset!
|
|
end
|
|
|
|
# Scenario: The first play must be the lowest dealt card
|
|
# Given: A new game and I am the holder of the lowest card
|
|
# When I play a hand containing the lowest card
|
|
# Then I see a successful play message
|
|
scenario 'first play contains lowest card' do
|
|
# create game with players
|
|
# current_player plays hand containing lowest card
|
|
# expect successful play message
|
|
|
|
# TODO: extract game setup to a factory
|
|
game = setup_game
|
|
login_as(game.current_player.user, scope: :user)
|
|
visit game_path game
|
|
# Click the lowest card checkbox
|
|
@card_to_play = game.lowest_card
|
|
check @card_to_play.to_s
|
|
click_button 'Play Hand'
|
|
expect(page).to have_content('Played ' + game.lowest_card.to_s)
|
|
end
|
|
|
|
scenario 'first play does not contain lowest card' do
|
|
# current_player plays hand not containing lowest card
|
|
# expect unsuccessful play message hand MUST contain lowest card
|
|
game = setup_game
|
|
login_as(game.current_player.user, scope: :user)
|
|
visit game_path game
|
|
# Click the lowest card checkbox
|
|
@card_to_play = game.current_player.player_cards.order(:value).last
|
|
check @card_to_play.to_s
|
|
click_button 'Play Hand'
|
|
expect(page).to have_content
|
|
"First hand must contain the lowest card: #{game.lowest_card.to_s}"
|
|
end
|
|
|
|
# Scenario: Played cards leave the players inventory
|
|
# Given I am the current player
|
|
# When I play a hand
|
|
# Then the cards played should leave my inventory
|
|
scenario 'played cards are removed from the players inventory' do
|
|
game = setup_game
|
|
# Store initial state of players inventory
|
|
@player = game.current_player
|
|
@player_inventory = @player.player_cards.order(:value).join(' ')
|
|
@player_inventory = @player.inventory.order(:value).join(' ')
|
|
login_as(game.current_player.user, scope: :user)
|
|
visit game_path game
|
|
@card_to_play = game.current_player.player_cards.order(:value).first
|
|
check @card_to_play.to_s
|
|
click_button 'Play Hand'
|
|
# Played hand is rendered
|
|
expect(page).to have_content('Played ' + game.lowest_card.to_s)
|
|
# Player inventory is rendered without played cards
|
|
expect(page).to have_content(@player_inventory.gsub(@card_to_play.to_s,''))
|
|
# Player inventory method does not return played cards
|
|
expect(@player.inventory.order(:value).join(' ')).to_not have_content(@card_to_play.to_s)
|
|
end
|
|
|
|
# Scenario: Current player status updates after successful play
|
|
# Given I am the current player
|
|
# When I play a hand
|
|
# Then the next player becomes the current player
|
|
scenario 'active player rotates after a valid hand' do
|
|
@game = setup_game
|
|
login_as(@game.active_player.user, scope: :user)
|
|
@next_player_id = @game.next_player_id
|
|
@active_player_id = @game.active_player.id
|
|
@active_player_index = @game.players.index(@game.active_player)
|
|
visit game_path @game
|
|
@card_to_play = @game.active_player.player_cards.order(:value).first
|
|
check @card_to_play.to_s
|
|
click_button 'Play Hand'
|
|
# reload the game object instance
|
|
@game.reload
|
|
expect(page).to have_content('Played ' + @card_to_play.to_s)
|
|
|
|
# render active player style
|
|
expect(page).to have_content(@game.players.find(@next_player_id).user.email + " My Turn")
|
|
|
|
# next player is now the active player
|
|
expect(@game.active_player_id).to_not eq(@active_player_id)
|
|
expect(@game.active_player_id).to eq(@next_player_id)
|
|
end
|
|
|
|
# Scenario: Player can play a valid hand on their turn
|
|
# Given I am the active player
|
|
# And the last played card was a single card
|
|
# When I play a valid hand of one higher card
|
|
# Then I see a successful play message
|
|
scenario 'active player can play a valid hand' do
|
|
skip 'to be implemented'
|
|
# create game with players
|
|
game = setup_game
|
|
# current_player plays the lowest card
|
|
login_as(game.current_player.user, scope: :user)
|
|
visit game_path game
|
|
@card_to_play = game.lowest_card
|
|
check @card_to_play.to_s
|
|
click_button 'Play Hand'
|
|
expect(page).to have_content('Played ' + game.lowest_card.to_s)
|
|
# next player plays a valid hand
|
|
login_as(game.current_player.user, scope: :user)
|
|
visit game_path game
|
|
expect(page).to have_content('Played ' + game.lowest_card.to_s)
|
|
@card_to_play = game.current_player.player_cards.order(:value).first
|
|
check @card_to_play.to_s
|
|
click_button 'Play Hand'
|
|
expect(page).to have_content('Played ' + @card_to_play.to_s)
|
|
# expect successful play message
|
|
end
|
|
|
|
# Scenario: Player can not play an invalid hand on their turn
|
|
# Given I am the active player
|
|
# When I play an invalid hand
|
|
# Then I see an invalid hand message
|
|
scenario 'active player can play a valid hand' do
|
|
# create game with players
|
|
# current_player plays an invalid hand
|
|
# expect invalid hand message
|
|
skip 'to be implemented'
|
|
end
|
|
|
|
# Scenario: Player can not play a hand when it is not their turn
|
|
# Given I am not the active player
|
|
# When I play a hand
|
|
# Then I see an unsuccessful play message
|
|
scenario 'inactive player can not play a hand' do
|
|
# create game with players
|
|
# not_current_player plays a valid hand
|
|
# expect unsuccessful play message
|
|
skip 'to be implemented'
|
|
end
|
|
end
|