thirteen-tien-len/spec/features/bots/bot_play_spec.rb

44 lines
1.5 KiB
Ruby

# Feature: Bot takes turns
# As a player
# I want bots to take turns
# So I can play against the computer
feature 'Bot takes turn', type: :feature do
before(:each) do
@table = FactoryGirl.create :table
@game = @table.current_game
visit table_path @table
end
scenario 'bot player passes' do
@button = page.find_button('+ Bot', match: :first).click
expect(page).to have_content "BotPlayer"
@button = page.find_button('Sit', match: :first).click
click_button "Start"
# click_button 'Pass'
bot_player = @game.players.first
# set bot inventory value low so has to pass
# kind of hacky
bot_player.inventory.map{|i| i.value = 2; i.save}
@game = @table.current_game
@card_to_play = @game.controlling_player.inventory.first
find("[data-card-name='#{@card_to_play.to_s}']").click
click_button 'Play Hand'
expect(page).to have_content "#{bot_player.display_name} passed."
end
scenario 'bot player plays single' do
@button = page.find_button('+ Bot', match: :first).click
expect(page).to have_content "BotPlayer"
@button = page.find_button('Sit', match: :first).click
click_button "Start"
@game = @table.current_game
if @game.controlling_player.soft_token == page.current_user.soft_token
@card_to_play = @game.controlling_player.inventory.first
find("[data-card-name='#{@card_to_play.to_s}']").click
click_button 'Play Hand'
end
expect(@game.play_to_beat.player.is_bot?).to eq true
expect(@game.play_to_beat.hand_type).to eq "single"
end
end