spec/FileTestHelper_spec.rb in filetesthelper-0.9.0 vs spec/FileTestHelper_spec.rb in filetesthelper-0.9.1

- old
+ new

@@ -2,34 +2,50 @@ require 'rubygems' require 'spec' require 'filetesthelper' include FileTestHelper -describe FileTestHelper do - it 'should start in an empty working directory' do - with_files() do - Dir.glob('**/*').size == 0 +parameters = { + 'nil' => nil, + 'an empty hash' => {}, + 'a hash with only one file' => {'file.txt' => 'file content'} +} + +parameters.each do |parameter_name, parameter| + describe FileTestHelper, "when the hash paramater is #{parameter_name}" do + it 'should execute the block parameter' do + block_runned = false + with_files(parameter) {block_runned = true} + block_runned.should be_true end - end - it 'should not use the current directory as default' do - initial_directory = Dir.pwd - with_files() do - Dir.pwd.should_not == initial_directory + it 'should not use the current directory' do + initial_directory = Dir.pwd + with_files(parameter) do + Dir.pwd.should_not == initial_directory + end + Dir.pwd.should == initial_directory end - Dir.pwd.should == initial_directory - end - it 'should delete the working directory and its contents after use' do - working_directory_path = '' - with_files() do - working_directory_path = Dir.pwd + it 'should start in an empty working directory' do + with_files(parameter) do + Dir.glob('**/*').size == 0 + end end - working_directory_path.should_not be_empty - File.exist?(working_directory_path).should be_false - end + it 'should delete the working directory and its contents after running the block' do + working_directory_path = '' + with_files(parameter) do + working_directory_path = Dir.pwd + end + working_directory_path.should_not be_empty + File.exist?(working_directory_path).should be_false + end + end +end + +describe FileTestHelper do it 'should create the files and directories that were specified in a hash' do files_to_create = {'a directory/a file.txt' => '', 'a directory/another file.rb' => '', 'an_empty_directory/' => '', 'a_file' => ''} with_files(files_to_create) do files_to_create.each_key{|created_file| File.exist?(created_file).should be_true} end @@ -57,6 +73,10 @@ end it 'should throw an error if a path uses ".."' do lambda { with_files('../../dir/filea' => 'content of filea') {}}.should raise_error end -end + + it 'should not throw an exception when the hash parameter is nil' do + lambda { with_files(nil) {}}.should_not raise_error + end +end \ No newline at end of file