Avoid js driver

This commit is contained in:
Jesse C. Fisher 2021-11-07 22:40:50 -08:00
parent fe136d1764
commit 13730bf979
12 changed files with 34 additions and 38 deletions

View File

@ -1,9 +1,10 @@
require 'rails_helper' require 'rails_helper'
RSpec.feature "EndOfGames", type: :feature, js: true do RSpec.feature "EndOfGames", type: :feature do
# Given I am in a started game # Given I am in a started game
before(:each) do 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 = setup_game
@game.reload @game.reload
@player = @game.controlling_player @player = @game.controlling_player

View File

@ -2,7 +2,7 @@
# As a visitor # As a visitor
# I want to quickly join a game # I want to quickly join a game
# So I can play # So I can play
feature 'Play now', :devise, js: true do feature 'Play now', :devise do
# Scenario: Visitor can play now # Scenario: Visitor can play now
# Given I am not signed in # Given I am not signed in
# When I click Play Now # When I click Play Now

View File

@ -2,7 +2,7 @@ require 'rails_helper'
include Warden::Test::Helpers include Warden::Test::Helpers
Warden.test_mode! Warden.test_mode!
feature 'Play a hand', type: :feature, js: true do feature 'Play a hand', type: :feature do
before(:each) do before(:each) do
@game = setup_game @game = setup_game
@game.reload @game.reload
@ -37,7 +37,7 @@ feature 'Play a hand', type: :feature, js: true do
# No play to beat, because play was invalid # No play to beat, because play was invalid
expect(@game.play_to_beat).to eq(nil) expect(@game.play_to_beat).to eq(nil)
# TODO: This scenario is causing other scenarios to fail unless we slow down here # TODO: This scenario is causing other scenarios to fail unless we slow down here
sleep 1 # sleep 1
# TODO: Flash messages # TODO: Flash messages
#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}"
end end
@ -48,7 +48,9 @@ feature 'Play a hand', type: :feature, js: true do
# Then I see the hand to beat is this play # Then I see the hand to beat is this play
scenario 'first play contains lowest card' do scenario 'first play contains lowest card' do
@card_to_play = @game.lowest_card @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' click_button 'Play Hand'
expect(cards_to_beat).to eq @game.lowest_card.to_s expect(cards_to_beat).to eq @game.lowest_card.to_s
end end
@ -166,11 +168,11 @@ feature 'Play a hand', type: :feature, js: true do
# Given I am the active player # Given I am the active player
# 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', js: true do
@current_user = @game.controlling_player @current_user = @game.controlling_player
click_button 'Pass' accept_confirm do
# binding.pry click_button 'Pass'
page.driver.browser.switch_to.alert.accept end
# click_button "pass_hand_button_#{@player.id}" # click_button "pass_hand_button_#{@player.id}"
## TODO: Flash messages ## TODO: Flash messages
expect(page).to have_content 'Successfully passed.' 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(page).to have_button 'Play Hand'
expect(@game.player_to_beat).to eq(@game.controlling_player) expect(@game.player_to_beat).to eq(@game.controlling_player)
debug
expect(page).to have_content "Hand to beat:\nNone" expect(page).to have_content "Hand to beat:\nNone"
end end

View File

@ -2,7 +2,7 @@
# As a visitor # As a visitor
# I want to sit in a seat # I want to sit in a seat
# So I can be at a table and play a game # 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 context "As a visitor" do
before(:each) do before(:each) do
@table = FactoryGirl.create :table @table = FactoryGirl.create :table
@ -62,7 +62,7 @@ feature 'Seats', :devise, js: true do
find_all(:button, "Sit") find_all(:button, "Sit")
end end
scenario 'visitor can leave the current game' do scenario 'visitor can leave the current game', js: true do
click_button 'Sit', match: :first click_button 'Sit', match: :first
expect(page).to have_content 'Guest' expect(page).to have_content 'Guest'
expect(page.text.scan('Guest').count).to eq 1 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 expect(page.text.scan(@user.email).count).to eq 1
end end
scenario 'user can leave the current game' do scenario 'user can leave the current game', js: true do
click_button 'Sit', match: :first click_button 'Sit', match: :first
expect(page).to have_content @user.email expect(page).to have_content @user.email
expect(page.text.scan(@user.email).count).to eq 1 expect(page.text.scan(@user.email).count).to eq 1

View File

@ -8,7 +8,7 @@ feature 'Table index', :devise do
# Given I am not signed in # Given I am not signed in
# When I click browse tables # When I click browse tables
# Then I see an index of 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 } 5.times { FactoryGirl.create :table }
visit root_path visit root_path
click_link 'Browse Tables' click_link 'Browse Tables'
@ -24,7 +24,7 @@ feature 'Table index', :devise do
# Given I am signed in # Given I am signed in
# When I click browse tables # When I click browse tables
# Then I see an index of 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 @user = FactoryGirl.create :user
signin(@user.email,'password') signin(@user.email,'password')

View File

