Skip to content

Commit 2b733ff

Browse files
author
Vicent Marti
committed
Merge pull request #497 from libgit2/arthur/rework-tests
Better Fixture Management
2 parents f792da5 + 95aed7a commit 2b733ff

28 files changed

+351
-546
lines changed

rugged.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ for testing and using the libgit2 library in a language that is awesome.
3030
desc
3131
s.add_development_dependency "rake-compiler", ">= 0.9.0"
3232
s.add_development_dependency "pry"
33-
s.add_development_dependency "minitest", "~> 3.0.0"
33+
s.add_development_dependency "minitest", "~> 3.0"
3434
end

test/blame_test.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
require "test_helper"
22
require "time"
33

4-
class BlameTest < Rugged::SandboxedTestCase
4+
class BlameTest < Rugged::TestCase
55
def setup
6-
super
7-
@repo = sandbox_init("testrepo")
6+
@repo = FixtureRepo.from_libgit2("testrepo")
87
@blame = Rugged::Blame.new(@repo, "branch_file.txt")
98
end
109

11-
def teardown
12-
@repo.close
13-
super
14-
end
15-
1610
def test_blame_index
1711
assert_equal 2, @blame.count
1812

test/blob_test.rb

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
require "test_helper"
22

33
class BlobTest < Rugged::TestCase
4-
include Rugged::RepositoryAccess
4+
def setup
5+
@repo = FixtureRepo.from_rugged("testrepo.git")
6+
end
57

68
def test_lookup_raises_error_if_object_type_does_not_match
79
assert_raises Rugged::InvalidError do
@@ -123,7 +125,10 @@ def test_blob_text_set_encoding
123125
end
124126

125127
class BlobWriteTest < Rugged::TestCase
126-
include Rugged::TempRepositoryAccess
128+
def setup
129+
@source_repo = FixtureRepo.from_rugged("testrepo.git")
130+
@repo = FixtureRepo.clone(@source_repo)
131+
end
127132

128133
def test_fetch_blob_content_with_nulls
129134
content = "100644 example_helper.rb\x00\xD3\xD5\xED\x9DA4_"+
@@ -171,7 +176,9 @@ def test_blob_is_binary
171176
end
172177

173178
class BlobLOCTest < Rugged::TestCase
174-
include Rugged::TempRepositoryAccess
179+
def setup
180+
@repo = FixtureRepo.from_rugged("testrepo.git")
181+
end
175182

176183
def write_blob(data)
177184
sha = Rugged::Blob.from_buffer(@repo, data)
@@ -209,15 +216,9 @@ def test_loc_mixed_no_end_nl
209216
end
210217
end
211218

212-
class BlobDiffTest < Rugged::SandboxedTestCase
219+
class BlobDiffTest < Rugged::TestCase
213220
def setup
214-
super
215-
@repo = sandbox_init("diff")
216-
end
217-
218-
def teardown
219-
@repo.close
220-
super
221+
@repo = FixtureRepo.from_libgit2("diff")
221222
end
222223

223224
def test_diff_blob
@@ -351,7 +352,9 @@ def test_diff_with_paths
351352
end
352353

353354
class BlobCreateFromIOTest < Rugged::TestCase
354-
include Rugged::TempRepositoryAccess
355+
def setup
356+
@repo = FixtureRepo.from_rugged("testrepo.git")
357+
end
355358

356359
def test_write_blob_from_io_with_hintpath
357360
file_path= File.join(TEST_DIR, (File.join('fixtures', 'archive.tar.gz')))
@@ -415,7 +418,9 @@ def test_write_blob_from_io_bad_io
415418
end
416419

417420
class BlobHashSignatureTest < Rugged::TestCase
418-
include Rugged::RepositoryAccess
421+
def setup
422+
@repo = FixtureRepo.from_rugged("testrepo.git")
423+
end
419424

420425
LOREM = <<-LOREM
421426
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
@@ -445,4 +450,3 @@ def test_signature_from_blob
445450
assert Rugged::Blob::HashSignature.compare(sig1, sig2) > 75
446451
end
447452
end
448-

test/branch_test.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
require "test_helper"
33

44
class BranchTest < Rugged::TestCase
5-
include Rugged::TempRepositoryAccess
5+
def setup
6+
@source_repo = FixtureRepo.from_rugged("testrepo.git")
7+
@repo = FixtureRepo.clone(@source_repo)
8+
end
69

710
def test_list_all_names
811
assert_equal [

test/cherrypick_test.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
require "test_helper"
22

3-
class WorkdirCherrypickTest < Rugged::SandboxedTestCase
3+
class WorkdirCherrypickTest < Rugged::TestCase
44
def setup
5-
super
6-
@repo = sandbox_init("cherrypick")
7-
end
8-
9-
def teardown
10-
@repo.close
11-
super
5+
@repo = FixtureRepo.from_libgit2("cherrypick")
126
end
137

148
def test_automerge

test/commit_test.rb

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
require "test_helper"
22

33
class TestCommit < Rugged::TestCase
4-
include Rugged::RepositoryAccess
4+
def setup
5+
@repo = FixtureRepo.from_rugged("testrepo.git")
6+
end
57

68
def test_lookup_raises_error_if_object_type_does_not_match
79
assert_raises Rugged::InvalidError do
@@ -174,7 +176,10 @@ def test_amend_commit_blank_message
174176
end
175177

176178
class CommitWriteTest < Rugged::TestCase
177-
include Rugged::TempRepositoryAccess
179+
def setup
180+
@source_repo = FixtureRepo.from_rugged("testrepo.git")
181+
@repo = FixtureRepo.clone(@source_repo)
182+
end
178183

179184
def test_write_commit_with_time
180185
person = {:name => 'Scott', :email => '[email protected]', :time => Time.now }
@@ -258,17 +263,9 @@ def test_write_empty_email_fails
258263
end
259264
end
260265

261-
class CommitToMboxTest < Rugged::SandboxedTestCase
266+
class CommitToMboxTest < Rugged::TestCase
262267
def setup
263-
super
264-
265-
@repo = sandbox_init "diff_format_email"
266-
end
267-
268-
def teardown
269-
@repo.close
270-
271-
super
268+
@repo = FixtureRepo.from_libgit2 "diff_format_email"
272269
end
273270

274271
def test_format_to_mbox

test/config_test.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
require "test_helper"
22

3-
class ConfigTest < Rugged::TestCase
4-
include Rugged::RepositoryAccess
3+
class ConfigTest < Rugged::TestCase
4+
def setup
5+
@repo = FixtureRepo.from_rugged("testrepo.git")
6+
end
57

68
def test_read_config_file
79
config = @repo.config
@@ -22,7 +24,11 @@ def test_read_global_config_file
2224
end
2325

2426
class ConfigWriteTest < Rugged::TestCase
25-
include Rugged::TempRepositoryAccess
27+
def setup
28+
@source_repo = FixtureRepo.from_rugged("testrepo.git")
29+
@repo = FixtureRepo.clone(@source_repo)
30+
@path = @repo.workdir
31+
end
2632

2733
def test_write_config_values
2834
config = @repo.config

0 commit comments

Comments
 (0)