Module: Treebis::Test::TestDirAsHash

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

Instance Method Summary collapse

Instance Method Details

#test_baby_jug_fail ⇒ Object



1118
1119
1120
1121
1122
1123
1124
# File 'lib/treebis.rb', line 1118

def test_baby_jug_fail
  hh = {'foo'=>nil}
  e = assert_raise(RuntimeError) do
    hash_to_dir(hh, empty_tmpdir('babyjug')+'/bar', file_utils)
  end
  assert_match(/bad type for dir hash/, e.message)
end

#test_dir_as_hash ⇒ Object



1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
# File 'lib/treebis.rb', line 1128

def test_dir_as_hash
  h = {
    'not'=>'funny',
    'baby-jug'=>{
      'what-does'=>'the baby have',
      'blood'=>'where?'},
    'not-funny'=>{
      'youre' => {
        'right' => 'its not funny',
        'not'=>{
          'funny'=>'ha ha',
          'not funny'=>'BLOO-DUH'
        }
      }
    }
  }
  td = empty_tmpdir('blah')+'/not-there'
  hash_to_dir(h, td, file_utils)
  skips = [ 'baby-jug/blood',
            'not-funny/youre/not/funny']
  wow = dir_as_hash(td, :skip=>skips)
  no_way = {
    "baby-jug"=>{"what-does"=>"the baby have"},
    "not"=>"funny",
    "not-funny"=>{
      "youre"=>{
        "right"=>"its not funny",
        "not"=>{"not funny"=>"BLOO-DUH"}
      }
    }
  }
  assert_equal no_way, wow
end

#test_dir_as_hash_with_globs ⇒ Object



1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
# File 'lib/treebis.rb', line 1161

def test_dir_as_hash_with_globs
  h = {
    'file1.txt' => 'foo',
    'file2.rb' => 'baz',
    'dir1' => {
      'file3.txt' => 'bar',
      'file4.rb' => 'bling'
    }
  }
  td = empty_tmpdir('blah')+'/not-there'
  hash_to_dir(h, td, file_utils)
  skips = [ 'dir1/*.rb' ]
  wow = dir_as_hash(td, :skip=>skips)
  no_way = {
    "file1.txt"=>"foo", "file2.rb"=>"baz",
    "dir1"=>{"file3.txt"=>"bar"},
  }
  assert_equal no_way, wow
end