@ -10,12 +10,12 @@ feature 'Table show', :devise do
click_link @table.title click_link @table.title
end end
scenario 'visitor can sit at the table', js: true do scenario 'visitor can sit at the table' do
click_button 'Sit', match: :first click_button 'Sit', match: :first
expect(page).to have_content "Guest" expect(page).to have_content "Guest"
end end
scenario 'visitor can join the current game', js: true do scenario 'visitor can join the current game' do
click_button 'Sit', match: :first click_button 'Sit', match: :first
expect(page).to have_content "Guest" expect(page).to have_content "Guest"
expect(page.text.scan('Guest').count).to eq 1 expect(page.text.scan('Guest').count).to eq 1
@ -42,14 +42,14 @@ feature 'Table show', :devise do
visit table_path @table visit table_path @table
end end
scenario 'user can sit at the table', js: true do scenario 'user can sit at the table' do
#TODO: Fix race condition #TODO: Fix race condition
expect(page).to have_content "Sit" expect(page).to have_content "Sit"
click_button 'Sit', match: :first click_button 'Sit', match: :first
expect(page).to have_content @user.email expect(page).to have_content @user.email
end 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" expect(page).to have_content "Sit"
click_button 'Sit', match: :first click_button 'Sit', match: :first
expect(page).to have_content @user.email expect(page).to have_content @user.email

View File

@ -2,7 +2,7 @@ require 'rails_helper'
include Warden::Test::Helpers include Warden::Test::Helpers
Warden.test_mode! Warden.test_mode!
feature 'Join a game', type: :feature, js: true do feature 'Join a game', type: :feature do
# before(:each) do # before(:each) do
# @game = setup_game # @game = setup_game
# @game.reload # @game.reload

View File

@ -2,7 +2,7 @@ require 'rails_helper'
include Warden::Test::Helpers include Warden::Test::Helpers
Warden.test_mode! Warden.test_mode!
feature 'Play a hand', type: :feature, js: true do feature 'Play a hand', type: :feature do
before(:each) do before(:each) do
@game = setup_visitor_game @game = setup_visitor_game
visit table_path @game.table visit table_path @game.table

View File

@ -7,7 +7,7 @@ feature 'Join game', :devise do
# Given I am not signed in # Given I am not signed in
# When I visit a joinable game # When I visit a joinable game
# Then I see a join button # 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 visit new_table_path
fill_in 'table_title', with: 'Test Game' fill_in 'table_title', with: 'Test Game'
click_button 'Create Table' click_button 'Create Table'
@ -16,7 +16,6 @@ feature 'Join game', :devise do
click_button 'Sit', match: :first click_button 'Sit', match: :first
#TODO: Fix this asynchronous race condition #TODO: Fix this asynchronous race condition
visit current_path visit current_path
page.save_screenshot
@table = Table.find(current_path.split('/').last) @table = Table.find(current_path.split('/').last)
@player = @table.current_game.players.last @player = @table.current_game.players.last
@playerComponent = page.find_all(".seat").first @playerComponent = page.find_all(".seat").first

View File

@ -7,9 +7,8 @@ feature 'Home page' do
# Given I am a visitor # Given I am a visitor
# When I visit the home page # When I visit the home page
# Then I see the main menu # Then I see the main menu
scenario 'visit the home page', js: true do scenario 'visit the home page' do
visit root_path 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 'Play Now'
expect(page).to have_link 'Browse Tables' expect(page).to have_link 'Browse Tables'
expect(page).to have_link 'Tutorial' expect(page).to have_link 'Tutorial'

View File

@ -1,9 +1,5 @@
RSpec.describe Table, type: :model do RSpec.describe Table, type: :model do
before :all do let(:table) { FactoryGirl.create(:table) }
@table = FactoryGirl.create(:table)
end
subject { @table }
it { should respond_to :title } it { should respond_to :title }
it { should respond_to :seats } it { should respond_to :seats }
@ -12,27 +8,27 @@ RSpec.describe Table, type: :model do
it { should respond_to :current_game } it { should respond_to :current_game }
it '#title returns a string' do it '#title returns a string' do
expect(@table.title).to match 'Test Table' expect(table.title).to match 'Test Table'
end end
it '#seats returns Seats collection' do 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 end
it '#users returns Users collection' do 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 end
it '#games returns Games collection' do 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 end
it '#current_game returns a Game' do it '#current_game returns a Game' do
expect(@table.current_game.class).to match Game expect(table.current_game.class).to match Game
end end
it "#seats returns 4 seats by default" do it "#seats returns 4 seats by default" do
expect(@table.seats.count).to eq 4 expect(table.seats.count).to eq 4
end end
end end

View File

@ -7,7 +7,7 @@ RSpec.configure do |config|
DatabaseCleaner.strategy = :transaction DatabaseCleaner.strategy = :transaction
end end
config.before(:each, js: true) do config.before(:each) do
DatabaseCleaner.strategy = :truncation DatabaseCleaner.strategy = :truncation
end end