From 13730bf979b1259eb3909b543428fd54314d6221 Mon Sep 17 00:00:00 2001 From: "Jesse C. Fisher" Date: Sun, 7 Nov 2021 22:40:50 -0800 Subject: [PATCH] Avoid js driver --- spec/features/end_of_games_spec.rb | 5 +++-- spec/features/play_now_spec.rb | 2 +- spec/features/plays_spec.rb | 17 +++++++++-------- spec/features/seats/seats_sit_spec.rb | 6 +++--- spec/features/tables/table_index_spec.rb | 4 ++-- spec/features/tables/table_join_spec.rb | 8 ++++---- spec/features/users/user_join_game_spec.rb | 2 +- spec/features/visitor_plays_spec.rb | 2 +- spec/features/visitors/game_join_spec.rb | 3 +-- spec/features/visitors/home_page_spec.rb | 3 +-- spec/models/table_spec.rb | 18 +++++++----------- spec/support/database_cleaner.rb | 2 +- 12 files changed, 34 insertions(+), 38 deletions(-) diff --git a/spec/features/end_of_games_spec.rb b/spec/features/end_of_games_spec.rb index ad1a6c4..9d9681b 100644 --- a/spec/features/end_of_games_spec.rb +++ b/spec/features/end_of_games_spec.rb @@ -1,9 +1,10 @@ require 'rails_helper' -RSpec.feature "EndOfGames", type: :feature, js: true do +RSpec.feature "EndOfGames", type: :feature do # Given I am in a started game before(:each) do - page.driver.browser.manage.window.resize_to(1640, 1090) + # If test is unable to click correct card, use wider window + # page.driver.browser.manage.window.resize_to(1640, 1090) @game = setup_game @game.reload @player = @game.controlling_player diff --git a/spec/features/play_now_spec.rb b/spec/features/play_now_spec.rb index afc2a76..fac5158 100644 --- a/spec/features/play_now_spec.rb +++ b/spec/features/play_now_spec.rb @@ -2,7 +2,7 @@ # As a visitor # I want to quickly join a game # So I can play -feature 'Play now', :devise, js: true do +feature 'Play now', :devise do # Scenario: Visitor can play now # Given I am not signed in # When I click Play Now diff --git a/spec/features/plays_spec.rb b/spec/features/plays_spec.rb index 15ec9c2..76f0e15 100644 --- a/spec/features/plays_spec.rb +++ b/spec/features/plays_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' include Warden::Test::Helpers Warden.test_mode! -feature 'Play a hand', type: :feature, js: true do +feature 'Play a hand', type: :feature do before(:each) do @game = setup_game @game.reload @@ -37,7 +37,7 @@ feature 'Play a hand', type: :feature, js: true do # No play to beat, because play was invalid expect(@game.play_to_beat).to eq(nil) # TODO: This scenario is causing other scenarios to fail unless we slow down here - sleep 1 + # sleep 1 # TODO: Flash messages #expect(page).to have_content "First hand must contain the lowest card: #{@game.lowest_card.to_s}" end @@ -48,7 +48,9 @@ feature 'Play a hand', type: :feature, js: true do # Then I see the hand to beat is this play scenario 'first play contains lowest card' do @card_to_play = @game.lowest_card - find_card(@card_to_play).click(x: 0, y: 0) + # If test can't click card enable js and click coordinates + # find_card(@card_to_play).click(x: 0, y: 0) + find_card(@card_to_play).click click_button 'Play Hand' expect(cards_to_beat).to eq @game.lowest_card.to_s end @@ -166,11 +168,11 @@ feature 'Play a hand', type: :feature, js: true do # Given I am the active player # When I pass # Then I see an successful pass message - scenario 'active player can pass' do + scenario 'active player can pass', js: true do @current_user = @game.controlling_player - click_button 'Pass' - # binding.pry - page.driver.browser.switch_to.alert.accept + accept_confirm do + click_button 'Pass' + end # click_button "pass_hand_button_#{@player.id}" ## TODO: Flash messages expect(page).to have_content 'Successfully passed.' @@ -213,7 +215,6 @@ feature 'Play a hand', type: :feature, js: true do 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 diff --git a/spec/features/seats/seats_sit_spec.rb b/spec/features/seats/seats_sit_spec.rb index 367e5b9..a4f4ba0 100644 --- a/spec/features/seats/seats_sit_spec.rb +++ b/spec/features/seats/seats_sit_spec.rb @@ -2,7 +2,7 @@ # As a visitor # I want to sit in a seat # So I can be at a table and play a game -feature 'Seats', :devise, js: true do +feature 'Seats', :devise do context "As a visitor" do before(:each) do @table = FactoryGirl.create :table @@ -62,7 +62,7 @@ feature 'Seats', :devise, js: true do find_all(:button, "Sit") end - scenario 'visitor can leave the current game' do + scenario 'visitor can leave the current game', js: true do click_button 'Sit', match: :first expect(page).to have_content 'Guest' expect(page.text.scan('Guest').count).to eq 1 @@ -95,7 +95,7 @@ feature 'Seats', :devise, js: true do expect(page.text.scan(@user.email).count).to eq 1 end - scenario 'user can leave the current game' do + scenario 'user can leave the current game', js: true do click_button 'Sit', match: :first expect(page).to have_content @user.email expect(page.text.scan(@user.email).count).to eq 1 diff --git a/spec/features/tables/table_index_spec.rb b/spec/features/tables/table_index_spec.rb index 4177efc..7f86995 100644 --- a/spec/features/tables/table_index_spec.rb +++ b/spec/features/tables/table_index_spec.rb @@ -8,7 +8,7 @@ feature 'Table index', :devise do # Given I am not signed in # When I click browse tables # Then I see an index of tables - scenario 'I can see all the tables', js: true do + scenario 'I can see all the tables' do 5.times { FactoryGirl.create :table } visit root_path click_link 'Browse Tables' @@ -24,7 +24,7 @@ feature 'Table index', :devise do # Given I am signed in # When I click browse tables # Then I see an index of tables - scenario 'I can see all the tables', js: true do + scenario 'I can see all the tables' do @user = FactoryGirl.create :user signin(@user.email,'password') diff --git a/spec/features/tables/table_join_spec.rb b/spec/features/tables/table_join_spec.rb index cb3b129..6661621 100644 --- a/spec/features/tables/table_join_spec.rb +++ b/spec/features/tables/table_join_spec.rb @@ -10,12 +10,12 @@ feature 'Table show', :devise do click_link @table.title end - scenario 'visitor can sit at the table', js: true do + scenario 'visitor can sit at the table' do click_button 'Sit', match: :first expect(page).to have_content "Guest" end - scenario 'visitor can join the current game', js: true do + scenario 'visitor can join the current game' do click_button 'Sit', match: :first expect(page).to have_content "Guest" expect(page.text.scan('Guest').count).to eq 1 @@ -42,14 +42,14 @@ feature 'Table show', :devise do visit table_path @table end - scenario 'user can sit at the table', js: true do + scenario 'user can sit at the table' do #TODO: Fix race condition expect(page).to have_content "Sit" click_button 'Sit', match: :first expect(page).to have_content @user.email end - scenario 'user can join the current game', js: true do + scenario 'user can join the current game' do expect(page).to have_content "Sit" click_button 'Sit', match: :first expect(page).to have_content @user.email diff --git a/spec/features/users/user_join_game_spec.rb b/spec/features/users/user_join_game_spec.rb index 43d4a97..2e4926c 100644 --- a/spec/features/users/user_join_game_spec.rb +++ b/spec/features/users/user_join_game_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' include Warden::Test::Helpers Warden.test_mode! -feature 'Join a game', type: :feature, js: true do +feature 'Join a game', type: :feature do # before(:each) do # @game = setup_game # @game.reload diff --git a/spec/features/visitor_plays_spec.rb b/spec/features/visitor_plays_spec.rb index 89e1c6c..defa683 100644 --- a/spec/features/visitor_plays_spec.rb +++ b/spec/features/visitor_plays_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' include Warden::Test::Helpers Warden.test_mode! -feature 'Play a hand', type: :feature, js: true do +feature 'Play a hand', type: :feature do before(:each) do @game = setup_visitor_game visit table_path @game.table diff --git a/spec/features/visitors/game_join_spec.rb b/spec/features/visitors/game_join_spec.rb index c4b8405..beb2470 100644 --- a/spec/features/visitors/game_join_spec.rb +++ b/spec/features/visitors/game_join_spec.rb @@ -7,7 +7,7 @@ feature 'Join game', :devise do # Given I am not signed in # When I visit a joinable game # Then I see a join button - scenario 'visitor can join a game', js: true do + scenario 'visitor can join a game' do visit new_table_path fill_in 'table_title', with: 'Test Game' click_button 'Create Table' @@ -16,7 +16,6 @@ feature 'Join game', :devise do click_button 'Sit', match: :first #TODO: Fix this asynchronous race condition visit current_path - page.save_screenshot @table = Table.find(current_path.split('/').last) @player = @table.current_game.players.last @playerComponent = page.find_all(".seat").first diff --git a/spec/features/visitors/home_page_spec.rb b/spec/features/visitors/home_page_spec.rb index 91dad18..35f8778 100644 --- a/spec/features/visitors/home_page_spec.rb +++ b/spec/features/visitors/home_page_spec.rb @@ -7,9 +7,8 @@ feature 'Home page' do # Given I am a visitor # When I visit the home page # Then I see the main menu - scenario 'visit the home page', js: true do + scenario 'visit the home page' do visit root_path - page.save_screenshot('screenshot-' + Time.now.strftime("%Y-%m-%d %H%M") + '.png') expect(page).to have_link 'Play Now' expect(page).to have_link 'Browse Tables' expect(page).to have_link 'Tutorial' diff --git a/spec/models/table_spec.rb b/spec/models/table_spec.rb index acb5093..8bd6e74 100644 --- a/spec/models/table_spec.rb +++ b/spec/models/table_spec.rb @@ -1,9 +1,5 @@ RSpec.describe Table, type: :model do - before :all do - @table = FactoryGirl.create(:table) - end - - subject { @table } + let(:table) { FactoryGirl.create(:table) } it { should respond_to :title } it { should respond_to :seats } @@ -12,27 +8,27 @@ RSpec.describe Table, type: :model do it { should respond_to :current_game } it '#title returns a string' do - expect(@table.title).to match 'Test Table' + expect(table.title).to match 'Test Table' end it '#seats returns Seats collection' do - expect(@table.seats.class.to_s).to match "Seat::ActiveRecord_Associations_CollectionProxy" + expect(table.seats.class.to_s).to match "Seat::ActiveRecord_Associations_CollectionProxy" end it '#users returns Users collection' do - expect(@table.users.class.to_s).to match "User::ActiveRecord_Associations_CollectionProxy" + expect(table.users.class.to_s).to match "User::ActiveRecord_Associations_CollectionProxy" end it '#games returns Games collection' do - expect(@table.games.class.to_s).to match "Game::ActiveRecord_Associations_CollectionProxy" + expect(table.games.class.to_s).to match "Game::ActiveRecord_Associations_CollectionProxy" end it '#current_game returns a Game' do - expect(@table.current_game.class).to match Game + expect(table.current_game.class).to match Game end it "#seats returns 4 seats by default" do - expect(@table.seats.count).to eq 4 + expect(table.seats.count).to eq 4 end end diff --git a/spec/support/database_cleaner.rb b/spec/support/database_cleaner.rb index ac38e31..a2c605f 100644 --- a/spec/support/database_cleaner.rb +++ b/spec/support/database_cleaner.rb @@ -7,7 +7,7 @@ RSpec.configure do |config| DatabaseCleaner.strategy = :transaction end - config.before(:each, js: true) do + config.before(:each) do DatabaseCleaner.strategy = :truncation end