diff --git a/.gitignore b/.gitignore index 746a98b..837edd8 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ # Corrections? Improvements? Create a GitHub issue: # http://github.com/RailsApps/rails-composer/issues #---------------------------------------------------------------------------- +/spec/reports/ # ctags tags diff --git a/app/views/tables/_seat.html.haml b/app/views/tables/_seat.html.haml index a78e18f..c17c899 100644 --- a/app/views/tables/_seat.html.haml +++ b/app/views/tables/_seat.html.haml @@ -11,7 +11,7 @@ sit_seat_path(seat) - if seat.player - .player{class: @game.controlling_player == seat.player ? "taking-turn" : "", + .player{id: "player-#{seat.player.id}", class: @game.controlling_player == seat.player ? "taking-turn" : "", data: {soft_token: seat.player.soft_token} } .user-name= seat.player.display_name - if @game.started? @@ -31,7 +31,7 @@ = check_box_tag 'player_card_ids[]', card.id, false, - data: {value: card.id, card_name: card.rank.gsub('10','J') .gsub('12','Q') .gsub('13','K') .gsub('14','A') .gsub('15','2') + ' ' + card.suit} + data: {value: card.id, card_name: card.rank.gsub('11','J') .gsub('12','Q') .gsub('13','K') .gsub('14','A') .gsub('15','2') + ' ' + card.suit} -# %input{form: "player_controls_" + card.player_id.to_s, type: "checkbox", diff --git a/spec/features/play_now_spec.rb b/spec/features/play_now_spec.rb index 3c7f123..b384dfe 100644 --- a/spec/features/play_now_spec.rb +++ b/spec/features/play_now_spec.rb @@ -27,8 +27,8 @@ feature 'Play now', :devise, js: true do context 'visitor joins an existing game' do before do - FactoryGirl.create :game - @game = Game.last + FactoryGirl.create :table + @table = Table.last visit root_path # expect(Game.all.count).to eq 1 click_link 'Play Now' @@ -37,9 +37,9 @@ feature 'Play now', :devise, js: true do it 'shows and starts the game' do #TODO: Deprecated it shows the game title #expect(page).to have_content "Test Game" - expect(page).to have_content "Hand to beat" + # expect(page).to have_content "Hand to beat" #it 'is located at the correct url' do - expect(current_path).to eq table_path(@game.table) + # expect(current_path).to eq table_path(@table) #it 'shows the visitor as a player' do @player = @game.players.last @@ -55,6 +55,7 @@ feature 'Play now', :devise, js: true do #TODO: Remove race condition visit current_path expect(page).to have_content @user2.display_name + game_count = Game.all.count #it 'the game is startable' do click_button 'Start' #TODO: Remove race condition @@ -63,7 +64,7 @@ feature 'Play now', :devise, js: true do visit current_path visit current_path expect(page).to have_content 'Hand to beat' - expect(Game.all.count).to eq 1 + expect(Game.all.count).to eq (game_count + 1) end end end diff --git a/spec/features/plays_spec.rb b/spec/features/plays_spec.rb index 8924256..15ec9c2 100644 --- a/spec/features/plays_spec.rb +++ b/spec/features/plays_spec.rb @@ -61,6 +61,7 @@ feature 'Play a hand', type: :feature, js: true do # Store initial state of players inventory @player_inventory = @player.inventory.join(' ') @card_to_play = @player.inventory.first + expect(page).to have_css("#inventory [data-card-name='#{@card_to_play.to_s}']") find_card(@card_to_play).click click_button 'Play Hand' #wait_for_ajax @@ -68,8 +69,7 @@ feature 'Play a hand', type: :feature, js: true do # Played hand is rendered expect(cards_to_beat).to eq @game.lowest_card.to_s # Player inventory is rendered without played cards - #TODO: Deprecated have_content for inventory. Write new expectation. - expect(page.find("#player_controls_#{@player.id}")).to_not have_content(@card_to_play.to_s) + expect(page).not_to have_css("#inventory [data-card-name='#{@card_to_play.to_s}']") end # Scenario: Invalid cards do not leave the players inventory @@ -87,16 +87,15 @@ feature 'Play a hand', type: :feature, js: true do @cards_to_play << @player.inventory.first # Select each card to play - @cards_to_play.map {|card| find("[data-card-name='#{card.to_s}'] ~ img").click } - #click_button 'Play Hand' - click_button "play_hand_button_#{@player.id}" + @cards_to_play.map {|card| find("[data-card-name='#{card.to_s}']").click } + click_button 'Play Hand' # Played hand is rendered # TODO: Flash messages - #expect(page).to have_content("Invalid pair") + expect(page).to have_content("Invalid pair") # Player inventory is rendered with played cards @initial_player_inventory.each do |card| - expect(page).to have_selector("[data-card-name='#{card.to_s}'] ~ img") + expect(page).to have_css("#inventory input[data-card-name='#{card.to_s}']") end # TODO: This scenario is causing other scenarios to fail unless we slow down here sleep 1 @@ -121,7 +120,7 @@ feature 'Play a hand', type: :feature, js: true do click_button 'Play Hand' expect(page).to have_content "Hand to beat" expect(cards_to_beat).to eq @card_to_play.to_s - expect(page).to have_selector("#player-#{@next_player_id}.has-control") + expect(page).to have_selector("#player-#{@next_player_id}.taking-turn") end # Scenario: Player can not play an invalid hand on their turn @@ -132,17 +131,16 @@ feature 'Play a hand', type: :feature, js: true do #@game.reload @cards_to_play = [@game.controlling_player.player_cards.order(:value).first.to_s, @game.controlling_player.player_cards.order(:value).last.to_s] @cards_to_play.each do |card| - find("[data-card-name='#{card.to_s}'] ~ img").click + find("[data-card-name='#{card.to_s}']").click end - #click_button 'Play Hand' - click_button "play_hand_button_#{@player.id}" + click_button 'Play Hand' # controlling_player plays an invalid hand # expect invalid hand message #:TODO: Flash messages #expect(page).to have_content("Invalid pair.") # expect inventory to remain unchanged @game.controlling_player.inventory.each do |card| - expect(page).to have_selector("[data-card-name='#{card.to_s}'] ~ img") + expect(page).to have_selector("[data-card-name='#{card.to_s}']") end # TODO: This scenario is causing other scenarios to fail unless we slow down here sleep 1 @@ -159,10 +157,9 @@ feature 'Play a hand', type: :feature, js: true do @non_controlling_player = @game.players.where.not(id: @game.controlling_player_id).first login_as(@non_controlling_player.user, scope: :user) visit game_path @game - #expect(page).to_not have_button 'Play Hand' - elem = page.find "input#play_hand_button_#{@non_controlling_player.id}" - expect(elem.disabled?).to be true - # TODO: Submit a POST request + expect(page).to_not have_button 'Play Hand' + # click_button 'Play Hand' + # expect(page).to have_content "not your turn" end # Scenario: Player can pass when it is their turn @@ -171,14 +168,16 @@ feature 'Play a hand', type: :feature, js: true do # Then I see an successful pass message scenario 'active player can pass' do @current_user = @game.controlling_player - #click_button 'Pass' - click_button "pass_hand_button_#{@player.id}" + click_button 'Pass' + # binding.pry + page.driver.browser.switch_to.alert.accept + # click_button "pass_hand_button_#{@player.id}" ## TODO: Flash messages - #expect(page).to have_content 'Successfully passed.' + expect(page).to have_content 'Successfully passed.' # Expect active player should rotate - #expect(page).to_not have_button 'Play Hand' - elem = page.find "input#play_hand_button_#{@player.id}" - expect(elem.disabled?).to be false + # expect(page).to_not have_button 'Play Hand' + # elem = page.find "input#play_hand_button_#{@player.id}" + # expect(elem.disabled?).to be false @new_controlling_player = @game.controlling_player expect(@game.controlling_player).to_not eq(@controlling_player) @@ -195,9 +194,9 @@ feature 'Play a hand', type: :feature, js: true do @game.reload @player = @game.controlling_player @card_to_play = @player.inventory.first - find("[data-card-name='#{@card_to_play.to_s}'] ~ img").click - #click_button 'Play Hand' - click_button "play_hand_button_#{@player.id}" + find("[data-card-name='#{@card_to_play.to_s}']").click + click_button 'Play Hand' + # click_button "play_hand_button_#{@player.id}" #TODO: Fix race condition sleep 4 @@ -210,13 +209,12 @@ feature 'Play a hand', type: :feature, js: true do @game.controlling_player_id = @player.id @game.save @game.reload - visit game_path @game + visit table_path @game.table - # Expect active player should rotate - #expect(page).to have_button 'Play Hand' - expect(page).to have_button "play_hand_button_#{@player.id}" - #expect(@game.player_to_beat).to eq(@game.controlling_player) - expect(page).to have_content 'Hand to beat: None' + expect(page).to have_button 'Play Hand' + expect(@game.player_to_beat).to eq(@game.controlling_player) + debug + expect(page).to have_content "Hand to beat:\nNone" end # Scenario: Player wins the game @@ -225,10 +223,13 @@ feature 'Play a hand', type: :feature, js: true do # And I am the first player to do so # Then I see a 1st place winner message scenario 'first place winner' do + @card_to_play = @player.inventory.first + @player.inventory[1..12].map{|card| card.destroy} # play last card - pending "TBD" + find_card(@card_to_play).click + click_button 'Play Hand' expect(@player.inventory.count).to eq 0 - expect(page).to have_content "Winner: #{@player.display_name}" + expect(page).to have_content "Player #{@player.display_name} wins!" end diff --git a/spec/support/helpers/game_helpers.rb b/spec/support/helpers/game_helpers.rb index 8a658de..662ff0a 100644 --- a/spec/support/helpers/game_helpers.rb +++ b/spec/support/helpers/game_helpers.rb @@ -1,4 +1,10 @@ module GameHelpers + def debug + puts page.html + page.save_screenshot + # binding.pry + end + def setup_game # Default game has 4 players table = FactoryGirl.create :table