Module: Treebis::Test::TestDirAsHash

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

Instance Method Summary collapse

Instance Method Details

#test_baby_jug_failObject



1132
1133
1134
1135
1136
1137
1138
# File 'lib/treebis.rb', line 1132

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_hashObject



1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
# File 'lib/treebis.rb', line 1142

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_globsObject



1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
# File 'lib/treebis.rb', line 1175

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