hooks.rb 2.26 KB
Newer Older
Joe Libipl's avatar
Joe Libipl committed
1
require 'tiny_tds'
2
require 'timeout'
3 4 5

Before do |scenario|
  # useful:
6
  # debug_msg "Scenario supports: #{(scenario.methods - Object.methods).inspect}"
7
end
8

9 10 11 12 13 14 15 16 17 18
Before ('@restore_config_file') do
  FileUtils.cp('test_env/test001/DragSpinExp.exe.config',
    'test_env/test001/DragSpinExp.exe.config.bak')
end

After ('@restore_config_file') do
  FileUtils.cp('test_env/test001/DragSpinExp.exe.config.bak',
    'test_env/test001/DragSpinExp.exe.config')
end

19
Before('@reset_server') do |scenario|
20
  # Kill the server if it's already running
21
  result = %x[taskkill /F /T /IM DragSpinExp.exe"]
22
  debug_msg "Result of taskkill: #{result}"
23
  @server_database = "minimal"
24
  # Reset the database
25 26 27
  result = %x[sqlcmd -S "#{ENV['DB_DATASERVER']}" -U "#{ENV['DB_USERNAME']}" \
    -P "#{ENV['DB_PASSWORD']}" -i EntireDB-#{@server_database}.sql \
    -o EntireDB-#{@server_database}.out -v MYDATABASE = "#{@server_database}"]
28
  debug_msg "Result of sqlcmd: #{result}"
29
  set_db_in_config(@server_database)
30
  # Start up the server
Joe Libipl's avatar
Joe Libipl committed
31
  result = start_server()
32
  # Wait for server to come up
33
  client = connect_to_db(@server_database)
34
  log_contains('Starting main game loop.')
35
end
Joe Libipl's avatar
Joe Libipl committed
36

Joe Libipl's avatar
Joe Libipl committed
37
After('@kill_server_after') do |scenario|
38 39
  # Kill the server
  result = %x[taskkill /F /T /IM DragSpinExp.exe"]
40
  debug_msg "Result of taskkill: #{result}"
41 42
end

Joe Libipl's avatar
Joe Libipl committed
43
After('@db_cleanup') do |scenario|
44
  client = connect_to_db(@server_database)
Joe Libipl's avatar
Joe Libipl committed
45
  result = client.execute("DELETE
46
    FROM [#{@server_database}].[dbo].[Account]
Joe Libipl's avatar
Joe Libipl committed
47 48
    WHERE account LIKE 'test%'
    AND email LIKE '%301days.com'")
49
  debug_msg "Rows deleted from [Account]: #{result.do}"
50 51 52
  player_tables = ["PlayerBelt","PlayerEffects","PlayerFlags","PlayerHeld","PlayerLocker",
    "PlayerQuests","PlayerRings","PlayerSack","PlayerSettings","PlayerSkills","PlayerSpells",
    "PlayerWearing","Player"]
53
  get_all_test_player_ids().each do |player_to_delete|
54
    debug_msg "Deleting player #{player_to_delete}"
Joe Libipl's avatar
Joe Libipl committed
55
    player_tables.each do |table|
Joe Libipl's avatar
Joe Libipl committed
56
      result = client.execute("DELETE
57
      FROM [#{@server_database}].[dbo].[#{table}]
Joe Libipl's avatar
Joe Libipl committed
58
      WHERE playerID = '#{player_to_delete}'")
59
      debug_msg "Rows deleted from [#{table}]: #{result.do}"
Joe Libipl's avatar
Joe Libipl committed
60
    end
Joe Libipl's avatar
Joe Libipl committed
61
  end
Joe Libipl's avatar
Joe Libipl committed
62
    result = client.execute("DELETE
63
    FROM [#{@server_database}].[dbo].[Log]")
64
  debug_msg "Rows deleted from [Log]: #{result.do}"
Joe Libipl's avatar
Joe Libipl committed
65
end