提交 5278af3d 编写于 作者: A Aaron Patterson

return an empty array for empty yaml files

上级 74c5f65b
......@@ -32,7 +32,9 @@ def each(&block)
private
def rows
return @rows if @rows
@rows = YAML.load(render(IO.read(@file))).to_a
data = YAML.load(render(IO.read(@file)))
@rows = data ? data.to_a : []
end
def render(content)
......
......@@ -41,6 +41,23 @@ def test_erb_processing
assert_equal [], devs - fh.to_a.map(&:first)
end
end
def test_empty_file
tmp_yaml ['empty', 'yml'], '' do |t|
assert_equal [], File.open(t.path) { |fh| fh.to_a }
end
end
private
def tmp_yaml(name, contents)
t = Tempfile.new name
t.binmode
t.write contents
t.close
yield t
ensure
t.close true
end
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册