# Feature: Table show # As a visitor # I want to view a table # So I can sit and play a game feature 'Table show', :devise do context "As a visitor" do before(:each) do @table = FactoryGirl.create :table visit tables_path click_link @table.title end 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' do click_button 'Sit', match: :first expect(page).to have_content "Guest" expect(page.text.scan('Guest').count).to eq 1 end # scenario 'visitor can leave the current game', js: true do scenario 'visitor can leave the current game' do click_button 'Sit', match: :first expect(page).to have_content "Guest" expect(page.text.scan('Guest').count).to eq 1 # accept_confirm do click_button 'Stand', match: :first # end expect(page.find('.seat.position-1')).to have_content "Sit" expect(page.text.scan('Guest').count).to eq 0 end end context "As a user" do before(:each) do @table = FactoryGirl.create :table @user = FactoryGirl.create :user signin(@user.email, @user.password) visit table_path @table end 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' do expect(page).to have_content "Sit" click_button 'Sit', match: :first expect(page).to have_content @user.email expect(page.text.scan(@user.email).count).to eq 1 end # scenario 'user can leave the current game', js: true do scenario 'user can leave the current game' do expect(page).to have_content "Sit" click_button 'Sit', match: :first expect(page).to have_content @user.email expect(page.text.scan(@user.email).count).to eq 1 # accept_confirm do click_button 'Stand', match: :first # end expect(page.find('.seat.position-1')).to have_content "Sit" expect(page.text.scan(@user.email).count).to eq 0 end end end