jm81-svn-fixture 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.
@@ -0,0 +1,350 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe SvnFixture::Repository do
4
+ before(:all) do
5
+ @klass = SvnFixture::Repository
6
+ end
7
+
8
+ before(:each) do
9
+ # Force to default state
10
+ @klass.destroy_all
11
+ end
12
+
13
+ after(:all) do
14
+ # Force to default state for other specs
15
+ @klass.destroy_all
16
+ end
17
+
18
+ describe '.get' do
19
+ it 'should create a new repository if not found' do
20
+ @klass.instance_variable_get(:@repositories).should be_empty
21
+ r0 = @klass.get('test')
22
+ r0.should be_kind_of(SvnFixture::Repository)
23
+
24
+ r1 = @klass.get('different')
25
+ r0.should_not be(r1)
26
+ end
27
+
28
+ it 'should get an existing repository' do
29
+ @klass.instance_variable_get(:@repositories).should be_empty
30
+ r0 = @klass.new('test')
31
+ r1 = @klass.get('test')
32
+ r0.should be(r1)
33
+ end
34
+
35
+ it 'should pass repos_path and wc_path to .new' do
36
+ @klass.should_receive(:new).with('test', '/tmp/repo', '/tmp/wc')
37
+ @klass.get('test', '/tmp/repo', '/tmp/wc')
38
+ end
39
+
40
+ it 'should pass block to .new' do
41
+ # There's probably a better way to test this
42
+ SvnFixture::Revision.should_receive(:new).twice
43
+ @klass.get('test') do
44
+ revision(1, 'log')
45
+ revision(2, 'log')
46
+ end
47
+ end
48
+
49
+ it 'should process a block for an existing Repository' do
50
+ @klass.new('test')
51
+ SvnFixture::Revision.should_receive(:new).twice
52
+ @klass.get('test') do
53
+ revision(1, 'log')
54
+ revision(2, 'log')
55
+ end
56
+ end
57
+ end
58
+
59
+ describe '.repositories' do
60
+ it 'should default to an empty Hash' do
61
+ @klass.repositories.should == {}
62
+ end
63
+ end
64
+
65
+ describe '.new' do
66
+ it 'should add to .repositories' do
67
+ @klass.repositories.should be_empty
68
+ r = @klass.new('new_repo')
69
+ @klass.repositories.should == {'new_repo' => r}
70
+ end
71
+
72
+ it 'should evaluate block if given' do
73
+ SvnFixture::Revision.should_receive(:new).once
74
+ @klass.new('test') do
75
+ revision(1, 'log')
76
+ end
77
+ end
78
+
79
+ it "should verify there's no other Repository with this name" do
80
+ @klass.new('test')
81
+ lambda { @klass.new('test') }.should raise_error(
82
+ RuntimeError, "A Repository with this name (test) already exists.")
83
+ end
84
+
85
+ it 'should set up @repos_path' do
86
+ r = @klass.new('test1', '/test/path')
87
+ r.instance_variable_get(:@repos_path).should == '/test/path'
88
+
89
+ r = @klass.new('test2')
90
+ r.instance_variable_get(:@repos_path).should ==
91
+ ::File.join(SvnFixture::config[:base_path], 'repo_test2')
92
+ end
93
+
94
+ it 'should set up @wc_path' do
95
+ r = @klass.new('test1', nil, '/test/path')
96
+ r.instance_variable_get(:@wc_path).should == '/test/path'
97
+
98
+ r = @klass.new('test2')
99
+ r.instance_variable_get(:@wc_path).should ==
100
+ ::File.join(SvnFixture::config[:base_path], 'wc_test2')
101
+ end
102
+
103
+ it 'should initialize an empty revisions Array' do
104
+ r = @klass.new('test')
105
+ r.instance_variable_get(:@revisions).should == []
106
+ end
107
+
108
+ it 'should verify that repos_path does not exist' do
109
+ repos_path = File.join(Dir.tmpdir, 'svn-fixture-test-path')
110
+ FileUtils.mkdir_p(repos_path)
111
+ lambda {
112
+ @klass.new('test', repos_path, File.join(Dir.tmpdir, 'other-test-path'))
113
+ }.should raise_error(RuntimeError, "repos_path already exists (#{repos_path})")
114
+ end
115
+
116
+ it 'should verify that wc_path does not exist' do
117
+ File.exist?(File.join(Dir.tmpdir, 'other-test-path')).should be_false
118
+ wc_path = File.join(Dir.tmpdir, 'svn-fixture-test-path')
119
+ FileUtils.mkdir_p(wc_path)
120
+ lambda {
121
+ @klass.new('test', File.join(Dir.tmpdir, 'other-test-path'), wc_path)
122
+ }.should raise_error(RuntimeError, "wc_path already exists (#{wc_path})")
123
+ end
124
+ end
125
+
126
+ describe '#revision' do
127
+ before(:each) do
128
+ @repos = @klass.new('test')
129
+ end
130
+
131
+ it 'should create a Revision' do
132
+ SvnFixture::Revision.should_receive(:new).with(1, 'log msg', {})
133
+ @repos.revision(1, 'log msg', {})
134
+ end
135
+
136
+ it 'should add Revision to @revisions' do
137
+ @repos.instance_variable_get(:@revisions).should == []
138
+ rev1 = @repos.revision(1, 'log msg', {})
139
+ rev2 = @repos.revision(2, 'log msg', {})
140
+ @repos.instance_variable_get(:@revisions).should == [rev1, rev2]
141
+ end
142
+
143
+ it 'should accept a block' do
144
+ rev = @repos.revision(1, 'log msg', {}) do
145
+ dir('whatever')
146
+ end
147
+ rev.instance_variable_get(:@block).should be_kind_of(Proc)
148
+ end
149
+ end
150
+
151
+ describe '@revisions' do
152
+ it 'can be updated directly' do
153
+ @repos = @klass.new('test')
154
+ @repos.revisions.should == []
155
+ rev = SvnFixture::Revision.new(1, 'msg')
156
+ @repos.revisions << rev
157
+ @repos.instance_variable_get(:@revisions).should == [rev]
158
+ end
159
+ end
160
+
161
+ describe '#create' do
162
+ before(:each) do
163
+ @repos = @klass.new('test')
164
+ @repos_path = @repos.instance_variable_get(:@repos_path)
165
+ end
166
+
167
+ it 'should create Subversion repository' do
168
+ ::Svn::Repos.should_receive(:create).with(@repos_path)
169
+ @repos.create
170
+ end
171
+
172
+ it 'should create at repos_path' do
173
+ File.exist?(@repos_path).should be_false
174
+ @repos.create
175
+ File.exist?(@repos_path).should be_true
176
+ @repos.instance_variable_get(:@dirs_created).should == [@repos_path]
177
+ end
178
+
179
+ it 'should return self (for method chaining)' do
180
+ @repos.create.should be(@repos)
181
+ end
182
+ end
183
+
184
+ describe '#checkout' do
185
+ before(:each) do
186
+ @repos = @klass.new('test')
187
+ @repos_path = @repos.instance_variable_get(:@repos_path)
188
+ @wc_path = @repos.instance_variable_get(:@wc_path)
189
+ end
190
+
191
+ it 'should call #create if needed' do
192
+ File.exist?(@repos_path).should be_false
193
+ @repos.checkout
194
+ File.exist?(@repos_path).should be_true
195
+ @repos.instance_variable_get(:@dirs_created).should include(@repos_path)
196
+ end
197
+
198
+ it 'should call not call #create if something exists at @repos_path' do
199
+ FileUtils.mkdir_p(@repos_path)
200
+ ::Svn::Repos.create(@repos_path)
201
+ @repos.should_not_receive(:create)
202
+ @repos.checkout
203
+ FileUtils.rm_rf(@repos_path)
204
+ end
205
+
206
+ it 'should create @ctx (Svn::Client::Context)' do
207
+ @repos.ctx.should be_nil
208
+ @repos.checkout
209
+ @repos.ctx.should be_kind_of(::Svn::Client::Context)
210
+ end
211
+
212
+ it 'should checkout repository at wc_path' do
213
+ File.exist?(@wc_path).should be_false
214
+ @repos.checkout
215
+ File.exist?(@wc_path).should be_true
216
+ File.exist?(File.join(@wc_path, '.svn')).should be_true
217
+ @repos.instance_variable_get(:@dirs_created).should include(@wc_path)
218
+ end
219
+
220
+ it 'should return self' do
221
+ @repos.checkout.should be(@repos)
222
+ end
223
+ end
224
+
225
+ describe '#commit' do
226
+ before(:each) do
227
+ @repos = @klass.new('test') do
228
+ revision(1, 'log') do
229
+ dir 'test-dir'
230
+ end
231
+
232
+ revision(2, 'log') do
233
+ file 'test-file.txt'
234
+ end
235
+
236
+ revision(3, 'log') do
237
+ file 'test-file2.txt'
238
+ end
239
+ end
240
+ @repos_path = @repos.instance_variable_get(:@repos_path)
241
+ @wc_path = @repos.instance_variable_get(:@wc_path)
242
+ end
243
+
244
+ it 'should call #checkout if needed' do
245
+ File.exist?(@wc_path).should be_false
246
+ @repos.commit
247
+ File.exist?(@wc_path).should be_true
248
+ @repos.instance_variable_get(:@dirs_created).should include(@wc_path)
249
+ end
250
+
251
+ it 'should call not call #checkout if something exists at @wc_path' do
252
+ @repos.checkout
253
+ File.exist?(@wc_path).should be_true
254
+ @repos.should_not_receive(:checkout)
255
+ @repos.commit
256
+ end
257
+
258
+ it 'should commit all Revisions if no arguments given' do
259
+ @repos.revisions[0].should_receive(:commit).with(@repos)
260
+ @repos.revisions[1].should_receive(:commit).with(@repos)
261
+ @repos.revisions[2].should_receive(:commit).with(@repos)
262
+ @repos.commit
263
+ end
264
+
265
+ it 'should commit Revisions by name and/or actual instance' do
266
+ @repos.revisions[0].should_receive(:commit).with(@repos)
267
+ @repos.revisions[2].should_receive(:commit).with(@repos)
268
+ @repos.commit(@repos.revisions[2], 1)
269
+ end
270
+
271
+ =begin
272
+ def commit(to_commit = nil)
273
+ checkout unless ::File.exist?(@wc_path)
274
+ to_commit = @revisions if to_commit.nil?
275
+ to_commit = [to_commit] if (!to_commit.respond_to?(:each) || to_commit.kind_of?(String))
276
+
277
+ to_commit.each do | rev |
278
+ rev = @revisions.find{ |r| r.name == rev } unless rev.kind_of?(Revision)
279
+ rev.commit(self)
280
+ end
281
+ end
282
+ =end
283
+ end
284
+
285
+ describe '#destroy' do
286
+ before(:each) do
287
+ @repos = @klass.new('test')
288
+ end
289
+
290
+ it 'should delete repository and working copy directories' do
291
+ repos_path = @repos.instance_variable_get(:@repos_path)
292
+ wc_path = @repos.instance_variable_get(:@wc_path)
293
+ @repos.checkout # To create directories
294
+
295
+ File.exist?(repos_path).should be_true
296
+ File.exist?(wc_path).should be_true
297
+
298
+ @repos.destroy
299
+
300
+ File.exist?(repos_path).should be_false
301
+ File.exist?(wc_path).should be_false
302
+ end
303
+
304
+ it 'should not destroy directories that the Repository did not make' do
305
+ repos_path = @repos.instance_variable_get(:@repos_path)
306
+ wc_path = @repos.instance_variable_get(:@wc_path)
307
+ FileUtils.mkdir_p(repos_path)
308
+ FileUtils.mkdir_p(wc_path)
309
+
310
+ @repos.destroy
311
+
312
+ File.exist?(repos_path).should be_true
313
+ File.exist?(wc_path).should be_true
314
+
315
+ # Remove for other tests
316
+ FileUtils.rm_rf(repos_path)
317
+ FileUtils.rm_rf(wc_path)
318
+ end
319
+
320
+ it 'should remove Repository from .repositories' do
321
+ @klass.repositories.should == {'test' => @repos}
322
+ @repos.destroy
323
+ @klass.repositories.should == {}
324
+ end
325
+
326
+ it 'should not remove other Repositories' do
327
+ other_repos = @klass.new('other')
328
+ other_repos.checkout
329
+ @klass.repositories.should == {'test' => @repos, 'other' => other_repos}
330
+ @repos.destroy
331
+ @klass.repositories.should == {'other' => other_repos}
332
+ File.exist?(other_repos.instance_variable_get(:@repos_path)).should be_true
333
+ File.exist?(other_repos.instance_variable_get(:@wc_path)).should be_true
334
+ end
335
+ end
336
+
337
+ describe '.destroy_all' do
338
+ it 'should destroy all Repositories' do
339
+ repos = [@klass.new('test1'), @klass.new('test2'), @klass.new('test3')]
340
+ repos.each {|repo| repo.should_receive(:destroy)}
341
+ @klass.destroy_all
342
+ end
343
+
344
+ it 'should empty .repositories Hash' do
345
+ repos = [@klass.new('test1'), @klass.new('test2'), @klass.new('test3')]
346
+ @klass.destroy_all
347
+ @klass.repositories.should == {}
348
+ end
349
+ end
350
+ end
@@ -0,0 +1,70 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe SvnFixture::Revision do
4
+ before(:all) do
5
+ @klass = SvnFixture::Revision
6
+ end
7
+
8
+ describe '#initialize' do
9
+ it 'should accept a name, message, options and block' do
10
+ rev = @klass.new('name', 'msg', {:author => 'author'}) do
11
+ dir('test-dir')
12
+ end
13
+
14
+ rev.name.should == 'name'
15
+ rev.instance_variable_get(:@message).should == 'msg'
16
+ rev.instance_variable_get(:@author).should == 'author'
17
+ rev.instance_variable_get(:@block).should be_kind_of(Proc)
18
+ end
19
+
20
+ it 'should convert +:date+ option to an +svn_time+' do
21
+ rev = SvnFixture::Revision.new('name', 'msg', {:date => Time.parse('2009-01-01 12:00:00Z')})
22
+ rev.instance_variable_get(:@date).should == '2009-01-01T12:00:00.000000Z'
23
+ end
24
+ end
25
+
26
+ describe 'commit' do
27
+ before(:all) do
28
+ @repos = SvnFixture::repo('file_test').checkout
29
+ # @repos_path = @repos.instance_variable_get(:@repos_path)
30
+ @wc_path = @repos.instance_variable_get(:@wc_path)
31
+ @rev = @klass.new(1, 'msg', :author => 'author', :date => Time.parse('2009-01-01 12:00:00Z')) do
32
+ dir('test-dir')
33
+ end
34
+ @rev.commit(@repos)
35
+ @fs = @repos.repos.fs
36
+ end
37
+
38
+ after(:all) do
39
+ SvnFixture::Repository.destroy_all
40
+ end
41
+
42
+ it 'should process @block on root directory' do
43
+ File.exist?(File.join(@wc_path, 'test-dir')).should be_true
44
+ end
45
+
46
+ it 'should commit changes' do
47
+ @fs.root.dir?('test-dir').should be_true
48
+ end
49
+
50
+ it 'should set log message' do
51
+ @fs.prop(Svn::Core::PROP_REVISION_LOG, 1).should == 'msg'
52
+ end
53
+
54
+ it 'should set author if given' do
55
+ @fs.prop(Svn::Core::PROP_REVISION_AUTHOR, 1).should == 'author'
56
+ end
57
+
58
+ it 'should set date if given' do
59
+ @fs.prop(Svn::Core::PROP_REVISION_DATE, 1).should ==
60
+ Time.parse('2009-01-01T12:00:00.000000Z')
61
+ end
62
+
63
+ it 'should print warning if no changes' do
64
+ no_change_rev = @klass.new(2, 'msg')
65
+ no_change_rev.should_receive(:puts).
66
+ with("Warning: No change in revision 2 (SvnFixture::Revision#commit)")
67
+ no_change_rev.commit(@repos)
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,89 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe SvnFixture do
4
+
5
+ describe '.svn_time' do
6
+ it 'should format as expected by ::Svn::Client::Context#propset' do
7
+ t = Time.parse('2009-06-18 13:00')
8
+ SvnFixture.svn_time(t).should == '2009-06-18T13:00:00.000000Z'
9
+
10
+ d = Date.parse('2009-06-19')
11
+ SvnFixture.svn_time(d).should == '2009-06-19T00:00:00.000000Z'
12
+ end
13
+
14
+ it 'should parse the #to_s value if not a Date or Time or nil' do
15
+ t = '2009-06-18 13:00'
16
+ SvnFixture.svn_time(t).should == '2009-06-18T13:00:00.000000Z'
17
+ end
18
+
19
+ it 'should return nil if value is nil' do
20
+ SvnFixture.svn_time(nil).should be_nil
21
+ end
22
+ end
23
+
24
+ describe '.svn_prop' do
25
+ it 'should format Time/Date as expected by ::Svn::Client::Context#propset' do
26
+ t = Time.parse('2009-06-18 13:00')
27
+ SvnFixture.svn_prop(t).should == '2009-06-18T13:00:00.000000Z'
28
+
29
+ d = Date.parse('2009-06-19')
30
+ SvnFixture.svn_prop(d).should == '2009-06-19T00:00:00.000000Z'
31
+ end
32
+
33
+ it 'should leave alone non Time/Date values' do
34
+ t = 'Test'
35
+ SvnFixture.svn_prop(t).should == 'Test'
36
+ end
37
+ end
38
+
39
+ describe '.repo' do
40
+ it 'should call Repository.get' do
41
+ SvnFixture::Repository.should_receive(:get).with('test', '/tmp/repos_test', 'tmp/wc')
42
+ SvnFixture.repo('test', '/tmp/repos_test', 'tmp/wc')
43
+ end
44
+ end
45
+
46
+ describe '.simple_context' do
47
+ before(:each) do
48
+ SvnFixture::Repository.destroy_all
49
+ @repos = SvnFixture.repo('test').create
50
+ @repos_path = @repos.instance_variable_get(:@repos_path)
51
+ @wc_path = @repos.instance_variable_get(:@wc_path)
52
+ @path = File.join(@wc_path, 'file.txt')
53
+ @full_repos_path = "file://#{File.join(@repos_path, 'file.txt')}"
54
+ end
55
+
56
+ after(:each) do
57
+ FileUtils.rm_rf(@wc_path)
58
+ end
59
+
60
+ after(:all) do
61
+ SvnFixture::Repository.destroy_all
62
+ end
63
+
64
+ def add_prop_to_file
65
+ FileUtils.touch(@path)
66
+ @ctx.add(@path)
67
+ file = SvnFixture::File.new(@ctx, @path)
68
+ file.prop('name', 'Value')
69
+ @ctx.commit(@wc_path)
70
+ @ctx.propget('name', @path)[@full_repos_path].should == 'Value'
71
+ end
72
+
73
+ it 'should return a Context' do
74
+ SvnFixture.simple_context.should be_kind_of(::Svn::Client::Context)
75
+ end
76
+
77
+ it 'should be useable by File/Directory with a working copy checked out' do
78
+ @repos.checkout # Checkout under different context (although same setup)
79
+ @ctx = SvnFixture.simple_context
80
+ add_prop_to_file
81
+ end
82
+
83
+ it 'should be useable to checkout a working copy' do
84
+ @ctx = SvnFixture.simple_context
85
+ @ctx.checkout("file://" + ::File.expand_path(@repos_path), @wc_path)
86
+ add_prop_to_file
87
+ end
88
+ end
89
+ end