Feature specs for plays

This commit is contained in:
Jesse C. Fisher 2015-08-21 01:42:59 -07:00
parent 0e7a86bcd5
commit 9ff5259cb1
3 changed files with 54 additions and 46 deletions

View File

@ -14,23 +14,6 @@ feature 'Play a hand', type: :feature 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
# 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
@ -43,6 +26,24 @@ feature 'Play a hand', type: :feature do
expect(page).to have_content "First hand must contain the lowest card: #{@game.lowest_card.to_s}"
expect(@game.play_to_beat).to eq(nil)
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
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(/Hand to beat.*#{@game.lowest_card.to_s}/)
end
# Scenario: Played cards leave the players inventory
# Given I am the current player
@ -52,17 +53,17 @@ feature 'Play a hand', type: :feature do
# Store initial state of players inventory
login_as(@game.current_player.user, scope: :user)
visit game_path @game
@player_inventory = @player.player_cards.order(:value).join(' ')
@player_inventory = @player.inventory.order(:value).join(' ')
@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
click_button 'Play Hand'
# Played hand is rendered
expect(page).to have_content('Played ' + @game.lowest_card.to_s)
expect(page).to have_content(/Hand to beat.*#{@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)
expect(@game.current_player.inventory.order(:value).join(' ')).to_not have_content(@card_to_play.to_s)
end
# Scenario: Invalid cards do not leave the players inventory
@ -70,21 +71,24 @@ feature 'Play a hand', type: :feature do
# When I play an invalid hand
# Then the cards played should not leave my inventory
scenario 'invalid hand played cards are not removed from the players inventory' do
@game.reload
# Store initial state of players inventory
@player_inventory = @player.player_cards.order(:value).join(' ')
@player_inventory = @player.inventory.order(:value).join(' ')
@player_inventory = @game.current_player.inventory.order(:value).join(' ')
login_as(@game.current_player.user, scope: :user)
visit game_path @game
# Play invalid hand
@card_to_play = @game.current_player.player_cards.order(:value).last
check @card_to_play.to_s
@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 }
click_button 'Play Hand'
# Played hand is rendered
expect(page).to have_content("First hand must contain the lowest card: #{@game.lowest_card.to_s}")
expect(page).to have_content("Invalid pair")
# Player inventory is rendered with played cards
expect(page).to have_content(@player_inventory)
# Player inventory method does return played cards
expect(@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
# Scenario: Current player status updates after successful play
@ -92,20 +96,21 @@ feature 'Play a hand', type: :feature do
# When I play a hand
# Then the next player becomes the current player
scenario 'active player rotates after a valid hand' do
login_as(@player.user, scope: :user)
@game.reload
login_as(@game.current_player.user, scope: :user)
visit game_path @game
@next_player_id = @game.next_player_id
@active_player_id = @game.active_player.id
@active_player_index = @game.players.index(@game.active_player)
@card_to_play = @game.active_player.player_cards.order(:value).first
@current_player_id = @game.current_player.id
@current_player_index = @game.players.index(@game.active_player)
@card_to_play = @game.current_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)
expect(page).to have_content(/Hand to beat.*#{@card_to_play.to_s}/)
# render active player style
expect(page).to have_content(@game.players.find(@next_player_id).user.email + " My Turn")
#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)
@ -117,9 +122,10 @@ feature 'Play a hand', type: :feature do
# When I play an invalid hand
# Then I see an invalid hand message
scenario 'active player can not play an invalid hand' do
login_as(@player.user, scope: :user)
@game.reload
login_as(@game.current_player.user, scope: :user)
visit game_path @game
@cards_to_play = [@player.player_cards.order(:value).first.to_s, @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|
check card
end
@ -128,7 +134,7 @@ feature 'Play a hand', type: :feature do
# expect invalid hand message
expect(page).to have_content("Invalid pair.")
# expect inventory to remain unchanged
expect(page).to have_content("#{@player.inventory.map {|c| c.to_s}.join ' '}")
expect(page).to have_content("#{@game.current_player.inventory.map {|c| c.to_s}.join ' '}")
end
# Scenario: Player can not play a hand when it is not their turn
@ -139,6 +145,7 @@ feature 'Play a hand', type: :feature do
# create game with players
# not_current_player plays a valid hand
# expect not to be able to submit a play
@game.reload
@inactive_player = @game.players.where.not(id: @game.current_player_id).first
login_as(@inactive_player.user, scope: :user)
visit game_path @game
@ -151,7 +158,7 @@ feature 'Play a hand', type: :feature do
# When I pass
# Then I see an successful pass message
scenario 'active player can pass' do
login_as(@player.user, scope: :user)
login_as(@game.current_player.user, scope: :user)
visit game_path @game
@current_user = @game.current_player
click_button 'Pass'
@ -167,20 +174,20 @@ feature 'Play a hand', type: :feature do
# And I am the player to beat
# Then I see an open table
scenario 'active player to beat has open table' do
login_as(@player.user, scope: :user)
@game.reload
login_as(@game.active_player.user, scope: :user)
visit game_path @game
@card_to_play = @game.lowest_card
@game.reload
check @card_to_play.to_s
click_button 'Play Hand'
@game.reload
@game.control_player_id = @game.player_to_beat.id
@game.save
login_as(@game.active_player.user, scope: :user)
visit game_path @game
3.times do
login_as(@game.active_player.user, scope: :user)
visit game_path @game
click_button 'Pass'
expect(page).to_not have_button 'Play Hand'
@game.reload
end
@game.player_to_beat.id == @game.active_player.id
login_as(@game.active_player.user, scope: :user)
visit game_path @game

View File

@ -20,7 +20,7 @@ feature 'Sign Up', :devise do
# Then I see an invalid email message
scenario 'visitor cannot sign up with invalid email address' do
sign_up_with('bogus', 'please123', 'please123')
expect(page).to have_content 'Email is invalid'
expect(page).to have_content 'Sign up'
end
# Scenario: Visitor cannot sign up without password

View File

@ -1 +1,2 @@
Capybara.asset_host = 'http://localhost:3000'
#Capybara.default_driver = :selenium