Module: Treebis::Test::TestFileUtilsProxy

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

Instance Method Summary collapse

Instance Method Details

#test_cp_not_prettyObject



1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
# File 'lib/treebis.rb', line 1183

def test_cp_not_pretty
  src_dir = empty_tmpdir('foo')
  tgt_dir = empty_tmpdir('bar')

  task.new{
    mkdir_p
    write 'some-file.txt', "i am some text\n"
  }.on(src_dir).run

  task.new {
    from(src_dir)
    report_action :notice, "the below is not supposed to be pretty"
    file_utils.not_pretty!
    copy 'some-file.txt'
    mkdir_p 'emptoz'
    file_utils.pretty!
    report_action :notice, "the above was not pretty"
  }.on(tgt_dir).run

  act = dir_as_hash tgt_dir
  exp = {
    "some-file.txt"=>"i am some text\n",
    "emptoz" => {}
  }
  assert_equal(exp, act)
end

#test_custom_fileutils_implementationObject



1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
# File 'lib/treebis.rb', line 1226

def test_custom_fileutils_implementation
  task = self.task.new do
    from 'not there'
    copy 'doesnt even exist'
  end
  fu = Object.new
  class << fu
    def prefix; '_____' end
    def ui;    $stdout end
  end
  hi_there = false
  class << fu; self end.send(:define_method, :cp) do |*blah|
    hi_there = blah
  end
  task.file_utils = fu
  task.on('doesnt exist here').run
  exp =
  ["not there/doesnt even exist", "doesnt exist here/doesnt even exist"]
  act = hi_there[0..1]
  assert_equal exp, act
end

#test_patch_fileutilsObject



1211
1212
1213
1214
1215
1216
1217
1218
1219
# File 'lib/treebis.rb', line 1211

def test_patch_fileutils
  tmpdir = empty_tmpdir('oilspill')
  out, err = capture3 do
    file_utils.remove_entry_secure tmpdir+'/not-there'
    file_utils.mkdir_p tmpdir, :verbose => true
  end
  assert_match(/didn't exist.+not-there/, err)
  assert_match(/mkdir_p.+exists.+oilspill/, err)
end

#test_pretty_puts_cp_unexpected_outputObject



1220
1221
1222
1223
1224
1225
# File 'lib/treebis.rb', line 1220

def test_pretty_puts_cp_unexpected_output
  e = assert_raises(RuntimeError) do
    file_utils.send(:pretty_puts_cp, false, '', '')
  end
  assert_match(/unexpected out/, e.message)
end