Module: Treebis::Test::TestTempdirAndTasksAndCopy

Included in:
TestCase
Defined in:
lib/treebis.rb

Instance Method Summary collapse

Instance Method Details

#test_can_open_same_name_in_different_task_setsObject



1439
1440
1441
1442
# File 'lib/treebis.rb', line 1439

def test_can_open_same_name_in_different_task_sets
  Treebis::TaskSet.new.task(:same){}
  Treebis::TaskSet.new.task(:same){}
end

#test_cant_reopen_tasksObject



1430
1431
1432
1433
1434
1435
1436
1437
1438
# File 'lib/treebis.rb', line 1430

def test_cant_reopen_tasks
  tasks = Treebis::TaskSet.new
  tasks.task(:same){}
  e = assert_raises(RuntimeError) do
    tasks.task(:same){}
  end
  exp = "can't reopen task: :same"
  assert_equal(exp, e.message)
end

#test_copy_one_fileObject



1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
# File 'lib/treebis.rb', line 1475

def test_copy_one_file
  the_tmpdir = tmpdir
  # doc start
  content = "i am the content of\na file called baz.txt\n"
  File.open(the_tmpdir+'/baz.txt','w+') do |fh|
    fh.puts(content)
  end
  tasks = Treebis::TaskSet.new
  tasks.task(:default) do
    mkdir_p_unless_exists # makes output dir referred to in on() below
    from the_tmpdir # the source directory
    copy('./baz.txt')
  end
  tasks[:default].on(the_tmpdir+'/out-dir/').run()
  output = File.read(the_tmpdir+'/out-dir/baz.txt')
  # doc stop
  assert_equal(content, output)
end

#test_copy_one_file_a_bunch_of_tmpdir_crapObject



1466
1467
1468
1469
1470
1471
1472
1473
1474
# File 'lib/treebis.rb', line 1466

def test_copy_one_file_a_bunch_of_tmpdir_crap
  out_dir = tmpdir+'/out-dir'
  src_file = tmpdir+'/baz.txt'
  file_utils.remove_entry_secure(out_dir) if File.exist?(out_dir)
  file_utils.remove_entry_secure(src_file) if File.exist?(src_file)
  self.class.instance_variable_set('@tmpdir',nil)
  tmpdir # gets to a hard to reach line
  test_copy_one_file
end

#test_copy_one_file_almost_nothing_existObject



1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
# File 'lib/treebis.rb', line 1452

def test_copy_one_file_almost_nothing_exist
  out_dir = tmpdir+'/out-dir'
  src_file = tmpdir+'/baz.txt'
  per_file = self.class.dotfile_path_to_write_to
  file_utils.remove_entry_secure(out_dir) if File.exist?(out_dir)
  file_utils.remove_entry_secure(src_file) if File.exist?(src_file)
  if File.exist?(per_file)
    struct = JSON.parse(File.read(per_file))
    if File.exist?(struct["tmpdir"])
      file_utils.remove_entry_secure(struct["tmpdir"])
    end
  end
  test_copy_one_file
end

#test_copy_one_file_nothing_existObject



1443
1444
1445
1446
1447
1448
1449
1450
1451
# File 'lib/treebis.rb', line 1443

def test_copy_one_file_nothing_exist
  out_dir = tmpdir+'/out-dir'
  src_file = tmpdir+'/baz.txt'
  per_file = self.class.dotfile_path_to_write_to
  file_utils.remove_entry_secure(out_dir) if File.exist?(out_dir)
  file_utils.remove_entry_secure(src_file) if File.exist?(src_file)
  file_utils.remove_entry_secure(per_file) if File.exist?(per_file)
  test_copy_one_file
end