svn-transform 0.1.0
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/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.rdoc +101 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/examples/example_helper.rb +31 -0
- data/examples/fixtures/dir_props.rb +29 -0
- data/examples/fixtures/original.rb +86 -0
- data/examples/fixtures/result.rb +105 -0
- data/examples/svn-transform/dir_example.rb +56 -0
- data/examples/svn-transform/file_example.rb +71 -0
- data/examples/svn-transform/transform/extension_example.rb +48 -0
- data/examples/svn-transform/transform/newline_example.rb +51 -0
- data/examples/svn-transform/transform/noop_example.rb +15 -0
- data/examples/svn-transform/transform/props_to_yaml_example.rb +137 -0
- data/examples/svn-transform_example.rb +148 -0
- data/lib/svn-transform.rb +264 -0
- data/lib/svn-transform/dir.rb +65 -0
- data/lib/svn-transform/file.rb +79 -0
- data/lib/svn-transform/session.rb +62 -0
- data/lib/svn-transform/transform/extension.rb +41 -0
- data/lib/svn-transform/transform/newline.rb +50 -0
- data/lib/svn-transform/transform/noop.rb +28 -0
- data/lib/svn-transform/transform/props_to_yaml.rb +134 -0
- metadata +115 -0
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'example_helper'
|
2
|
+
|
3
|
+
describe SvnTransform::Dir do
|
4
|
+
before(:each) do
|
5
|
+
@dir = SvnTransform::Dir.example
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '#initialize' do
|
9
|
+
it 'should set #path' do
|
10
|
+
@dir.path.should be_kind_of(Pathname)
|
11
|
+
@dir.path.to_s.should == '/path/to/dir'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should set #entries (extracted from node_data)' do
|
15
|
+
@dir.entries.should == {'entry.txt' => nil}
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should set #repos' do
|
19
|
+
@dir.repos.should == :repos # Actually, a Svn::Ra::Session
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should set #fixture_dir' do
|
23
|
+
@dir.fixture_dir.should == :fixture_dir # Actually, a SvnFixture::Directory
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should set #properties (extracted from node_data)' do
|
27
|
+
@dir.properties.should == {'prop:svn' => 'property value'}
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should set #rev_num' do
|
31
|
+
@dir.rev_num.should == 10
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should set #rev_props' do
|
35
|
+
@dir.rev_props.should == {'svn:author' => 'me'}
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#basename' do
|
40
|
+
it 'should return the basename of the path' do
|
41
|
+
@dir.basename.should == 'dir'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#properties=' do
|
46
|
+
it "should reject an Argument that doesn't respond to #each_pair" do
|
47
|
+
lambda { @dir.properties = 'properties' }.should raise_error(ArgumentError)
|
48
|
+
@dir.properties.should == {'prop:svn' => 'property value'}
|
49
|
+
end
|
50
|
+
|
51
|
+
it 'should set @properties' do
|
52
|
+
@dir.properties = {'diffprop' => 'value'}
|
53
|
+
@dir.properties.should == {'diffprop' => 'value'}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'example_helper'
|
2
|
+
|
3
|
+
describe SvnTransform::File do
|
4
|
+
before(:each) do
|
5
|
+
@file = SvnTransform::File.example
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '#initialize' do
|
9
|
+
it 'should set #path' do
|
10
|
+
@file.path.should be_kind_of(Pathname)
|
11
|
+
@file.path.to_s.should == '/path/to/file.txt'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should set #body (extracted from node_data)' do
|
15
|
+
@file.body.should == 'body of file'
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should set #properties (extracted from node_data)' do
|
19
|
+
@file.properties.should == {'prop:svn' => 'property value'}
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should set #rev_num' do
|
23
|
+
@file.rev_num.should == 10
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should set #rev_props' do
|
27
|
+
@file.rev_props.should == {'svn:author' => 'me'}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#basename' do
|
32
|
+
it 'should return the basename of the path' do
|
33
|
+
@file.basename.should == 'file.txt'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#basename=' do
|
38
|
+
it 'should update the path' do
|
39
|
+
@file.basename = 'app.exe'
|
40
|
+
@file.path.should == Pathname.new('/path/to/app.exe')
|
41
|
+
@file.basename.should == 'app.exe'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#body=' do
|
46
|
+
it 'should set @body' do
|
47
|
+
@file.body = 'new body'
|
48
|
+
@file.body.should == 'new body'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#properties=' do
|
53
|
+
it "should reject an Argument that doesn't respond to #each_pair" do
|
54
|
+
lambda { @file.properties = 'properties' }.should raise_error(ArgumentError)
|
55
|
+
@file.properties.should == {'prop:svn' => 'property value'}
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should set @properties' do
|
59
|
+
@file.properties = {'diffprop' => 'value'}
|
60
|
+
@file.properties.should == {'diffprop' => 'value'}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#skip!' do
|
65
|
+
it 'should set #skip? to true' do
|
66
|
+
@file.skip?.should be_false
|
67
|
+
@file.skip!
|
68
|
+
@file.skip?.should be_true
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'example_helper'
|
2
|
+
|
3
|
+
describe SvnTransform::Transform::Extension do
|
4
|
+
before(:each) do
|
5
|
+
@file = SvnTransform::File.example
|
6
|
+
@klass = SvnTransform::Transform::Extension
|
7
|
+
@transform = @klass.new(@file, {:txt => :markdown})
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#initialize' do
|
11
|
+
it 'should set @file' do
|
12
|
+
@transform.instance_variable_get(:@file).should be(@file)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should set @extensions (as strings preceded with dot)' do
|
16
|
+
@transform.instance_variable_get(:@extensions).should == {".txt" => ".markdown"}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#run' do
|
21
|
+
it 'should return false if no changes made' do
|
22
|
+
@file.basename = 'file.other'
|
23
|
+
@transform.run.should be_false
|
24
|
+
@file.basename.should == 'file.other'
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should return true and update @file.basename if changes made' do
|
28
|
+
@file.basename = 'file.txt'
|
29
|
+
@transform.run.should be_true
|
30
|
+
@file.basename.should == 'file.markdown'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should process multiple extension options' do
|
34
|
+
@transform = @klass.new(@file, {:txt => :markdown, :ruby => :rb})
|
35
|
+
@file.basename = 'file.txt'
|
36
|
+
@transform.run.should be_true
|
37
|
+
@file.basename.should == 'file.markdown'
|
38
|
+
|
39
|
+
@file.basename = 'file.ruby'
|
40
|
+
@transform.run.should be_true
|
41
|
+
@file.basename.should == 'file.rb'
|
42
|
+
|
43
|
+
@file.basename = 'file'
|
44
|
+
@transform.run.should be_false
|
45
|
+
@file.basename.should == 'file'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'example_helper'
|
2
|
+
|
3
|
+
describe SvnTransform::Transform::Newline do
|
4
|
+
before(:each) do
|
5
|
+
@file = SvnTransform::File.example
|
6
|
+
@klass = SvnTransform::Transform::Newline
|
7
|
+
@transform = @klass.new(@file, "<br \/>\n")
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#initialize' do
|
11
|
+
it 'should set @file' do
|
12
|
+
@transform.instance_variable_get(:@file).should be(@file)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should set @newline' do
|
16
|
+
@transform.instance_variable_get(:@newline).should == "<br \/>\n"
|
17
|
+
@klass.new(@file).instance_variable_get(:@newline).should == "\n"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#all_to_lf' do
|
22
|
+
it 'should convert CRs and CRLFs to LFs' do
|
23
|
+
str = "\nabc\r\n\n\rdef\r\rghi\r\n\r\n\njkl\r"
|
24
|
+
@transform.__send__(:all_to_lf, str).should ==
|
25
|
+
"\nabc\n\n\ndef\n\nghi\n\n\njkl\n"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#run' do
|
30
|
+
it 'should return false if no changes made' do
|
31
|
+
input = "\r\nabc\r\n"
|
32
|
+
@file.body = input
|
33
|
+
@klass.new(@file, @klass::CRLF).run.should be_false
|
34
|
+
@file.body.should be(input)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should return true and update @file.body if changes made' do
|
38
|
+
input = "\r\nabc\r\n"
|
39
|
+
@file.body = input
|
40
|
+
@klass.new(@file).run.should be_true
|
41
|
+
@file.body.should == "\nabc\n"
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should replace all newlines with @newline' do
|
45
|
+
input = "\r\nabc\r\n\n\n\r"
|
46
|
+
@file.body = input
|
47
|
+
@klass.new(@file, "NL").run.should be_true
|
48
|
+
@file.body.should == "NLabcNLNLNLNL"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'example_helper'
|
2
|
+
|
3
|
+
describe SvnTransform::Transform::Noop do
|
4
|
+
before(:each) do
|
5
|
+
@file = SvnTransform::File.example
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should do nothing' do
|
9
|
+
untouched = SvnTransform::File.example
|
10
|
+
SvnTransform::Transform::Noop.new(@file).run.should be_false
|
11
|
+
@file.body.should == untouched.body
|
12
|
+
@file.basename.should == untouched.basename
|
13
|
+
@file.properties.should == untouched.properties
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'example_helper'
|
2
|
+
|
3
|
+
describe SvnTransform::Transform::PropsToYaml do
|
4
|
+
before(:each) do
|
5
|
+
@klass = SvnTransform::Transform::PropsToYaml
|
6
|
+
@file = SvnTransform::File.example
|
7
|
+
@file.body = "Body Only\n"
|
8
|
+
@file.properties = {'title' => 'Hello', 'prop:one' => 'o', 'prop:two' => 't'}
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#run (file)' do
|
12
|
+
it 'should move all if instruction is :all' do
|
13
|
+
@klass.new(@file, :all).run.should be_true
|
14
|
+
@file.body.should == "--- \ntitle: Hello\nprop:two: t\nprop:one: o\n---\n\nBody Only\n"
|
15
|
+
@file.properties.should == {}
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should add to existing Yaml props' do
|
19
|
+
@file.body = "--- \nnewprop: hi\n---\n\nBody Only\n"
|
20
|
+
@klass.new(@file, :all).run.should be_true
|
21
|
+
@file.body.should == "--- \ntitle: Hello\nprop:two: t\nnewprop: hi\nprop:one: o\n---\n\nBody Only\n"
|
22
|
+
@file.properties.should == {}
|
23
|
+
|
24
|
+
@file.body = "---\nnewprop: hi\n...\nBody Only\n"
|
25
|
+
@file.properties = {'title' => 'Hello', 'prop:one' => 'o', 'prop:two' => 't'}
|
26
|
+
@klass.new(@file, :all).run.should be_true
|
27
|
+
@file.body.should == "--- \ntitle: Hello\nprop:two: t\nnewprop: hi\nprop:one: o\n---\n\nBody Only\n"
|
28
|
+
@file.properties.should == {}
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should override existing Yaml props that conflict with Svn props' do
|
32
|
+
@file.body = "---\nnewprop: hi\ntitle: World\n...\nBody Only\n"
|
33
|
+
@klass.new(@file, :all).run.should be_true
|
34
|
+
@file.body.should == "--- \ntitle: Hello\nprop:two: t\nnewprop: hi\nprop:one: o\n---\n\nBody Only\n"
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should match a string' do
|
38
|
+
@klass.new(@file, [['title', 'newtitle']]).run.should be_true
|
39
|
+
@file.body.should == "--- \nnewtitle: Hello\n---\n\nBody Only\n"
|
40
|
+
@file.properties.should == {'prop:one' => 'o', 'prop:two' => 't'}
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should match a regex' do
|
44
|
+
@klass.new(@file, [[/\Aprop:(.*)\Z/, 'p-\1']]).run.should be_true
|
45
|
+
@file.body.should == "--- \np-two: t\np-one: o\n---\n\nBody Only\n"
|
46
|
+
@file.properties.should == {'title' => 'Hello'}
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should move props' do
|
50
|
+
@klass.new(@file, [[/prop/, :move]]).run.should be_true
|
51
|
+
@file.body.should == "--- \nprop:two: t\nprop:one: o\n---\n\nBody Only\n"
|
52
|
+
@file.properties.should == {'title' => 'Hello'}
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should delete props' do
|
56
|
+
@klass.new(@file, [[/prop/, :delete]]).run.should be_true
|
57
|
+
@file.body.should == "Body Only\n"
|
58
|
+
@file.properties.should == {'title' => 'Hello'}
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should not add empty yaml to body' do
|
62
|
+
@klass.new(@file, [['nothing', :move]]).run.should be_false
|
63
|
+
@file.body.should == "Body Only\n"
|
64
|
+
@file.properties.should == {'title' => 'Hello', 'prop:one' => 'o', 'prop:two' => 't'}
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should return false if nothing happens' do
|
68
|
+
@klass.new(@file, [['nothing', :move]]).run.should be_false
|
69
|
+
@file.body.should == "Body Only\n"
|
70
|
+
@file.properties.should == {'title' => 'Hello', 'prop:one' => 'o', 'prop:two' => 't'}
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'should handle multiple instructions' do
|
74
|
+
@file.body = "---\ntitle: Hello\nyaml_only: yaml\n---\nBody Only\n"
|
75
|
+
@file.properties = {'ws:title' => 'Hello World', 'ws:published' => 'y', 'ws:tags' => 'this; that'}
|
76
|
+
@klass.new(@file, [['ws:tags', 'topics'], [/\Aws:(.*)\Z/, '\1']]).run.should be_true
|
77
|
+
@file.body.should == "--- \ntitle: Hello World\npublished: y\ntopics: this; that\nyaml_only: yaml\n---\n\nBody Only\n"
|
78
|
+
@file.properties.should == {}
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '#run (directory)' do
|
83
|
+
# The best way I can see to test this is just run a full example.
|
84
|
+
it 'should move properties to YAML file' do
|
85
|
+
load 'fixtures/dir_props.rb'
|
86
|
+
in_repo = SvnFixture.repo('dir_props')
|
87
|
+
transform = SvnTransform.new(in_repo.uri, 'dir_props_out')
|
88
|
+
transform.dir_transform(@klass, :all)
|
89
|
+
transform.convert
|
90
|
+
|
91
|
+
out_sess = SvnTransform::Session.new(SvnFixture.repo('dir_props_out').uri)
|
92
|
+
repo = out_sess.session
|
93
|
+
repo.stat('noprops/meta.yml', 1).should be_nil
|
94
|
+
|
95
|
+
repo.dir('svnprops', 1)[1]['one'].should be_nil
|
96
|
+
repo.dir('svnprops', 1)[1]['two'].should be_nil
|
97
|
+
repo.stat('svnprops/meta.yml', 1).should_not be_nil
|
98
|
+
repo.file('svnprops/meta.yml', 1)[0].should == "--- \ntwo: t\none: o\n"
|
99
|
+
|
100
|
+
repo.dir('yamlprops', 1)[1]['one'].should be_nil
|
101
|
+
repo.dir('yamlprops', 1)[1]['two'].should be_nil
|
102
|
+
repo.file('yamlprops/meta.yml', 1)[0].should == "---\none: yaml\n"
|
103
|
+
|
104
|
+
repo.dir('bothprops', 1)[1]['one'].should be_nil
|
105
|
+
repo.dir('bothprops', 1)[1]['two'].should be_nil
|
106
|
+
repo.file('bothprops/meta.yml', 1)[0].should == "--- \ntwo: yaml\none: o\n"
|
107
|
+
|
108
|
+
SvnFixture.repo('dir_props').destroy
|
109
|
+
SvnFixture.repo('dir_props_out').destroy
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe 'yaml_split' do
|
114
|
+
def get_split
|
115
|
+
@klass.new(@file, :all).__send__(:yaml_split)[1]
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should split out yaml (end with ---)' do
|
119
|
+
@file.body = "---\none: two\nthree: four\n---\n\nBody"
|
120
|
+
get_split.should == 'Body'
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should remove yaml (end with ...)' do
|
124
|
+
@file.body = "---\none: two\nthree: four\n...\n\nBody"
|
125
|
+
get_split.should == 'Body'
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'should handle newlines well' do
|
129
|
+
@file.body = "---\r\none: two\r\nthree: four\r\n---\r\n\r\nBody"
|
130
|
+
get_split.should == 'Body'
|
131
|
+
@file.body = "--- \r\none: two\r\nthree: four\r\n\n---\r\n\r\n\n\nBody"
|
132
|
+
get_split.should == 'Body'
|
133
|
+
@file.body = "--- \n\none: two\nthree: four\n\n...\n\nBody"
|
134
|
+
get_split.should == 'Body'
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require 'example_helper'
|
2
|
+
|
3
|
+
describe "SvnTransform" do
|
4
|
+
describe '#convert' do
|
5
|
+
it 'should make full conversion correctly' do
|
6
|
+
SvnFixture::Repository.instance_variable_set(:@repositories, {})
|
7
|
+
load File.dirname(__FILE__) + '/fixtures/original.rb'
|
8
|
+
load File.dirname(__FILE__) + '/fixtures/result.rb'
|
9
|
+
in_repo = SvnFixture.repo('original')
|
10
|
+
# Update rev 0 date in result
|
11
|
+
r0_date = in_repo.ctx.revprop_list(in_repo.uri, 0)[0]['svn:date']
|
12
|
+
SvnFixture.repo('result').repos.fs.set_prop('svn:date', SvnFixture.svn_time(r0_date), 0)
|
13
|
+
|
14
|
+
@transform = SvnTransform.new(in_repo.uri, 'transformed')
|
15
|
+
|
16
|
+
@transform.file_transform(
|
17
|
+
SvnTransform::Transform::PropsToYaml,
|
18
|
+
[['ws:tags', 'topics'], [/\Aws:(.*)\Z/, '\1']]
|
19
|
+
)
|
20
|
+
@transform.dir_transform(
|
21
|
+
SvnTransform::Transform::PropsToYaml,
|
22
|
+
[['ws:tags', 'topics'], [/\Aws:(.*)\Z/, '\1']]
|
23
|
+
)
|
24
|
+
@transform.file_transform(
|
25
|
+
SvnTransform::Transform::Newline
|
26
|
+
)
|
27
|
+
@transform.file_transform(
|
28
|
+
SvnTransform::Transform::Extension,
|
29
|
+
:txt => :md
|
30
|
+
)
|
31
|
+
|
32
|
+
@transform.convert
|
33
|
+
SvnTransform.compare(SvnFixture.repo('result').repos_path, SvnFixture.repo('transformed').repos_path).should be_true
|
34
|
+
SvnFixture.repo('original').destroy
|
35
|
+
SvnFixture.repo('result').destroy
|
36
|
+
SvnFixture.repo('transformed').destroy
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'direct copy' do
|
41
|
+
it 'should make a MOL copy' do
|
42
|
+
SvnFixture::Repository.instance_variable_set(:@repositories, {})
|
43
|
+
load File.dirname(__FILE__) + '/fixtures/original.rb'
|
44
|
+
in_repo = SvnFixture.repo('original')
|
45
|
+
SvnTransform.new(in_repo.uri, 'directcopy').convert
|
46
|
+
SvnTransform.compare(in_repo.repos_path, SvnFixture.repo('directcopy').repos_path).should be_true
|
47
|
+
SvnFixture.repo('original').destroy
|
48
|
+
SvnFixture.repo('directcopy').destroy
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#file_transform' do
|
53
|
+
before(:each) do
|
54
|
+
@svn_t = SvnTransform.new('in', 'out')
|
55
|
+
@svn_t.file_transform(Object)
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should add a [Class, args] Array to the @file_transforms Array' do
|
59
|
+
@svn_t.file_transform(Class, 'a', 1)
|
60
|
+
@svn_t.instance_variable_get(:@file_transforms).should ==
|
61
|
+
[[Object, []], [Class, ['a', 1]]]
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should add a block to the @file_transforms Array' do
|
65
|
+
@svn_t.file_transform { |file| p file }
|
66
|
+
@svn_t.instance_variable_get(:@file_transforms)[1].should be_kind_of(Proc)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should raise an Error if neither is provided' do
|
70
|
+
lambda { @svn_t.file_transform }.should raise_error(ArgumentError)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#process_file_transforms' do
|
75
|
+
before(:each) do
|
76
|
+
@svn_t = SvnTransform.new('in', 'out')
|
77
|
+
@file = SvnTransform::File.example
|
78
|
+
|
79
|
+
@klass = Class.new do
|
80
|
+
def initialize(file, arg1 = nil, arg2 = nil)
|
81
|
+
@file = file
|
82
|
+
@arg1 = arg1
|
83
|
+
@arg2 = arg2
|
84
|
+
end
|
85
|
+
def run
|
86
|
+
if @arg2
|
87
|
+
@file.body += " #{@arg2}"
|
88
|
+
else
|
89
|
+
@file.body = "body from transform Class"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should run +file+ through each file_transform' do
|
96
|
+
@svn_t.file_transform do |file|
|
97
|
+
file.properties['other'] = 'other_val'
|
98
|
+
end
|
99
|
+
@svn_t.file_transform(@klass)
|
100
|
+
@svn_t.file_transform(@klass, 'ARG1', 'ARG2')
|
101
|
+
@svn_t.__send__(:process_file_transforms, @file)
|
102
|
+
|
103
|
+
@file.body.should == 'body from transform Class ARG2'
|
104
|
+
@file.properties.should ==
|
105
|
+
{'prop:svn' => 'property value', 'other' => 'other_val'}
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe '#dir_transform' do
|
110
|
+
before(:each) do
|
111
|
+
@svn_t = SvnTransform.new('in', 'out')
|
112
|
+
@svn_t.dir_transform(Object)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'should add a [Class, args] Array to the @dir_transforms Array' do
|
116
|
+
@svn_t.dir_transform(Class, 'a', 1)
|
117
|
+
@svn_t.instance_variable_get(:@dir_transforms).should ==
|
118
|
+
[[Object, []], [Class, ['a', 1]]]
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'should add a block to the @dir_transforms Array' do
|
122
|
+
@svn_t.dir_transform { |dir| p dir }
|
123
|
+
@svn_t.instance_variable_get(:@dir_transforms)[1].should be_kind_of(Proc)
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should raise an Error if neither is provided' do
|
127
|
+
lambda { @svn_t.dir_transform }.should raise_error(ArgumentError)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe '#process_dir_transforms' do
|
132
|
+
before(:each) do
|
133
|
+
@svn_t = SvnTransform.new('in', 'out')
|
134
|
+
@dir = SvnTransform::Dir.example
|
135
|
+
end
|
136
|
+
|
137
|
+
it 'should run +dir+ through each dir_transform' do
|
138
|
+
@svn_t.dir_transform do |dir|
|
139
|
+
dir.properties['other'] = 'other_val'
|
140
|
+
end
|
141
|
+
|
142
|
+
@svn_t.__send__(:process_dir_transforms, @dir)
|
143
|
+
|
144
|
+
@dir.properties.should ==
|
145
|
+
{'prop:svn' => 'property value', 'other' => 'other_val'}
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|