New game for :each spec
This commit is contained in:
parent
6f0f8e259a
commit
b4c8b3a6be
@ -3,8 +3,16 @@ include Warden::Test::Helpers
|
|||||||
Warden.test_mode!
|
Warden.test_mode!
|
||||||
|
|
||||||
feature 'Play a hand', type: :feature do
|
feature 'Play a hand', type: :feature do
|
||||||
before(:all) do
|
# TODO: Implement a player / seat order. scenario 'active player rotates after a valid hand'
|
||||||
|
## fails without a consistent seat order. Workaround is to create a new game for each scenario
|
||||||
|
## with before :each instead of :all
|
||||||
|
## When using :all, the order of @game.player_ids inexplicably changes
|
||||||
|
before(:each) do
|
||||||
@game = setup_game
|
@game = setup_game
|
||||||
|
end
|
||||||
|
|
||||||
|
before(:each) do
|
||||||
|
@game.reload
|
||||||
@player = @game.current_player
|
@player = @game.current_player
|
||||||
login_as(@player.user, scope: :user)
|
login_as(@player.user, scope: :user)
|
||||||
visit game_path @game
|
visit game_path @game
|
||||||
@ -17,45 +25,36 @@ feature 'Play a hand', type: :feature do
|
|||||||
scenario 'first play does not contain lowest card' do
|
scenario 'first play does not contain lowest card' do
|
||||||
# current_player plays hand not containing lowest card
|
# current_player plays hand not containing lowest card
|
||||||
# expect unsuccessful play message hand MUST contain lowest card
|
# expect unsuccessful play message hand MUST contain lowest card
|
||||||
# Click the lowest card checkbox
|
|
||||||
login_as(@game.current_player.user, scope: :user)
|
# Play the highest card
|
||||||
visit game_path @game
|
@card_to_play = @player.inventory.last
|
||||||
@card_to_play = @game.current_player.player_cards.order(:value).last
|
|
||||||
check @card_to_play.to_s
|
check @card_to_play.to_s
|
||||||
click_button 'Play Hand'
|
click_button 'Play Hand'
|
||||||
|
|
||||||
expect(page).to have_content "First hand must contain the lowest card: #{@game.lowest_card.to_s}"
|
expect(page).to have_content "First hand must contain the lowest card: #{@game.lowest_card.to_s}"
|
||||||
|
# No play to beat, because play was invalid
|
||||||
expect(@game.play_to_beat).to eq(nil)
|
expect(@game.play_to_beat).to eq(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Scenario: The first play must be the lowest dealt card
|
# Scenario: The first play must be the lowest dealt card
|
||||||
# Given: A new game and I am the holder of the lowest card
|
# Given: A new game and I am the holder of the lowest card
|
||||||
# When I play a hand containing the lowest card
|
# When I play a hand containing the lowest card
|
||||||
# Then I see a successful play message
|
# Then I see the hand to beat is this play
|
||||||
scenario 'first play contains lowest card' do
|
scenario 'first play contains lowest card' do
|
||||||
# create game with players
|
|
||||||
# current_player plays hand containing lowest card
|
|
||||||
# expect successful play message
|
|
||||||
login_as(@game.current_player.user, scope: :user)
|
|
||||||
visit game_path @game
|
|
||||||
# Click the lowest card checkbox
|
|
||||||
@card_to_play = @game.lowest_card
|
@card_to_play = @game.lowest_card
|
||||||
check @card_to_play.to_s
|
check @card_to_play.to_s
|
||||||
click_button 'Play Hand'
|
click_button 'Play Hand'
|
||||||
expect(page).to have_content(/Hand to beat.*#{@game.lowest_card.to_s}/)
|
expect(page).to have_content(/Hand to beat.*#{@game.lowest_card.to_s}/)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# Scenario: Played cards leave the players inventory
|
# Scenario: Played cards leave the players inventory
|
||||||
# Given I am the current player
|
# Given I am the current player
|
||||||
# When I play a hand
|
# When I play a hand
|
||||||
# Then the cards played should leave my inventory
|
# Then the cards played should leave my inventory
|
||||||
scenario 'played cards are removed from the players inventory' do
|
scenario 'played cards are removed from the players inventory' do
|
||||||
# Store initial state of players inventory
|
# Store initial state of players inventory
|
||||||
login_as(@game.current_player.user, scope: :user)
|
@player_inventory = @player.inventory.join(' ')
|
||||||
visit game_path @game
|
@card_to_play = @player.inventory.first
|
||||||
@player_inventory = @game.current_player.player_cards.order(:value).join(' ')
|
|
||||||
@player_inventory = @game.current_player.inventory.order(:value).join(' ')
|
|
||||||
@card_to_play = @game.current_player.player_cards.order(:value).first
|
|
||||||
check @card_to_play.to_s
|
check @card_to_play.to_s
|
||||||
click_button 'Play Hand'
|
click_button 'Play Hand'
|
||||||
# Played hand is rendered
|
# Played hand is rendered
|
||||||
@ -71,23 +70,24 @@ feature 'Play a hand', type: :feature do
|
|||||||
# When I play an invalid hand
|
# When I play an invalid hand
|
||||||
# Then the cards played should not leave my inventory
|
# Then the cards played should not leave my inventory
|
||||||
scenario 'invalid hand played cards are not removed from the players inventory' do
|
scenario 'invalid hand played cards are not removed from the players inventory' do
|
||||||
@game.reload
|
#@game.reload
|
||||||
# Store initial state of players inventory
|
# Store initial state of players inventory
|
||||||
@player_inventory = @game.current_player.inventory.order(:value).join(' ')
|
@player_inventory = @player.inventory.join(' ')
|
||||||
login_as(@game.current_player.user, scope: :user)
|
|
||||||
visit game_path @game
|
|
||||||
# Play invalid hand
|
|
||||||
@cards_to_play = []
|
|
||||||
@cards_to_play << @game.current_player.player_cards.order(:value).last
|
|
||||||
@cards_to_play << @game.current_player.player_cards.order(:value).first
|
|
||||||
@cards_to_play.map {|card| check card.to_s }
|
|
||||||
|
|
||||||
|
# Create invalid hand
|
||||||
|
@cards_to_play = []
|
||||||
|
@cards_to_play << @player.inventory.last
|
||||||
|
@cards_to_play << @player.inventory.first
|
||||||
|
|
||||||
|
# Select each card to play
|
||||||
|
@cards_to_play.map {|card| check card.to_s }
|
||||||
click_button 'Play Hand'
|
click_button 'Play Hand'
|
||||||
|
|
||||||
# Played hand is rendered
|
# Played hand is rendered
|
||||||
expect(page).to have_content("Invalid pair")
|
expect(page).to have_content("Invalid pair")
|
||||||
# Player inventory is rendered with played cards
|
# Player inventory is rendered with played cards
|
||||||
expect(page).to have_content(@player_inventory)
|
expect(page).to have_content(@player_inventory)
|
||||||
# Player inventory method does return played cards
|
# Player inventory method still returns played cards because the play was invalid
|
||||||
expect(@game.current_player.inventory.order(:value).join(' ')).to have_content(@card_to_play.to_s)
|
expect(@game.current_player.inventory.order(:value).join(' ')).to have_content(@card_to_play.to_s)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -96,15 +96,14 @@ feature 'Play a hand', type: :feature do
|
|||||||
# When I play a hand
|
# When I play a hand
|
||||||
# Then the next player becomes the current player
|
# Then the next player becomes the current player
|
||||||
scenario 'active player rotates after a valid hand' do
|
scenario 'active player rotates after a valid hand' do
|
||||||
@game.reload
|
|
||||||
login_as(@game.current_player.user, scope: :user)
|
|
||||||
visit game_path @game
|
|
||||||
@next_player_id = @game.next_player_id
|
@next_player_id = @game.next_player_id
|
||||||
@current_player_id = @game.current_player.id
|
@current_player_id = @player.id
|
||||||
@current_player_index = @game.players.index(@game.active_player)
|
@current_player_index = @game.player_ids.index(@game.active_player.id)
|
||||||
@card_to_play = @game.current_player.player_cards.order(:value).first
|
|
||||||
|
@card_to_play = @player.inventory.first
|
||||||
check @card_to_play.to_s
|
check @card_to_play.to_s
|
||||||
click_button 'Play Hand'
|
click_button 'Play Hand'
|
||||||
|
|
||||||
# reload the game object instance
|
# reload the game object instance
|
||||||
@game.reload
|
@game.reload
|
||||||
expect(page).to have_content(/Hand to beat.*#{@card_to_play.to_s}/)
|
expect(page).to have_content(/Hand to beat.*#{@card_to_play.to_s}/)
|
||||||
@ -122,9 +121,7 @@ feature 'Play a hand', type: :feature do
|
|||||||
# When I play an invalid hand
|
# When I play an invalid hand
|
||||||
# Then I see an invalid hand message
|
# Then I see an invalid hand message
|
||||||
scenario 'active player can not play an invalid hand' do
|
scenario 'active player can not play an invalid hand' do
|
||||||
@game.reload
|
#@game.reload
|
||||||
login_as(@game.current_player.user, scope: :user)
|
|
||||||
visit game_path @game
|
|
||||||
@cards_to_play = [@game.current_player.player_cards.order(:value).first.to_s, @game.current_player.player_cards.order(:value).last.to_s]
|
@cards_to_play = [@game.current_player.player_cards.order(:value).first.to_s, @game.current_player.player_cards.order(:value).last.to_s]
|
||||||
@cards_to_play.each do |card|
|
@cards_to_play.each do |card|
|
||||||
check card
|
check card
|
||||||
@ -145,7 +142,7 @@ feature 'Play a hand', type: :feature do
|
|||||||
# create game with players
|
# create game with players
|
||||||
# not_current_player plays a valid hand
|
# not_current_player plays a valid hand
|
||||||
# expect not to be able to submit a play
|
# expect not to be able to submit a play
|
||||||
@game.reload
|
#@game.reload
|
||||||
@inactive_player = @game.players.where.not(id: @game.current_player_id).first
|
@inactive_player = @game.players.where.not(id: @game.current_player_id).first
|
||||||
login_as(@inactive_player.user, scope: :user)
|
login_as(@inactive_player.user, scope: :user)
|
||||||
visit game_path @game
|
visit game_path @game
|
||||||
@ -158,8 +155,6 @@ feature 'Play a hand', type: :feature do
|
|||||||
# When I pass
|
# When I pass
|
||||||
# Then I see an successful pass message
|
# Then I see an successful pass message
|
||||||
scenario 'active player can pass' do
|
scenario 'active player can pass' do
|
||||||
login_as(@game.current_player.user, scope: :user)
|
|
||||||
visit game_path @game
|
|
||||||
@current_user = @game.current_player
|
@current_user = @game.current_player
|
||||||
click_button 'Pass'
|
click_button 'Pass'
|
||||||
expect(page).to have_content 'Successfully passed.'
|
expect(page).to have_content 'Successfully passed.'
|
||||||
@ -174,23 +169,21 @@ feature 'Play a hand', type: :feature do
|
|||||||
# And I am the player to beat
|
# And I am the player to beat
|
||||||
# Then I see an open table
|
# Then I see an open table
|
||||||
scenario 'active player to beat has open table' do
|
scenario 'active player to beat has open table' do
|
||||||
@game.reload
|
# play a card
|
||||||
login_as(@game.active_player.user, scope: :user)
|
@card_to_play = @player.inventory.first
|
||||||
visit game_path @game
|
|
||||||
@card_to_play = @game.lowest_card
|
|
||||||
@game.reload
|
|
||||||
check @card_to_play.to_s
|
check @card_to_play.to_s
|
||||||
click_button 'Play Hand'
|
click_button 'Play Hand'
|
||||||
|
|
||||||
|
expect(page).to have_content 'Hand to beat'
|
||||||
@game.reload
|
@game.reload
|
||||||
@game.control_player_id = @game.player_to_beat.id
|
expect(@game.player_to_beat).to eq @player
|
||||||
|
|
||||||
|
# set control player to player to beat
|
||||||
|
@game.control_player_id = @player.id
|
||||||
@game.save
|
@game.save
|
||||||
login_as(@game.active_player.user, scope: :user)
|
@game.reload
|
||||||
visit game_path @game
|
visit game_path @game
|
||||||
|
|
||||||
@game.player_to_beat.id == @game.active_player.id
|
|
||||||
|
|
||||||
login_as(@game.active_player.user, scope: :user)
|
|
||||||
visit game_path @game
|
|
||||||
# Expect active player should rotate
|
# Expect active player should rotate
|
||||||
expect(page).to have_button 'Play Hand'
|
expect(page).to have_button 'Play Hand'
|
||||||
#expect(@game.player_to_beat).to eq(@game.active_player)
|
#expect(@game.player_to_beat).to eq(@game.active_player)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user