Update specs

This commit is contained in:
Jesse C. Fisher 2021-07-07 23:14:13 -07:00
parent e3602f367c
commit ff00434945
10 changed files with 34 additions and 22 deletions

View File

@ -3,6 +3,7 @@ require 'rails_helper'
RSpec.feature "EndOfGames", type: :feature, js: true do
# Given I am in a started game
before(:each) do
page.driver.browser.manage.window.resize_to(1640, 1090)
@game = setup_game
@game.reload
@player = @game.controlling_player

View File

@ -16,6 +16,7 @@ feature 'Play now', :devise, js: true do
end
it 'creates and joins a new game' do
#TODO: Fix race condition
sleep 2
expect(page).to have_content "Hand to beat"
#Game title derived from visitor soft_token
expect(page).to have_content "#{Game.last.players.first.soft_token[0..4]}"
@ -29,7 +30,7 @@ feature 'Play now', :devise, js: true do
FactoryGirl.create :game
@game = Game.last
visit root_path
expect(Game.all.count).to eq 1
# expect(Game.all.count).to eq 1
click_link 'Play Now'
end
@ -38,13 +39,13 @@ feature 'Play now', :devise, js: true do
#expect(page).to have_content "Test Game"
expect(page).to have_content "Hand to beat"
#it 'is located at the correct url' do
expect(current_path).to eq game_path(@game)
expect(current_path).to eq table_path(@game.table)
#it 'shows the visitor as a player' do
@player = @game.players.last
@playerComponent = page.find("#player-1")
@playerComponent = page.find_all(".seat").first
#TODO: have_content @player.display_name
expect(@playerComponent.text).to have_content("Guest#{@player.soft_token[0..5]}")
expect(@playerComponent.text).to have_content("Guest#{@player.soft_token[0..4]}")
#it 'shows other players' do
# Add another player
@ -61,7 +62,7 @@ feature 'Play now', :devise, js: true do
visit current_path
visit current_path
visit current_path
expect(page).to have_content 'Inventory'
expect(page).to have_content 'Hand to beat'
expect(Game.all.count).to eq 1
end
end

View File

@ -8,17 +8,19 @@ feature 'Join game', :devise do
# When I visit a joinable game
# Then I see a join button
scenario 'visitor can join a game', js: true do
visit new_game_path
fill_in 'game_title', with: 'Test Game'
click_button 'Create Game'
visit new_table_path
fill_in 'table_title', with: 'Test Game'
click_button 'Create Table'
puts current_path
expect(page).to have_button("Sit")
click_button 'Sit', match: :first
#TODO: Fix this asynchronous race condition
visit current_path
@game = Game.find(current_path.split('/').last)
@player = @game.players.last
@playerComponent = page.find("#player-1")
expect(@playerComponent.text).to have_content("Guest#{@player.soft_token[0..5]}")
page.save_screenshot
@table = Table.find(current_path.split('/').last)
@player = @table.current_game.players.last
@playerComponent = page.find_all(".seat").first
expect(@playerComponent.text).to have_content("Guest#{@player.soft_token[0..4]}")
end
scenario 'visitor can join a game in progress' do

View File

@ -7,8 +7,9 @@ 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' do
scenario 'visit the home page', js: true 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'

View File

@ -20,14 +20,15 @@ feature 'Navigation links', :devise do
scenario 'follow navigation links', js: :true do
visit root_path
@links = {
'Play Now': '"/games/1"',
'Play Now': '"/tables/1"',
'Browse Tables': 'tables_path',
#'Tutorial': 'tutorial_path'
}
@links.each do |link|
click_link link[0]
#TODO: Remove race condition
sleep 1
sleep 4
page.save_screenshot
expect(page.current_path).to eq(eval(link[1]))
visit root_path
end

View File

@ -1,3 +1,4 @@
RSpec.describe Play, type: :model do
before(:each) do
@game = setup_game

View File

@ -49,4 +49,5 @@ RSpec.configure do |config|
config.infer_spec_type_from_file_location!
config.include GameHelpers
config.include PlayHelpers
end

View File

@ -1,15 +1,17 @@
module GameHelpers
def setup_game
# Default game has 4 players
game = FactoryGirl.create :game
table = FactoryGirl.create :table
game = table.current_game
user1 = FactoryGirl.create :user
user2 = FactoryGirl.create :user
user3 = FactoryGirl.create :user
user4 = FactoryGirl.create :user
game.seats[0].sit user1
game.seats[1].sit user2
game.seats[2].sit user3
game.seats[3].sit user4
table.seats[0].sit user1
table.seats[1].sit user2
table.seats[2].sit user3
table.seats[3].sit user4
# binding.pry
game.start
return game
end

View File

@ -1,4 +1,4 @@
module Models
# module Models
module PlayHelpers
def create_hand(count, type)
cards = []
@ -32,4 +32,4 @@ module Models
return cards
end
end
end
# end

View File

@ -10,6 +10,8 @@ module Features
def signin(email, password)
visit new_user_session_path
sleep 2
page.save_screenshot
fill_in 'Email', with: email
fill_in 'Password', with: password
click_button 'Log in'