filetesthelper 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.txt +5 -2
- data/Rakefile.rb +2 -2
- data/lib/filetesthelper.rb +2 -0
- data/spec/FileTestHelper_spec.rb +39 -19
- data/spec/spec.opts +4 -3
- metadata +3 -3
data/README.txt
CHANGED
@@ -2,7 +2,10 @@
|
|
2
2
|
|
3
3
|
A simple helper aimed at reducing the setup effort needed to create directories, files and file content in the scope of an integration test case.
|
4
4
|
|
5
|
-
==
|
5
|
+
== Installation
|
6
|
+
gem install filetesthelper
|
7
|
+
|
8
|
+
== Usage
|
6
9
|
|
7
10
|
require 'rubygems'
|
8
11
|
require 'filetesthelper'
|
@@ -23,5 +26,5 @@ A simple helper aimed at reducing the setup effort needed to create directories,
|
|
23
26
|
#When we finish we are back at directory X and the Y directory is deleted with all its contents
|
24
27
|
end
|
25
28
|
|
26
|
-
See the specs for more details.
|
29
|
+
See the {specs}[link:specs.html], the {Rubyforge project homepage}[http://rubyforge.org/projects/filetesthelper] and my {blog}[http://dcadenas.blogspot.com/2008/03/file-system-integration-tests-helper.html] for more details.
|
27
30
|
|
data/Rakefile.rb
CHANGED
@@ -7,7 +7,7 @@ require 'rake/gempackagetask'
|
|
7
7
|
require 'spec/rake/spectask'
|
8
8
|
|
9
9
|
NAME = 'filetesthelper'
|
10
|
-
PKGVERSION = '0.9.
|
10
|
+
PKGVERSION = '0.9.1'
|
11
11
|
is_windows = (PLATFORM =~ /win32|cygwin/)
|
12
12
|
SUDO = is_windows ? '' : 'sudo'
|
13
13
|
README = "README.txt"
|
@@ -22,7 +22,7 @@ CLEAN.include ["pkg", "coverage", "doc"]
|
|
22
22
|
spec = Gem::Specification.new do |s|
|
23
23
|
s.name = NAME
|
24
24
|
s.version = PKGVERSION
|
25
|
-
s.author = "Daniel Cadenas
|
25
|
+
s.author = "Daniel Cadenas Nión"
|
26
26
|
s.email = "filetesthelper-devel@rubyforge.org"
|
27
27
|
s.homepage = "http://rubyforge.org/projects/filetesthelper/"
|
28
28
|
s.platform = Gem::Platform::RUBY
|
data/lib/filetesthelper.rb
CHANGED
@@ -34,6 +34,8 @@ module FileTestHelper
|
|
34
34
|
|
35
35
|
def create_files_in_working_directory(working_directory, files_with_contents)
|
36
36
|
cd working_directory
|
37
|
+
|
38
|
+
return unless files_with_contents
|
37
39
|
files_with_contents.each do |path, file_contents|
|
38
40
|
fail 'A path is not allowed to start with /' if path =~ /^\//
|
39
41
|
fail 'A path is not allowed to contain ..' if path =~ /\.\./
|
data/spec/FileTestHelper_spec.rb
CHANGED
@@ -4,30 +4,46 @@ require 'spec'
|
|
4
4
|
require 'filetesthelper'
|
5
5
|
include FileTestHelper
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
parameters = {
|
8
|
+
'nil' => nil,
|
9
|
+
'an empty hash' => {},
|
10
|
+
'a hash with only one file' => {'file.txt' => 'file content'}
|
11
|
+
}
|
12
|
+
|
13
|
+
parameters.each do |parameter_name, parameter|
|
14
|
+
describe FileTestHelper, "when the hash paramater is #{parameter_name}" do
|
15
|
+
it 'should execute the block parameter' do
|
16
|
+
block_runned = false
|
17
|
+
with_files(parameter) {block_runned = true}
|
18
|
+
block_runned.should be_true
|
11
19
|
end
|
12
|
-
end
|
13
20
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
21
|
+
it 'should not use the current directory' do
|
22
|
+
initial_directory = Dir.pwd
|
23
|
+
with_files(parameter) do
|
24
|
+
Dir.pwd.should_not == initial_directory
|
25
|
+
end
|
26
|
+
Dir.pwd.should == initial_directory
|
18
27
|
end
|
19
|
-
Dir.pwd.should == initial_directory
|
20
|
-
end
|
21
28
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
29
|
+
it 'should start in an empty working directory' do
|
30
|
+
with_files(parameter) do
|
31
|
+
Dir.glob('**/*').size == 0
|
32
|
+
end
|
26
33
|
end
|
27
|
-
working_directory_path.should_not be_empty
|
28
|
-
File.exist?(working_directory_path).should be_false
|
29
|
-
end
|
30
34
|
|
35
|
+
it 'should delete the working directory and its contents after running the block' do
|
36
|
+
working_directory_path = ''
|
37
|
+
with_files(parameter) do
|
38
|
+
working_directory_path = Dir.pwd
|
39
|
+
end
|
40
|
+
working_directory_path.should_not be_empty
|
41
|
+
File.exist?(working_directory_path).should be_false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe FileTestHelper do
|
31
47
|
it 'should create the files and directories that were specified in a hash' do
|
32
48
|
files_to_create = {'a directory/a file.txt' => '', 'a directory/another file.rb' => '', 'an_empty_directory/' => '', 'a_file' => ''}
|
33
49
|
with_files(files_to_create) do
|
@@ -59,4 +75,8 @@ describe FileTestHelper do
|
|
59
75
|
it 'should throw an error if a path uses ".."' do
|
60
76
|
lambda { with_files('../../dir/filea' => 'content of filea') {}}.should raise_error
|
61
77
|
end
|
62
|
-
|
78
|
+
|
79
|
+
it 'should not throw an exception when the hash parameter is nil' do
|
80
|
+
lambda { with_files(nil) {}}.should_not raise_error
|
81
|
+
end
|
82
|
+
end
|
data/spec/spec.opts
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filetesthelper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- "Daniel Cadenas Ni\
|
7
|
+
- "Daniel Cadenas Ni\xC3\xB3n"
|
8
8
|
autorequire: filetesthelper
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-03-
|
12
|
+
date: 2008-03-09 01:00:00 -02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|