dirdiff 0.0.2

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.
@@ -0,0 +1,32 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ context "The SyncCallback" do
4
+
5
+ specify "should synchronize the target directory with the source" do
6
+ source = create_temporary_files(make_temporary_directory_containing('bin'), 'bin/file1.txt', 'bin/file2.pdf')
7
+ target = create_temporary_files(make_temporary_directory_containing('bin2'), 'bin2/file1.txt', 'bin2/file2.pdf')
8
+
9
+ Dirdiff::diff(source, target, Dirdiff::SyncCallback.new(source,target))
10
+
11
+ Dirdiff::diff(source, target, mock("This should not be called because there is nothing to do"))
12
+ end
13
+
14
+ teardown do
15
+ delete_temporary_directories
16
+ end
17
+
18
+ end
19
+
20
+ context "The CompositeCallback" do
21
+
22
+ specify "should forward method calls to each contained callback instance" do
23
+ callback1 = mock("callback1")
24
+ callback1.should_receive(:add_directory).with('bin/ruby', 'extra')
25
+ callback2 = mock("callback1")
26
+ callback2.should_receive(:add_directory).with('bin/ruby', 'extra')
27
+ composite = Dirdiff::compose(callback1,callback2)
28
+ composite.add_directory('bin/ruby','extra')
29
+ end
30
+
31
+ end
32
+
@@ -0,0 +1,89 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ context "A call to diff" do
4
+
5
+ specify "should make no callbacks when both directory contents are the same" do
6
+ Dirdiff::diff('.', '.', mock('should not be called'))
7
+ end
8
+
9
+ specify "should make the correct callback when the source directory has only one subdirectory and the target has none" do
10
+ source = make_temporary_directory_containing('bin')
11
+ target = make_temporary_directory_root
12
+ callback = mock("mock")
13
+ callback.should_receive(:add_directory).with('.', 'bin')
14
+ Dirdiff::diff(source, target, callback)
15
+ end
16
+
17
+ specify "should make the correct callback when the source directory has one subdirectory more than the target" do
18
+ source = make_temporary_directory_containing('bin/ruby/extra')
19
+ target = make_temporary_directory_containing('bin/ruby')
20
+ callback = mock("mock")
21
+ callback.should_receive(:add_directory).with('bin/ruby', 'extra')
22
+ Dirdiff::diff(source, target, callback)
23
+ end
24
+
25
+ specify "should make the correct callback when the source directory has two subdirectories more than the target" do
26
+ source = make_temporary_directory_containing('bin/ruby/extra/extra2')
27
+ target = make_temporary_directory_containing('bin/ruby')
28
+ callback = mock("mock")
29
+ callback.should_receive(:add_directory).with('bin/ruby', 'extra')
30
+ callback.should_receive(:add_directory).with('bin/ruby/extra', 'extra2')
31
+ Dirdiff::diff(source, target, callback)
32
+ end
33
+
34
+ specify "should make the correct callback when the target directory has one subdirectory more than the source" do
35
+ target = make_temporary_directory_containing('bin/ruby/extra')
36
+ source = make_temporary_directory_containing('bin/ruby')
37
+ callback = mock("mock")
38
+ callback.should_receive(:remove_directory).with('bin/ruby', 'extra')
39
+ Dirdiff::diff(source, target, callback)
40
+ end
41
+
42
+ specify "should make the correct callback when the target directory has two subdirectories more than the source" do
43
+ target = make_temporary_directory_containing('bin/ruby/extra/extra2')
44
+ source = make_temporary_directory_containing('bin/ruby')
45
+ callback = mock("mock")
46
+ callback.should_receive(:remove_directory).with('bin/ruby', 'extra')
47
+ Dirdiff::diff(source, target, callback)
48
+ end
49
+
50
+ specify "should make the correct callback when the source directory contains two files that the target does not have" do
51
+ source = create_temporary_files(make_temporary_directory_containing('bin'), 'bin/file1.txt', 'bin/file2.pdf')
52
+ target = make_temporary_directory_containing('bin')
53
+ callback = mock("mock")
54
+ callback.should_receive(:add_file).with('bin', 'file1.txt')
55
+ callback.should_receive(:add_file).with('bin', 'file2.pdf')
56
+ Dirdiff::diff(source, target, callback)
57
+ end
58
+
59
+ specify "should make the correct callback when the target directory contains two files that the source does not have" do
60
+ target = create_temporary_files(make_temporary_directory_containing('bin'), 'bin/file1.txt', 'bin/file2.pdf')
61
+ source = make_temporary_directory_containing('bin')
62
+ callback = mock("mock")
63
+ callback.should_receive(:remove_file).with('bin', 'file1.txt')
64
+ callback.should_receive(:remove_file).with('bin', 'file2.pdf')
65
+ Dirdiff::diff(source, target, callback)
66
+ end
67
+
68
+ specify "should make the correct callback when the source directory contains a more recent version of a file" do
69
+ target = create_temporary_files(make_temporary_directory_containing('bin'), 'bin/file1.txt')
70
+ sleep(1)
71
+ source = create_temporary_files(make_temporary_directory_containing('bin'), 'bin/file1.txt')
72
+ callback = mock("mock")
73
+ callback.should_receive(:update_file).with('bin', 'file1.txt')
74
+ Dirdiff::diff(source, target, callback)
75
+ end
76
+
77
+ specify "should make the correct callback when the source directory contains a file differing in content" do
78
+ target = make_file_with_random_contents(make_temporary_directory_containing('bin'), 'bin/file1.txt')
79
+ source = make_file_with_random_contents(make_temporary_directory_containing('bin'), 'bin/file1.txt')
80
+ callback = mock("mock")
81
+ callback.should_receive(:update_file).with('bin', 'file1.txt')
82
+ Dirdiff::diff(source, target, callback)
83
+ end
84
+
85
+ teardown do
86
+ delete_temporary_directories
87
+ end
88
+ end
89
+
@@ -0,0 +1,46 @@
1
+ require 'spec'
2
+ require 'fileutils'
3
+ require File.dirname(__FILE__) + '/../lib/dirdiff'
4
+
5
+ @@temporary_directory_root_count = 0
6
+ @@to_be_deleted = []
7
+
8
+ def make_temporary_directory_containing(subdir)
9
+ root = make_temporary_directory_root
10
+ FileUtils.mkdir_p(root + "/" + subdir)
11
+ root
12
+ end
13
+
14
+ def make_temporary_directory_root
15
+ root = "tmp_root_#{@@temporary_directory_root_count}"
16
+ @@temporary_directory_root_count = @@temporary_directory_root_count + 1
17
+ FileUtils.mkdir_p(root)
18
+ @@to_be_deleted << root
19
+ root
20
+ end
21
+
22
+ def create_temporary_files(root, *files)
23
+ files.each do |f|
24
+ File.open("#{root}/#{f}", "w") do |open_file|
25
+ open_file << f
26
+ end
27
+ end
28
+ root
29
+ end
30
+
31
+ def make_file_with_random_contents(root, path)
32
+ File.open("#{root}/#{path}", "w") do |open_file|
33
+ size = rand(1024)
34
+ s = ""
35
+ size.times { s << (i = Kernel.rand(62); i += ((i < 10) ? 48 : ((i < 36) ? 55 : 61 ))).chr }
36
+ open_file << s
37
+ end
38
+ root
39
+ end
40
+
41
+ def delete_temporary_directories
42
+ @@to_be_deleted.each {|d|
43
+ FileUtils.rm_r(d)
44
+ }
45
+ @@to_be_deleted = []
46
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: dirdiff
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.2
7
+ date: 2007-03-03 00:00:00 +00:00
8
+ summary: description of gem
9
+ require_paths:
10
+ - lib
11
+ email: your contact email for bug fixes and info
12
+ homepage: http://dirdiff.rubyforge.org
13
+ rubyforge_project: dirdiff
14
+ description: description of gem
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - hoganm
31
+ files:
32
+ - Rakefile
33
+ - README.txt
34
+ - CHANGELOG.txt
35
+ - Manifest.txt
36
+ - setup.rb
37
+ - lib/dirdiff/version.rb
38
+ - lib/dirdiff/dirdiff.rb
39
+ - lib/dirdiff.rb
40
+ - test/test_helper.rb
41
+ - test/dirdiff_test.rb
42
+ - test/callback_test.rb
43
+ test_files:
44
+ - test/callback_test.rb
45
+ - test/dirdiff_test.rb
46
+ rdoc_options: []
47
+
48
+ extra_rdoc_files: []
49
+
50
+ executables: []
51
+
52
+ extensions: []
53
+
54
+ requirements: []
55
+
56
+ dependencies: []
57
+