Module: Treebis::Test::TestColorAndRmAndMoveAndPatch
- Included in:
- TestCase
- Defined in:
- lib/treebis.rb
Instance Method Summary collapse
- #setup_sourcedir ⇒ Object
- #test_move ⇒ Object
- #test_no_color ⇒ Object
- #test_no_overwrite ⇒ Object
- #test_rm_rf ⇒ Object
Instance Method Details
#setup_sourcedir ⇒ Object
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 |
# File 'lib/treebis.rb', line 1064 def setup_sourcedir src_dir = tmpdir+'/banana' # return if File.exist?(src_dir) task = Treebis::Task.new do rm_rf mkdir_p mkdir_p 'dir1' write 'dir1/stooges.txt.diff', "--- a/stooges.txt 2010-04-25 03:23:18.000000000 -0400\n+++ b/stooges.txt 2010-04-25 03:23:12.000000000 -0400\n@@ -1,2 +1,3 @@\nlarry\n+moe\ncurly\n" write 'stooges.orig.txt', "larry\ncurly\n" write 'treebis-task.rb', "Treebis.tasks.task(:banana) do\ncopy './stooges.orig.txt'\nmkdir_p_unless_exists './dir1'\nmove './stooges.orig.txt', './dir1/stooges.txt'\napply './dir1/stooges.txt.diff'\nend\n" end task.on(src_dir).run end |
#test_move ⇒ Object
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 |
# File 'lib/treebis.rb', line 1096 def test_move setup_sourcedir task = Treebis.dir_task(tmpdir+'/banana') out_dir = tmpdir+'/test-move-output' file_utils.remove_entry_secure(out_dir) if File.exist?(out_dir) file_utils.mkdir_p(out_dir) task.on(out_dir).run tree = dir_as_hash(out_dir) assert_equal({"dir1"=>{"stooges.txt"=>"larry\nmoe\ncurly\n"}}, tree) end |
#test_no_color ⇒ Object
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 |
# File 'lib/treebis.rb', line 1039 def test_no_color t = task.new do report_action :fake, "blah" end Treebis::Config.no_color! out = t.ui_capture{ on('x').run } Treebis::Config.color! assert_equal(" fake blah\n", out) end |
#test_no_overwrite ⇒ Object
1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 |
# File 'lib/treebis.rb', line 1049 def test_no_overwrite dir = tmpdir + '/no-overwrite/' Fu.remove_entry_secure(dir) if File.exist?(dir) t = task.new do mkdir_p_unless_exists write 'foo.txt','blah content' end t2 = task.new do write 'foo.txt','blah content again' end str1 = t.ui_capture{ on(dir).run } str2 = t2.ui_capture{ on(dir).run } assert_match( /wrote/, str1 ) assert_match( /won/, str2 ) end |
#test_rm_rf ⇒ Object
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 |
# File 'lib/treebis.rb', line 1027 def test_rm_rf t = task.new do rm_rf mkdir_p write('foo.txt', "hi i'm foo") end out = tmpdir+'/blearg' t.on(out).run t.on(out).run tree = dir_as_hash(out) assert_equal({"foo.txt"=>"hi i'm foo"}, tree) end |