Skip to content

Instantly share code, notes, and snippets.

@iNecas
Created March 18, 2011 18:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iNecas/876548 to your computer and use it in GitHub Desktop.
Save iNecas/876548 to your computer and use it in GitHub Desktop.
Cucumber step definition checking content of directory
# Usage:
#
# Then directory "tmp/sample" should have the following tree:
# """
# monday
# | beer.rb
# tuesday
# | vodka.php
# | wine.rb
# wednesday
# | afternoon
# | | black.out
# | evening
# | | pain.php
# | | sleep.rb
# """
Then /^directory "([^"]*)" should have the following tree:$/ do |directory, text|
expected_files_tree = ""
text.each_line {|line| expected_files_tree << line.strip << "\n" }
current_files_tree = dir_to_files_tree(directory)
current_files_tree.should == expected_files_tree
end
def dir_to_files_tree(directory, level = 0)
file_tree = ""
Dir.glob(File.join(directory, "*")).sort.each do |file|
next if file =~ /^\./
file_tree << ("| "*level + File.basename(file)) << "\n"
if File.directory?(file)
file_tree << dir_to_files_tree(file, level + 1)
end
end
file_tree
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment