Module: Treebis::Test::TestPatch

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

Instance Method Summary collapse

Instance Method Details

#test_patch_fails ⇒ Object



1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
# File 'lib/treebis.rb', line 1261

def test_patch_fails
  src = empty_tmpdir 'patch/evil'
  task.new do
    write "badly-formed-patch-file.diff", <<-P
      i am not a good patch
    P
  end.on(src).run

  tgt = empty_tmpdir 'patch/innocent'
  patch_task = task.new do
    from src
    apply 'badly-formed-patch-file.diff'
  end
  e = assert_raises(Treebis::Fail) do
    patch_task.on(tgt).run
  end
  assert_match(/Failed to run patch command/, e.message)
end

#test_patch_hack ⇒ Object



1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
# File 'lib/treebis.rb', line 1279

def test_patch_hack
  task.new {
    write "some-file.txt", <<-X
      i am the new content
    X
  }.on(src = empty_tmpdir('src')).run
  task.new {
    write "some-file.txt", <<-X
      never see me
    X
  }.on(tgt = empty_tmpdir('tgt')).run
  task.new {
    from src
    opts[:patch_hack] = true
    apply "some-file.txt.diff"
  }.on(tgt).run
  assert_equal(
    {"some-file.txt"=>"i am the new content\n"},
    dir_as_hash(tgt)
  )
end

#test_unexpected_string_from_patch ⇒ Object



1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
# File 'lib/treebis.rb', line 1300

def test_unexpected_string_from_patch
  out, err, res = capture3 do
    task.new do
      pretty_puts_apply("i am another string", [])
      nil
    end.on(empty_tmpdir("blah")).run
  end
  assert_equal [nil, ""], [res, out]
  assert err.index("i am another string")
end