Permalink
Browse files

Tests are back to TestCase because Fuck Specs

  • Loading branch information...
1 parent 20f0d57 commit 719c32a7a04659ddec0632c9d55e63c33b23a0d1 @vmg vmg committed Dec 13, 2012
Showing with 569 additions and 645 deletions.
  1. +22 −26 test/blob_test.rb
  2. +132 −154 test/branch_test.rb
  3. +11 −13 test/commit_test.rb
  4. +11 −15 test/config_test.rb
  5. +154 −160 test/index_test.rb
  6. +5 −10 test/lib_test.rb
  7. +8 −11 test/object_test.rb
  8. +80 −102 test/reference_test.rb
  9. +4 −8 test/remote_test.rb
  10. +16 −22 test/repo_pack_test.rb
  11. +42 −54 test/repo_test.rb
  12. +20 −25 test/tag_test.rb
  13. +33 −17 test/test_helper.rb
  14. +17 −15 test/tree_test.rb
  15. +14 −13 test/walker_test.rb
View
48 test/blob_test.rb
@@ -1,38 +1,34 @@
require "test_helper"
-describe Rugged::Blob do
- before do
- @path = File.dirname(__FILE__) + '/fixtures/testrepo.git/'
- @repo = Rugged::Repository.new(@path)
- @oid = "fa49b077972391ad58037050f2a75f74e3671e92"
- end
+class BlobTest < Rugged::TestCase
+ include Rugged::RepositoryAccess
- describe "when loading blobs" do
+ def test_read_blob_data
+ oid = "fa49b077972391ad58037050f2a75f74e3671e92"
+ blob = @repo.lookup(oid)
+ assert_equal 9, blob.size
+ assert_equal "new file\n", blob.content
+ assert_equal :blob, blob.type
+ assert_equal oid, blob.oid
+ end
+end
- it "can read the blob data" do
- blob = @repo.lookup(@oid)
- assert_equal 9, blob.size
- assert_equal "new file\n", blob.content
- assert_equal :blob, blob.type
- assert_equal @oid, blob.oid
- end
+class BlobWriteTest < Rugged::TestCase
+ include Rugged::TempRepositoryAccess
- it "gets the complete content if it has nulls" do
- content = "100644 example_helper.rb\x00\xD3\xD5\xED\x9DA4_"+
- "\xE3\xC3\nK\xCD<!\xEA-_\x9E\xDC=40000 examples\x00"+
- "\xAE\xCB\xE9d!|\xB9\xA6\x96\x024],U\xEE\x99\xA2\xEE\xD4\x92"
+ def test_fetch_blob_content_with_nulls
+ content = "100644 example_helper.rb\x00\xD3\xD5\xED\x9DA4_"+
+ "\xE3\xC3\nK\xCD<!\xEA-_\x9E\xDC=40000 examples\x00"+
+ "\xAE\xCB\xE9d!|\xB9\xA6\x96\x024],U\xEE\x99\xA2\xEE\xD4\x92"
- content.force_encoding('binary') if content.respond_to?(:force_encoding)
+ content.force_encoding('binary') if content.respond_to?(:force_encoding)
- oid = @repo.write(content, 'tree')
- blob = @repo.lookup(oid)
- assert_equal content, blob.read_raw.data
- rm_loose(oid)
- end
+ oid = @repo.write(content, 'tree')
+ blob = @repo.lookup(oid)
+ assert_equal content, blob.read_raw.data
end
- it "can write new blob data" do
+ def test_write_blob_data
oid = Rugged::Blob.create(@repo, "a new blob content")
- rm_loose(oid)
end
end
View
286 test/branch_test.rb
@@ -1,214 +1,192 @@
# encoding: UTF-8
require "test_helper"
-describe Rugged::Branch do
- before do
- @path = temp_repo("testrepo.git")
- @repo = Rugged::Repository.new(@path)
+class BranchTest < Rugged::TestCase
+ include Rugged::TempRepositoryAccess
+
+ def test_list_all_names
+ assert_equal [
+ "master",
+ "origin/HEAD",
+ "origin/master",
+ "origin/packed",
+ ], Rugged::Branch.each_name(@repo).sort
end
- after do
- destroy_temp_repo(@path)
+ def test_list_only_local_branches
+ assert_equal ["master"], Rugged::Branch.each_name(@repo, :local).sort
end
- describe "Rugged::Branch.each_name" do
-
- it "lists the names of all branches in a bare repository" do
- assert_equal [
- "master",
- "origin/HEAD",
- "origin/master",
- "origin/packed",
- ], Rugged::Branch.each_name(@repo).sort
- end
-
- it "can list only local branches" do
- assert_equal ["master"], Rugged::Branch.each_name(@repo, :local).sort
- end
-
- it "can list only remote branches" do
- assert_equal [
- "origin/HEAD",
- "origin/master",
- "origin/packed",
- ], Rugged::Branch.each_name(@repo, :remote).sort
- end
+ def test_list_only_remote_branches
+ assert_equal [
+ "origin/HEAD",
+ "origin/master",
+ "origin/packed",
+ ], Rugged::Branch.each_name(@repo, :remote).sort
end
- describe "Rugged::Branch#tip" do
-
- it "returns the latest commit of the branch" do
- tip = Rugged::Branch.lookup(@repo, "master").tip
+ def test_get_latest_commit_in_branch
+ tip = Rugged::Branch.lookup(@repo, "master").tip
- assert_kind_of Rugged::Commit, tip
- assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", tip.oid
- end
+ assert_kind_of Rugged::Commit, tip
+ assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", tip.oid
end
- describe "Rugged::Branch.lookup" do
-
- it "can look up local branches" do
- branch = Rugged::Branch.lookup(@repo, "master")
- refute_nil branch
+ def test_lookup_local_branch
+ branch = Rugged::Branch.lookup(@repo, "master")
+ refute_nil branch
- assert_equal "master", branch.name
- assert_equal "refs/heads/master", branch.canonical_name
- assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", branch.tip.oid
- end
+ assert_equal "master", branch.name
+ assert_equal "refs/heads/master", branch.canonical_name
+ assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", branch.tip.oid
+ end
- it "can look up remote branches" do
- branch = Rugged::Branch.lookup(@repo, "origin/packed", :remote)
- refute_nil branch
+ def test_lookup_remote_branches
+ branch = Rugged::Branch.lookup(@repo, "origin/packed", :remote)
+ refute_nil branch
- assert_equal "origin/packed", branch.name
- assert_equal "refs/remotes/origin/packed", branch.canonical_name
- assert_equal "41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9", branch.tip.oid
- end
+ assert_equal "origin/packed", branch.name
+ assert_equal "refs/remotes/origin/packed", branch.canonical_name
+ assert_equal "41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9", branch.tip.oid
+ end
- it "can look up branches with non 7-bit ASCII characters" do
- new_branch = @repo.create_branch("Ångström", "5b5b025afb0b4c913b4c338a42934a3863bf3644")
- refute_nil new_branch
+ def test_lookup_unicode_branch_name
+ new_branch = @repo.create_branch("Ångström", "5b5b025afb0b4c913b4c338a42934a3863bf3644")
+ refute_nil new_branch
- retrieved_branch = Rugged::Branch.lookup(@repo, "Ångström")
- refute_nil retrieved_branch
+ retrieved_branch = Rugged::Branch.lookup(@repo, "Ångström")
+ refute_nil retrieved_branch
- assert_equal new_branch, retrieved_branch
- end
+ assert_equal new_branch, retrieved_branch
end
- describe "Rugged::Branch.delete" do
-
- it "deletes a branch from the repository" do
- branch = @repo.create_branch("test_branch")
- branch.delete!
- assert_nil Rugged::Branch.lookup(@repo, "test_branch")
- end
+ def test_delete_branch
+ branch = @repo.create_branch("test_branch")
+ branch.delete!
+ assert_nil Rugged::Branch.lookup(@repo, "test_branch")
end
- describe "Rugged::Branch.move" do
+ def test_rename_branch
+ branch = @repo.create_branch("test_branch")
- it "renames a branch" do
- branch = @repo.create_branch("test_branch")
+ branch.move('other_branch')
- branch.move('other_branch')
-
- assert_nil Rugged::Branch.lookup(@repo, "test_branch")
- refute_nil Rugged::Branch.lookup(@repo, "other_branch")
- end
+ assert_nil Rugged::Branch.lookup(@repo, "test_branch")
+ refute_nil Rugged::Branch.lookup(@repo, "other_branch")
end
- describe "Rugged::Repository#create_branch" do
+ def test_create_new_branch
+ new_branch = @repo.create_branch("test_branch", "5b5b025afb0b4c913b4c338a42934a3863bf3644")
- it "can create a new branch" do
- new_branch = @repo.create_branch("test_branch", "5b5b025afb0b4c913b4c338a42934a3863bf3644")
+ refute_nil new_branch
+ assert_equal "test_branch", new_branch.name
+ assert_equal "refs/heads/test_branch", new_branch.canonical_name
- refute_nil new_branch
- assert_equal "test_branch", new_branch.name
- assert_equal "refs/heads/test_branch", new_branch.canonical_name
+ refute_nil new_branch.tip
+ assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", new_branch.tip.oid
- refute_nil new_branch.tip
- assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", new_branch.tip.oid
+ refute_nil @repo.branches.find { |p| p.name == "test_branch" }
+ end
- refute_nil @repo.branches.find { |p| p.name == "test_branch" }
- end
+ def test_create_unicode_branch
+ branch_name = "A\314\212ngstro\314\210m"
+ new_branch = @repo.create_branch(branch_name, "5b5b025afb0b4c913b4c338a42934a3863bf3644")
- it "can create branches with non 7-bit ASCII names" do
- branch_name = "A\314\212ngstro\314\210m"
- new_branch = @repo.create_branch(branch_name, "5b5b025afb0b4c913b4c338a42934a3863bf3644")
+ refute_nil new_branch
+ assert_equal branch_name, new_branch.name
+ assert_equal "refs/heads/#{branch_name}", new_branch.canonical_name
- refute_nil new_branch
- assert_equal branch_name, new_branch.name
- assert_equal "refs/heads/#{branch_name}", new_branch.canonical_name
+ refute_nil new_branch.tip
+ assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", new_branch.tip.oid
- refute_nil new_branch.tip
- assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", new_branch.tip.oid
+ refute_nil @repo.branches.find { |p| p.name == branch_name }
+ end
- refute_nil @repo.branches.find { |p| p.name == branch_name }
- end
+ def test_create_branch_short_sha
+ new_branch = @repo.create_branch("test_branch", "5b5b025")
- it "can create a new branch with an abbreviated sha" do
- new_branch = @repo.create_branch("test_branch", "5b5b025")
+ refute_nil new_branch
+ assert_equal "test_branch", new_branch.name
+ assert_equal "refs/heads/test_branch", new_branch.canonical_name
- refute_nil new_branch
- assert_equal "test_branch", new_branch.name
- assert_equal "refs/heads/test_branch", new_branch.canonical_name
+ refute_nil new_branch.tip
+ assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", new_branch.tip.oid
+ end
- refute_nil new_branch.tip
- assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", new_branch.tip.oid
- end
+ def test_create_branch_from_tag
+ new_branch = @repo.create_branch("test_branch", "refs/tags/v0.9")
- it "can create a new branch from a tag name" do
- new_branch = @repo.create_branch("test_branch", "refs/tags/v0.9")
+ refute_nil new_branch
+ assert_equal "test_branch", new_branch.name
+ assert_equal "refs/heads/test_branch", new_branch.canonical_name
- refute_nil new_branch
- assert_equal "test_branch", new_branch.name
- assert_equal "refs/heads/test_branch", new_branch.canonical_name
+ refute_nil new_branch.tip
+ assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", new_branch.tip.oid
+ end
- refute_nil new_branch.tip
- assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", new_branch.tip.oid
- end
+ def test_create_branch_from_head
+ new_branch = @repo.create_branch("test_branch")
- it "can create a new branch from implicit head" do
- new_branch = @repo.create_branch("test_branch")
+ refute_nil new_branch
+ assert_equal "test_branch", new_branch.name
+ assert_equal "refs/heads/test_branch", new_branch.canonical_name
- refute_nil new_branch
- assert_equal "test_branch", new_branch.name
- assert_equal "refs/heads/test_branch", new_branch.canonical_name
+ refute_nil new_branch.tip
+ assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", new_branch.tip.oid
+ end
- refute_nil new_branch.tip
- assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", new_branch.tip.oid
- end
+ def test_create_branch_explicit_head
+ new_branch = @repo.create_branch("test_branch", "HEAD")
- it "can create a new branch from explicit head" do
- new_branch = @repo.create_branch("test_branch", "HEAD")
+ refute_nil new_branch
+ assert_equal "test_branch", new_branch.name
+ assert_equal "refs/heads/test_branch", new_branch.canonical_name
- refute_nil new_branch
- assert_equal "test_branch", new_branch.name
- assert_equal "refs/heads/test_branch", new_branch.canonical_name
+ refute_nil new_branch.tip
+ assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", new_branch.tip.oid
+ end
- refute_nil new_branch.tip
- assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", new_branch.tip.oid
- end
+ def test_create_branch_from_commit
+ new_branch = @repo.create_branch("test_branch",
+ Rugged::Commit.lookup(@repo, "5b5b025afb0b4c913b4c338a42934a3863bf3644"))
- it "can create a new branch from a commit object" do
- new_branch = @repo.create_branch("test_branch", Rugged::Commit.lookup(@repo, "5b5b025afb0b4c913b4c338a42934a3863bf3644"))
+ refute_nil new_branch
+ assert_equal "test_branch", new_branch.name
+ assert_equal "refs/heads/test_branch", new_branch.canonical_name
- refute_nil new_branch
- assert_equal "test_branch", new_branch.name
- assert_equal "refs/heads/test_branch", new_branch.canonical_name
+ refute_nil new_branch.tip
+ assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", new_branch.tip.oid
+ end
- refute_nil new_branch.tip
- assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", new_branch.tip.oid
+ def test_create_branch_from_tree_fails
+ assert_raises ArgumentError, Rugged::InvalidError do
+ @repo.create_branch("test_branch",
+ Rugged::Tree.lookup(@repo, "f60079018b664e4e79329a7ef9559c8d9e0378d1"))
end
+ end
- it "can not create a new branch from a tree" do
- assert_raises ArgumentError, Rugged::InvalidError do
- @repo.create_branch("test_branch", Rugged::Tree.lookup(@repo, "f60079018b664e4e79329a7ef9559c8d9e0378d1"))
- end
- end
-
- it "can not create a new branch from a blob" do
- assert_raises ArgumentError, Rugged::InvalidError do
- @repo.create_branch("test_branch", Rugged::Blob.lookup(@repo, "1385f264afb75a56a5bec74243be9b367ba4ca08"))
- end
+ def test_create_branch_from_blob_fails
+ assert_raises ArgumentError, Rugged::InvalidError do
+ @repo.create_branch("test_branch",
+ Rugged::Blob.lookup(@repo, "1385f264afb75a56a5bec74243be9b367ba4ca08"))
end
+ end
- it "can not create a new branch from an unknown branch" do
- assert_raises Rugged::ReferenceError do
- @repo.create_branch("test_branch", "i_do_not_exist")
- end
+ def test_create_branch_from_unknown_ref_fails
+ assert_raises Rugged::ReferenceError do
+ @repo.create_branch("test_branch", "i_do_not_exist")
end
+ end
- it "can not create a new branch from an unknown commit" do
- assert_raises Rugged::ReferenceError do
- @repo.create_branch("test_branch", "dd15de908706711b51b7acb24faab726d2b3cb16")
- end
+ def test_create_branch_from_unknown_commit_fails
+ assert_raises Rugged::ReferenceError do
+ @repo.create_branch("test_branch", "dd15de908706711b51b7acb24faab726d2b3cb16")
end
+ end
- it "can not create a new branch from a non canonical branch name" do
- assert_raises Rugged::ReferenceError do
- @repo.create_branch("test_branch", "packed")
- end
+ def test_create_branch_from_non_canonical_fails
+ assert_raises Rugged::ReferenceError do
+ @repo.create_branch("test_branch", "packed")
end
end
end
View
24 test/commit_test.rb
@@ -1,12 +1,9 @@
require "test_helper"
-describe Rugged::Commit do
- before do
- @path = File.dirname(__FILE__) + '/fixtures/testrepo.git/'
- @repo = Rugged::Repository.new(@path)
- end
+class TestCommit < Rugged::TestCase
+ include Rugged::RepositoryAccess
- it "can read the commit data" do
+ def test_read_commit_data
oid = "8496071c1b46c854b31185ea97743be6a8774479"
obj = @repo.lookup(oid)
@@ -30,30 +27,34 @@
assert_equal [], obj.parents
end
- it "can have multiple parents" do
+ def test_commit_with_multiple_parents
oid = "a4a7dce85cf63874e984719f4fdd239f5145052f"
obj = @repo.lookup(oid)
parents = obj.parents.map {|c| c.oid }
assert parents.include?("9fd738e8f7967c078dceed8190330fc8648ee56a")
assert parents.include?("c47800c7266a2be04c571c04d5a6614691ea99bd")
end
- it "can list parent oids only" do
+ def test_get_parent_oids
oid = "a4a7dce85cf63874e984719f4fdd239f5145052f"
obj = @repo.lookup(oid)
parents = obj.parent_oids
assert parents.include?("9fd738e8f7967c078dceed8190330fc8648ee56a")
assert parents.include?("c47800c7266a2be04c571c04d5a6614691ea99bd")
end
- it "can read a tree oid only" do
+ def test_get_tree_oid
oid = "8496071c1b46c854b31185ea97743be6a8774479"
obj = @repo.lookup(oid)
assert_equal obj.tree_oid, "181037049a54a1eb5fab404658a3a250b44335d7"
end
+end
+
+class CommitWriteTest < Rugged::TestCase
+ include Rugged::TempRepositoryAccess
- it "can write new commit data" do
+ def test_write_a_commit
person = {:name => 'Scott', :email => 'schacon@gmail.com', :time => Time.now }
commit_oid = Rugged::Commit.create(@repo,
@@ -62,8 +63,5 @@
:author => person,
:parents => [@repo.head.target],
:tree => "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b")
-
- rm_loose(commit_oid)
end
-
end
View
26 test/config_test.rb
@@ -1,33 +1,30 @@
require "test_helper"
-describe Rugged::Config do
- before do
- @path = temp_repo('testrepo.git')
- @repo = Rugged::Repository.new(@path)
- end
-
- after do
- destroy_temp_repo(@path)
- end
+class ConfigTest < Rugged::TestCase
+ include Rugged::RepositoryAccess
- it "can read the config file from repo" do
+ def test_read_config_file
config = @repo.config
assert_equal 'false', config['core.bare']
assert_nil config['not.exist']
end
- it "can read the config file from path" do
+ def test_read_config_from_path
config = Rugged::Config.new(File.join(@repo.path, 'config'))
assert_equal 'false', config['core.bare']
end
- it "can read the global config file" do
+ def test_read_global_config_file
config = Rugged::Config.global
assert config['user.name'] != nil
assert_nil config['core.bare']
end
+end
+
+class ConfigWriteTest < Rugged::TestCase
+ include Rugged::TempRepositoryAccess
- it "can write config values" do
+ def test_write_config_values
config = @repo.config
config['custom.value'] = 'my value'
@@ -38,12 +35,11 @@
assert_match(/value = my value/, content)
end
- it "can delete config values" do
+ def test_delete_config_values
config = @repo.config
config.delete('core.bare')
config2 = @repo.config
assert_nil config2.get('core.bare')
end
-
end
View
314 test/index_test.rb
@@ -3,9 +3,8 @@
require 'tempfile'
require 'fileutils'
-
-describe Rugged::Index do
- def new_index_entry
+class IndexTest < Rugged::TestCase
+ def self.new_index_entry
now = Time.now
{
:path => "new_path",
@@ -22,198 +21,193 @@ def new_index_entry
}
end
- describe "when reading the index" do
- before do
- path = File.dirname(__FILE__) + '/fixtures/testrepo.git/index'
- @index = Rugged::Index.new(path)
- end
+ def setup
+ path = File.dirname(__FILE__) + '/fixtures/testrepo.git/index'
+ @index = Rugged::Index.new(path)
+ end
- it "can iterate through the index" do
- enum = @index.each
- assert enum.kind_of? Enumerable
+ def test_iteration
+ enum = @index.each
+ assert enum.kind_of? Enumerable
- i = 0
- @index.each { |e| i += 1 }
- assert_equal @index.count, i
- end
+ i = 0
+ @index.each { |e| i += 1 }
+ assert_equal @index.count, i
+ end
- it "can count index entries" do
- assert_equal 2, @index.count
- end
+ def test_index_size
+ assert_equal 2, @index.count
+ end
- it "can clear the in-memory index" do
- @index.clear
- assert_equal 0, @index.count
- end
+ def test_empty_index
+ @index.clear
+ assert_equal 0, @index.count
+ end
- it "can remove entries from the index" do
- @index.remove 'new.txt'
- assert_equal 1, @index.count
- end
+ def test_remove_entries
+ @index.remove 'new.txt'
+ assert_equal 1, @index.count
+ end
- it "can get all data from an entry" do
- e = @index[0]
- assert_equal 'README', e[:path]
- assert_equal '1385f264afb75a56a5bec74243be9b367ba4ca08', e[:oid]
- assert_equal 1273360380, e[:mtime].to_i
- assert_equal 1273360380, e[:ctime].to_i
- assert_equal 4, e[:file_size]
- assert_equal 234881026, e[:dev]
- assert_equal 6674088, e[:ino]
- assert_equal 33188, e[:mode]
- assert_equal 501, e[:uid]
- assert_equal 0, e[:gid]
- assert_equal false, e[:valid]
- assert_equal 0, e[:stage]
-
- e = @index[1]
- assert_equal 'new.txt', e[:path]
- assert_equal 'fa49b077972391ad58037050f2a75f74e3671e92', e[:oid]
- end
+ def test_get_entry_data
+ e = @index[0]
+ assert_equal 'README', e[:path]
+ assert_equal '1385f264afb75a56a5bec74243be9b367ba4ca08', e[:oid]
+ assert_equal 1273360380, e[:mtime].to_i
+ assert_equal 1273360380, e[:ctime].to_i
+ assert_equal 4, e[:file_size]
+ assert_equal 234881026, e[:dev]
+ assert_equal 6674088, e[:ino]
+ assert_equal 33188, e[:mode]
+ assert_equal 501, e[:uid]
+ assert_equal 0, e[:gid]
+ assert_equal false, e[:valid]
+ assert_equal 0, e[:stage]
+
+ e = @index[1]
+ assert_equal 'new.txt', e[:path]
+ assert_equal 'fa49b077972391ad58037050f2a75f74e3671e92', e[:oid]
+ end
- it "can iterate over the entries" do
- itr_test = @index.sort { |a, b| a[:oid] <=> b[:oid] }.map { |e| e[:path] }.join(':')
- assert_equal "README:new.txt", itr_test
- end
+ def test_iterate_entries
+ itr_test = @index.sort { |a, b| a[:oid] <=> b[:oid] }.map { |e| e[:path] }.join(':')
+ assert_equal "README:new.txt", itr_test
+ end
- it "can update entries" do
- now = Time.at Time.now.to_i
- e = @index[0]
-
- e[:oid] = "12ea3153a78002a988bb92f4123e7e831fd1138a"
- e[:mtime] = now
- e[:ctime] = now
- e[:file_size] = 1000
- e[:dev] = 234881027
- e[:ino] = 88888
- e[:mode] = 33199
- e[:uid] = 502
- e[:gid] = 502
- e[:stage] = 3
-
- @index.add(e)
- new_e = @index.get e[:path], 3
-
- assert_equal e, new_e
- end
+ def test_update_entries
+ now = Time.at Time.now.to_i
+ e = @index[0]
+
+ e[:oid] = "12ea3153a78002a988bb92f4123e7e831fd1138a"
+ e[:mtime] = now
+ e[:ctime] = now
+ e[:file_size] = 1000
+ e[:dev] = 234881027
+ e[:ino] = 88888
+ e[:mode] = 33199
+ e[:uid] = 502
+ e[:gid] = 502
+ e[:stage] = 3
+
+ @index.add(e)
+ new_e = @index.get e[:path], 3
+
+ assert_equal e, new_e
+ end
- it "can add new entries" do
- e = new_index_entry
- @index << e
- assert_equal 3, @index.count
- itr_test = @index.sort { |a, b| a[:oid] <=> b[:oid] }.map { |x| x[:path] }.join(':')
- assert_equal "README:new_path:new.txt", itr_test
- end
+ def test_add_new_entries
+ e = IndexTest.new_index_entry
+ @index << e
+ assert_equal 3, @index.count
+ itr_test = @index.sort { |a, b| a[:oid] <=> b[:oid] }.map { |x| x[:path] }.join(':')
+ assert_equal "README:new_path:new.txt", itr_test
end
+end
- describe "when writing the index" do
- before do
- path = File.dirname(__FILE__) + '/fixtures/testrepo.git/index'
- @tmppath = Tempfile.new('index').path
- FileUtils.copy(path, @tmppath)
- @index = Rugged::Index.new(@tmppath)
- end
+class IndexWriteTest < Rugged::TestCase
+ def setup
+ path = File.dirname(__FILE__) + '/fixtures/testrepo.git/index'
+ @tmppath = Tempfile.new('index').path
+ FileUtils.copy(path, @tmppath)
+ @index = Rugged::Index.new(@tmppath)
+ end
- it "add raises if it gets something weird" do
- assert_raises TypeError do
- @index.add(21)
- end
+ def teardown
+ File.delete(@tmppath)
+ end
+
+ def test_raises_when_writing_invalid_entries
+ assert_raises TypeError do
+ @index.add(21)
end
+ end
- it "can write a new index" do
- e = new_index_entry
- @index << e
+ def test_can_write_index
+ e = IndexTest.new_index_entry
+ @index << e
- e[:path] = "else.txt"
- @index << e
+ e[:path] = "else.txt"
+ @index << e
- @index.write
+ @index.write
- index2 = Rugged::Index.new(@tmppath)
+ index2 = Rugged::Index.new(@tmppath)
- itr_test = index2.sort { |a, b| a[:oid] <=> b[:oid] }.map { |x| x[:path] }.join(':')
- assert_equal "README:else.txt:new_path:new.txt", itr_test
- assert_equal 4, index2.count
- end
+ itr_test = index2.sort { |a, b| a[:oid] <=> b[:oid] }.map { |x| x[:path] }.join(':')
+ assert_equal "README:else.txt:new_path:new.txt", itr_test
+ assert_equal 4, index2.count
+ end
+end
+
+class IndexWorkdirTest < Rugged::TestCase
+ def setup
+ @tmppath = Dir.mktmpdir
+ @repo = Rugged::Repository.init_at(@tmppath, false)
+ @index = @repo.index
end
- describe "when interacting with the working directory" do
- before do
- @tmppath = Dir.mktmpdir
- @repo = Rugged::Repository.init_at(@tmppath, false)
- @index = @repo.index
- end
+ def teardown
+ FileUtils.remove_entry_secure(@tmppath)
+ end
- after do
- FileUtils.remove_entry_secure(@tmppath)
+ def test_adding_a_path
+ File.open(File.join(@tmppath, 'test.txt'), 'w') do |f|
+ f.puts "test content"
end
+ @index.add('test.txt')
+ @index.write
- it "can add from a path" do
- File.open(File.join(@tmppath, 'test.txt'), 'w') do |f|
- f.puts "test content"
- end
- @index.add('test.txt')
- @index.write
+ index2 = Rugged::Index.new(@tmppath + '/.git/index')
+ assert_equal index2[0][:path], 'test.txt'
+ end
- index2 = Rugged::Index.new(@tmppath + '/.git/index')
- assert_equal index2[0][:path], 'test.txt'
+ def test_reloading_index
+ File.open(File.join(@tmppath, 'test.txt'), 'w') do |f|
+ f.puts "test content"
end
+ @index.add('test.txt')
+ @index.write
- it "can reload the index" do
- File.open(File.join(@tmppath, 'test.txt'), 'w') do |f|
- f.puts "test content"
- end
- @index.add('test.txt')
- @index.write
+ rindex = Rugged::Index.new(File.join(@tmppath, '/.git/index'))
+ e = rindex['test.txt']
+ assert_equal 0, e[:stage]
- rindex = Rugged::Index.new(File.join(@tmppath, '/.git/index'))
- e = rindex['test.txt']
- assert_equal 0, e[:stage]
+ rindex << IndexTest.new_index_entry
+ rindex.write
- rindex << new_index_entry
- rindex.write
+ assert_equal 1, @index.count
+ @index.reload
+ assert_equal 2, @index.count
- assert_equal 1, @index.count
- @index.reload
- assert_equal 2, @index.count
-
- e = @index.get 'new_path', 3
- assert_equal e[:mode], 33199
- end
+ e = @index.get 'new_path', 3
+ assert_equal e[:mode], 33199
end
+end
+class IndexRepositoryTest < Rugged::TestCase
+ include Rugged::TempRepositoryAccess
- describe "when interacting with Rugged::Repository" do
- before do
- @path = temp_repo("testrepo.git")
- @repo = Rugged::Repository.new(@path)
- @index = @repo.index
- end
-
- after do
- destroy_temp_repo(@path)
- end
-
- it "idempotent read_tree/write_tree" do
- head_sha = Rugged::Reference.lookup(@repo,'HEAD').resolve.target
- tree = @repo.lookup(head_sha).tree
- @index.read_tree(tree)
+ def test_idempotent_read_write
+ head_sha = Rugged::Reference.lookup(@repo,'HEAD').resolve.target
+ tree = @repo.lookup(head_sha).tree
+ index = @repo.index
+ index.read_tree(tree)
- index_tree_sha = @index.write_tree
- index_tree = @repo.lookup(index_tree_sha)
- assert_equal tree.oid, index_tree.oid
- end
+ index_tree_sha = index.write_tree
+ index_tree = @repo.lookup(index_tree_sha)
+ assert_equal tree.oid, index_tree.oid
+ end
+ def test_build_tree_from_index
+ head_sha = Rugged::Reference.lookup(@repo,'refs/remotes/origin/packed').resolve.target
+ tree = @repo.lookup(head_sha).tree
- it "build tree from index on non-HEAD branch" do
- head_sha = Rugged::Reference.lookup(@repo,'refs/remotes/origin/packed').resolve.target
- tree = @repo.lookup(head_sha).tree
- @index.read_tree(tree)
- @index.remove('second.txt')
+ index = @repo.index
+ index.read_tree(tree)
+ index.remove('second.txt')
- new_tree_sha = @index.write_tree
- assert head_sha != new_tree_sha
- assert_nil @repo.lookup(new_tree_sha)['second.txt']
- end
+ new_tree_sha = index.write_tree
+ assert head_sha != new_tree_sha
+ assert_nil @repo.lookup(new_tree_sha)['second.txt']
end
end
View
15 test/lib_test.rb
@@ -1,42 +1,37 @@
require "test_helper"
require 'base64'
-describe Rugged do
-
- it "can convert hex into raw oid" do
+class RuggedTest < Rugged::TestCase
+ def test_hex_to_raw_oid
raw = Rugged::hex_to_raw("ce08fe4884650f067bd5703b6a59a8b3b3c99a09")
b64raw = Base64.encode64(raw).strip
assert_equal "zgj+SIRlDwZ71XA7almos7PJmgk=", b64raw
- end
- it "converts hex into raw oid correctly" do
hex = "ce08fe4884650f067bd5703b6a59a8b3b3c99a09"
raw1 = Rugged::hex_to_raw(hex)
raw2 = [hex].pack("H*")
assert_equal raw1, raw2
end
- it "can convert raw oid into hex" do
+ def test_raw_to_hex
raw = Base64.decode64("FqASNFZ4mrze9Ld1ITwjqL109eA=")
hex = Rugged::raw_to_hex(raw)
assert_equal "16a0123456789abcdef4b775213c23a8bd74f5e0", hex
- end
- it "converts raw into hex oid correctly" do
raw = Rugged::hex_to_raw("ce08fe4884650f067bd5703b6a59a8b3b3c99a09")
hex1 = Rugged::raw_to_hex(raw)
hex2 = raw.unpack("H*")[0]
assert_equal hex1, hex2
end
- it "converts raw into hex with null bytes" do
+ def test_raw_to_hex_with_nulls
raw = Rugged::hex_to_raw("702f00394564b24052511cb69961164828bf5494")
hex1 = Rugged::raw_to_hex(raw)
hex2 = raw.unpack("H*")[0]
assert_equal hex1, hex2
end
- it "prettifies commit messages properly" do
+ def test_prettify_commit_messages
message = <<-MESSAGE
Testing this whole prettify business
View
19 test/object_test.rb
@@ -1,43 +1,40 @@
require "test_helper"
require 'base64'
-describe Rugged::Object do
- before do
- @path = File.dirname(__FILE__) + '/fixtures/testrepo.git/'
- @repo = Rugged::Repository.new(@path)
- end
+class ObjectTest < Rugged::TestCase
+ include Rugged::RepositoryAccess
- it "cannot lookup a non-existant object" do
+ def test_fail_to_lookup_inexistant_object
assert_raises Rugged::OdbError do
@repo.lookup("a496071c1b46c854b31185ea97743be6a8774479")
end
end
- it "can lookup an object" do
+ def test_lookup_object
obj = @repo.lookup("8496071c1b46c854b31185ea97743be6a8774479")
assert_equal :commit, obj.type
assert_equal '8496071c1b46c854b31185ea97743be6a8774479', obj.oid
end
- it "same looked up objects are the same" do
+ def test_objects_are_the_same
obj = @repo.lookup("8496071c1b46c854b31185ea97743be6a8774479")
obj2 = @repo.lookup("8496071c1b46c854b31185ea97743be6a8774479")
assert_equal obj, obj2
end
- it "can read raw data from an object" do
+ def test_read_raw_data
obj = @repo.lookup("8496071c1b46c854b31185ea97743be6a8774479")
assert obj.read_raw
end
- it "can lookup an object by revision string" do
+ def test_lookup_by_rev
obj = @repo.rev_parse("v1.0")
assert "0c37a5391bbff43c37f0d0371823a5509eed5b1d", obj.oid
obj = @repo.rev_parse("v1.0^1")
assert "8496071c1b46c854b31185ea97743be6a8774479", obj.oid
end
- it "can lookup just an object's oid by revision string" do
+ def test_lookup_oid_by_rev
oid = @repo.rev_parse_oid("v1.0")
assert "0c37a5391bbff43c37f0d0371823a5509eed5b1d", oid
@repo.rev_parse_oid("v1.0^1")
View
182 test/reference_test.rb
@@ -1,53 +1,39 @@
# encoding: UTF-8
require File.expand_path "../test_helper", __FILE__
-describe Rugged::Reference do
- UNICODE_REF_NAME = "A\314\212ngstro\314\210m"
-
- before do
- @path = File.dirname(__FILE__) + '/fixtures/testrepo.git'
- @repo = Rugged::Repository.new(@path)
- end
+class ReferenceTest < Rugged::TestCase
+ include Rugged::RepositoryAccess
- after do
- FileUtils.remove_entry_secure(@path + '/refs/heads/unit_test', true)
- FileUtils.remove_entry_secure(@path + "/refs/heads/#{UNICODE_REF_NAME}", true)
- end
+ UNICODE_REF_NAME = "A\314\212ngstro\314\210m"
- it "can list references" do
+ def test_list_references
refs = @repo.refs.map { |r| r.name.gsub("refs/", '') }.sort.join(':')
assert_equal "heads/master:heads/packed:tags/v0.9:tags/v1.0", refs
end
- it "can list references with non 7-bit ASCII characters" do
- Rugged::Reference.create(@repo, "refs/heads/#{UNICODE_REF_NAME}", "refs/heads/master")
- refs = @repo.refs.map { |r| r.name.gsub("refs/", '') }.sort.join(':')
- assert_equal "heads/#{UNICODE_REF_NAME}:heads/master:heads/packed:tags/v0.9:tags/v1.0", refs
- end
-
- it "can list filtered references from regex" do
+ def test_can_filter_refs_with_regex
refs = @repo.refs(/tags/).map { |r| r.name.gsub("refs/", '') }.sort.join(':')
assert_equal "tags/v0.9:tags/v1.0", refs
end
- it "can list filtered references from string" do
+ def test_can_filter_refs_with_string
refs = @repo.refs('0.9').map { |r| r.name.gsub("refs/", '') }.sort.join(':')
assert_equal "tags/v0.9", refs
end
- it "can open reference" do
+ def test_can_open_reference
ref = Rugged::Reference.lookup(@repo, "refs/heads/master")
assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", ref.target
assert_equal :direct, ref.type
assert_equal "refs/heads/master", ref.name
end
- it "will return nil for an invalid reference" do
+ def test_looking_up_missing_ref_returns_nil
ref = Rugged::Reference.lookup(@repo, "lol/wut")
assert_equal nil, ref
end
- it "can get a reflog" do
+ def test_load_reflog
ref = Rugged::Reference.lookup(@repo, "refs/heads/master")
log = ref.log
e = log[1]
@@ -57,39 +43,68 @@
assert_equal e[:committer][:email], "schacon@gmail.com"
end
- it "can check for the existence of a reference" do
+ def test_reference_exists
exists = Rugged::Reference.exist?(@repo, "refs/heads/master")
assert exists
exists = Rugged::Reference.exist?(@repo, "lol/wut")
assert !exists
end
- it "can open packed reference" do
+ def test_load_packed_ref
ref = Rugged::Reference.lookup(@repo, "refs/heads/packed")
assert_equal "41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9", ref.target
assert_equal :direct, ref.type
assert_equal "refs/heads/packed", ref.name
end
- it "can create reference from symbolic reference" do
+ def test_resolve_head
+ ref = Rugged::Reference.lookup(@repo, "HEAD")
+ assert_equal "refs/heads/master", ref.target
+ assert_equal :symbolic, ref.type
+
+ head = ref.resolve
+ assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", head.target
+ assert_equal :direct, head.type
+ end
+end
+
+class ReferenceWriteTest < Rugged::TestCase
+ include Rugged::TempRepositoryAccess
+
+ def test_list_unicode_refs
+ Rugged::Reference.create(@repo,
+ "refs/heads/#{ReferenceTest::UNICODE_REF_NAME}",
+ "refs/heads/master")
+
+ refs = @repo.refs.map { |r| r.name.gsub("refs/", '') }.sort.join(':')
+ assert_equal "heads/#{ReferenceTest::UNICODE_REF_NAME}:heads/master:heads/packed:tags/v0.9:tags/v1.0", refs
+ end
+
+ def test_create_symbolic_ref
ref = Rugged::Reference.create(@repo, "refs/heads/unit_test", "refs/heads/master")
assert_equal "refs/heads/master", ref.target
assert_equal :symbolic, ref.type
assert_equal "refs/heads/unit_test", ref.name
ref.delete!
end
- it "can create reference from oid" do
- ref = Rugged::Reference.create(@repo, "refs/heads/unit_test", "36060c58702ed4c2a40832c51758d5344201d89a")
+ def test_create_ref_from_oid
+ ref = Rugged::Reference.create(@repo,
+ "refs/heads/unit_test",
+ "36060c58702ed4c2a40832c51758d5344201d89a")
+
assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", ref.target
assert_equal :direct, ref.type
assert_equal "refs/heads/unit_test", ref.name
ref.delete!
end
- it "can rename ref" do
- ref = Rugged::Reference.create(@repo, "refs/heads/unit_test", "36060c58702ed4c2a40832c51758d5344201d89a")
+ def test_rename_ref
+ ref = Rugged::Reference.create(@repo,
+ "refs/heads/unit_test",
+ "36060c58702ed4c2a40832c51758d5344201d89a")
+
assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", ref.target
assert_equal :direct, ref.type
assert_equal "refs/heads/unit_test", ref.name
@@ -99,8 +114,11 @@
ref.delete!
end
- it "can set target on reference" do
- ref = Rugged::Reference.create(@repo, "refs/heads/unit_test", "36060c58702ed4c2a40832c51758d5344201d89a")
+ def test_set_ref_target
+ ref = Rugged::Reference.create(@repo,
+ "refs/heads/unit_test",
+ "36060c58702ed4c2a40832c51758d5344201d89a")
+
assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", ref.target
assert_equal :direct, ref.type
assert_equal "refs/heads/unit_test", ref.name
@@ -110,85 +128,45 @@
ref.delete!
end
- it "can resolve head" do
- ref = Rugged::Reference.lookup(@repo, "HEAD")
- assert_equal "refs/heads/master", ref.target
- assert_equal :symbolic, ref.type
+ def test_write_and_read_unicode_refs
+ ref1 = Rugged::Reference.create(@repo, "refs/heads/Ångström", "refs/heads/master")
+ ref2 = Rugged::Reference.create(@repo, "refs/heads/foobar", "refs/heads/Ångström")
- head = ref.resolve
- assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", head.target
- assert_equal :direct, head.type
+ assert_equal "refs/heads/Ångström", ref1.name
+ assert_equal "refs/heads/Ångström", ref2.target
end
+end
+class ReflogTest < Rugged::TestCase
+ include Rugged::TempRepositoryAccess
- describe "reference target" do
- before do
- @path = temp_repo 'testrepo.git'
- @repo = Rugged::Repository.new(@path)
- end
-
- after do
- destroy_temp_repo(@path)
- end
-
- it "returns the reference target name with UTF-8 encoding" do
- Rugged::Reference.create(@repo, "refs/heads/Ångström", "refs/heads/master")
-
- ref = Rugged::Reference.create(@repo, "refs/heads/foobar", "refs/heads/Ångström")
- assert_equal "refs/heads/Ångström", ref.target
- end
+ def setup
+ super
+ @ref = Rugged::Reference.create(@repo,
+ "refs/heads/test-reflog",
+ "36060c58702ed4c2a40832c51758d5344201d89a")
end
- describe "reference logging" do
- before do
- @path = temp_repo 'testrepo.git'
- @repo = Rugged::Repository.new(@path)
-
- @ref = Rugged::Reference.create(@repo, "refs/heads/test-reflog", "36060c58702ed4c2a40832c51758d5344201d89a")
- end
-
- after do
- destroy_temp_repo(@path)
- end
-
- it "creates reflog entries" do
- @ref.log!({ :name => "foo", :email => "foo@bar", :time => Time.now })
- @ref.log!({ :name => "foo", :email => "foo@bar", :time => Time.now }, "commit: bla bla")
-
- reflog = @ref.log
- assert_equal reflog.size, 2
-
- assert_equal reflog[0][:id_old], "0000000000000000000000000000000000000000"
- assert_equal reflog[0][:id_new], "36060c58702ed4c2a40832c51758d5344201d89a"
- assert_equal reflog[0][:message], nil
- assert_equal reflog[0][:committer][:name], "foo"
- assert_equal reflog[0][:committer][:email], "foo@bar"
- assert_kind_of Time, reflog[0][:committer][:time]
-
- assert_equal reflog[1][:id_old], "36060c58702ed4c2a40832c51758d5344201d89a"
- assert_equal reflog[1][:id_new], "36060c58702ed4c2a40832c51758d5344201d89a"
- assert_equal reflog[1][:message], "commit: bla bla"
- assert_equal reflog[1][:committer][:name], "foo"
- assert_equal reflog[1][:committer][:email], "foo@bar"
- assert_kind_of Time, reflog[1][:committer][:time]
-
- end
- end
+ def test_create_reflog_entries
+ @ref.log!({ :name => "foo", :email => "foo@bar", :time => Time.now })
+ @ref.log!({ :name => "foo", :email => "foo@bar", :time => Time.now }, "commit: bla bla")
- describe "reference name" do
- before do
- @path = temp_repo 'testrepo.git'
- @repo = Rugged::Repository.new(@path)
- end
+ reflog = @ref.log
+ assert_equal reflog.size, 2
- after do
- destroy_temp_repo(@path)
- end
+ assert_equal reflog[0][:id_old], "0000000000000000000000000000000000000000"
+ assert_equal reflog[0][:id_new], "36060c58702ed4c2a40832c51758d5344201d89a"
+ assert_equal reflog[0][:message], nil
+ assert_equal reflog[0][:committer][:name], "foo"
+ assert_equal reflog[0][:committer][:email], "foo@bar"
+ assert_kind_of Time, reflog[0][:committer][:time]
- it "returns the reference name with UTF-8 encoding" do
- ref = Rugged::Reference.create(@repo, "refs/heads/Ångström", "refs/heads/master")
- assert_equal "refs/heads/Ångström", ref.name
- end
+ assert_equal reflog[1][:id_old], "36060c58702ed4c2a40832c51758d5344201d89a"
+ assert_equal reflog[1][:id_new], "36060c58702ed4c2a40832c51758d5344201d89a"
+ assert_equal reflog[1][:message], "commit: bla bla"
+ assert_equal reflog[1][:committer][:name], "foo"
+ assert_equal reflog[1][:committer][:email], "foo@bar"
+ assert_kind_of Time, reflog[1][:committer][:time]
end
end
View
12 test/remote_test.rb
@@ -1,13 +1,10 @@
require "test_helper"
require 'net/http'
-describe Rugged::Remote do
- before do
- @path = File.dirname(__FILE__) + '/fixtures/testrepo.git/'
- @repo = Rugged::Repository.new(@path)
- end
+class RemoteTest < Rugged::TestCase
+ include Rugged::RepositoryAccess
- it "is able to connect to the remote" do
+ def test_remote_connect
begin
Net::HTTP.new('github.com').head('/')
rescue SocketError => msg
@@ -23,10 +20,9 @@
assert !remote.connected?
end
- it "can list remotes" do
+ def test_list_remotes
remotes = @repo.remotes
assert remotes.kind_of? Enumerable
assert_equal [ "libgit2" ], remotes.to_a
end
-
end
View
38 test/repo_pack_test.rb
@@ -1,30 +1,24 @@
require "test_helper"
require 'base64'
-describe Rugged::Repository do
+class PackfileTest < Rugged::TestCase
+ include Rugged::RepositoryAccess
- describe "packfile stuff" do
- before do
- path = File.dirname(__FILE__) + '/fixtures/testrepo.git/'
- @repo = Rugged::Repository.new(path)
- end
-
- it "can tell if a packed object exists" do
- assert @repo.exists?("41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9")
- assert @repo.exists?("f82a8eb4cb20e88d1030fd10d89286215a715396")
- end
+ def test_packfile_object_exists
+ assert @repo.exists?("41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9")
+ assert @repo.exists?("f82a8eb4cb20e88d1030fd10d89286215a715396")
+ end
- it "can read a packed object from the db" do
- rawobj = @repo.read("41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9")
- assert_match 'tree f82a8eb4cb20e88d1030fd10d89286215a715396', rawobj.data
- assert_equal 230, rawobj.len
- assert_equal :commit, rawobj.type
- end
+ def test_read_packed_object
+ rawobj = @repo.read("41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9")
+ assert_match 'tree f82a8eb4cb20e88d1030fd10d89286215a715396', rawobj.data
+ assert_equal 230, rawobj.len
+ assert_equal :commit, rawobj.type
+ end
- it "can read a packed object's headers from the db" do
- hash = @repo.read_header("41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9")
- assert_equal 230, hash[:len]
- assert_equal :commit, hash[:type]
- end
+ def test_read_packed_header
+ hash = @repo.read_header("41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9")
+ assert_equal 230, hash[:len]
+ assert_equal :commit, hash[:type]
end
end
View
96 test/repo_test.rb
@@ -1,21 +1,15 @@
require 'test_helper'
require 'base64'
-describe Rugged::Repository do
- before do
- @path = File.dirname(__FILE__) + '/fixtures/testrepo.git/'
- @repo = Rugged::Repository.new(@path)
+class RepositoryTest < Rugged::TestCase
+ include Rugged::RepositoryAccess
- @test_content = "my test data\n"
- @test_content_type = 'blob'
- end
-
- it "last_commit returns the most recent commit" do
+ def test_last_commit
assert @repo.respond_to? :last_commit
assert "36060c58702ed4c2a40832c51758d5344201d89a", @repo.last_commit.oid
end
- it "fails to open unexisting repositories" do
+ def test_fails_to_open_unexisting_repos
assert_raises IOError, Rugged::OSError do
Rugged::Repository.new("fakepath/123/")
end
@@ -25,140 +19,134 @@
end
end
- it "can tell if an object exists or not" do
+ def test_can_check_if_objects_exist
assert @repo.exists?("8496071c1b46c854b31185ea97743be6a8774479")
assert @repo.exists?("1385f264afb75a56a5bec74243be9b367ba4ca08")
assert !@repo.exists?("ce08fe4884650f067bd5703b6a59a8b3b3c99a09")
assert !@repo.exists?("8496071c1c46c854b31185ea97743be6a8774479")
end
- it "can read an object from the db" do
+ def test_can_read_a_raw_object
rawobj = @repo.read("8496071c1b46c854b31185ea97743be6a8774479")
assert_match 'tree 181037049a54a1eb5fab404658a3a250b44335d7', rawobj.data
assert_equal 172, rawobj.len
assert_equal :commit, rawobj.type
end
- it "can read an object's headers from the db" do
+ def test_can_read_object_headers
hash = @repo.read_header("8496071c1b46c854b31185ea97743be6a8774479")
assert_equal 172, hash[:len]
assert_equal :commit, hash[:type]
end
- it "checks that reading fails on unexisting objects" do
+ def test_check_reads_fail_on_missing_objects
assert_raises Rugged::OdbError do
@repo.read("a496071c1b46c854b31185ea97743be6a8774471")
end
end
- it "checks that reading headers fails on unexisting objects" do
+ def test_check_read_headers_fail_on_missing_objects
assert_raises Rugged::OdbError do
@repo.read_header("a496071c1b46c854b31185ea97743be6a8774471")
end
end
- it "can hash data" do
- oid = Rugged::Repository::hash(@test_content, @test_content_type)
- assert_equal "76b1b55ab653581d6f2c7230d34098e837197674", oid
- end
-
- it "can write to the db" do
- oid = @repo.write(@test_content, @test_content_type)
- assert_equal "76b1b55ab653581d6f2c7230d34098e837197674", oid
- assert @repo.exists?("76b1b55ab653581d6f2c7230d34098e837197674")
-
- rm_loose(oid)
- end
-
- it "can walk in a block" do
+ def test_walking_with_block
oid = "a4a7dce85cf63874e984719f4fdd239f5145052f"
list = []
@repo.walk(oid) { |c| list << c }
assert list.map {|c| c.oid[0,5] }.join('.'), "a4a7d.c4780.9fd73.4a202.5b5b0.84960"
end
- it "can walk without a block" do
+ def test_walking_without_block
commits = @repo.walk('a4a7dce85cf63874e984719f4fdd239f5145052f')
assert commits.kind_of?(Enumerable)
assert commits.count > 0
end
- it "can lookup an object" do
+ def test_lookup_object
object = @repo.lookup("8496071c1b46c854b31185ea97743be6a8774479")
-
assert object.kind_of?(Rugged::Commit)
end
- it "can find a ref" do
+ def test_find_reference
ref = @repo.ref('refs/heads/master')
assert ref.kind_of?(Rugged::Reference)
assert_equal 'refs/heads/master', ref.name
end
- it "can return all refs" do
- refs = @repo.refs
-
- assert_equal 4, refs.length
- end
-
- it "can return all refs that match" do
+ def test_match_all_refs
refs = @repo.refs 'refs/heads'
-
assert_equal 2, refs.length
end
- it "can return the names of all refs" do
+ def test_return_all_ref_names
refs = @repo.ref_names
-
refs.each {|name| assert name.kind_of?(String)}
assert_equal 4, refs.count
end
- it "can return all tags" do
+ def test_return_all_tags
tags = @repo.tags
-
assert_equal 2, tags.count
end
- it "can return all tags that match" do
+ def test_return_matching_tags
tags = @repo.tags 'v0.9'
-
assert_equal 1, tags.count
end
- it "can return all remotes" do
+ def test_return_all_remotes
remotes = @repo.remotes
-
assert_equal 1, remotes.count
end
- it "can lookup head from repo" do
+ def test_lookup_head
head = @repo.head
assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", head.target
assert_equal :direct, head.type
end
- it "can access a file" do
+ def test_access_a_file
sha = '36060c58702ed4c2a40832c51758d5344201d89a'
blob = @repo.blob_at(sha, 'new.txt')
assert_equal "new file\n", blob.content
end
- it "can be garbage collected" do
+ def test_garbage_collection
Rugged::Repository.new(@path)
ObjectSpace.garbage_collect
end
- it "can enumerate all objects in the odb" do
+ def test_enumerate_all_objects
assert_equal 30, @repo.each_id.to_a.length
end
- it "can load alternates" do
+ def test_loading_alternates
alt_path = File.dirname(__FILE__) + '/fixtures/alternate/objects'
repo = Rugged::Repository.new(@path, :alternates => [alt_path])
assert_equal 33, repo.each_id.to_a.length
assert repo.read('146ae76773c91e3b1d00cf7a338ec55ae58297e2')
end
end
+
+class RepositoryWriteTest < Rugged::TestCase
+ include Rugged::TempRepositoryAccess
+
+ TEST_CONTENT = "my test data\n"
+ TEST_CONTENT_TYPE = 'blob'
+
+ def test_can_hash_data
+ oid = Rugged::Repository::hash(TEST_CONTENT, TEST_CONTENT_TYPE)
+ assert_equal "76b1b55ab653581d6f2c7230d34098e837197674", oid
+ end
+
+ def test_write_to_odb
+ oid = @repo.write(TEST_CONTENT, TEST_CONTENT_TYPE)
+ assert_equal "76b1b55ab653581d6f2c7230d34098e837197674", oid
+ assert @repo.exists?("76b1b55ab653581d6f2c7230d34098e837197674")
+ end
+end
+
View
45 test/tag_test.rb
@@ -1,33 +1,28 @@
require "test_helper"
-describe Rugged::Tag do
- before do
- @path = File.dirname(__FILE__) + '/fixtures/testrepo.git/'
- @repo = Rugged::Repository.new(@path)
- end
+class TagTest < Rugged::TestCase
+ include Rugged::RepositoryAccess
- describe "when loading tags" do
- it "can read the tag data" do
- oid = "0c37a5391bbff43c37f0d0371823a5509eed5b1d"
- obj = @repo.lookup(oid)
+ def test_reading_a_tag
+ oid = "0c37a5391bbff43c37f0d0371823a5509eed5b1d"
+ obj = @repo.lookup(oid)
- assert_equal oid, obj.oid
- assert_equal :tag, obj.type
- assert_equal "test tag message\n", obj.message
- assert_equal "v1.0", obj.name
- assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", obj.target.oid
- assert_equal :commit, obj.target_type
- c = obj.tagger
- assert_equal "Scott Chacon", c[:name]
- assert_equal 1288114383, c[:time].to_i
- assert_equal "schacon@gmail.com", c[:email]
- end
+ assert_equal oid, obj.oid
+ assert_equal :tag, obj.type
+ assert_equal "test tag message\n", obj.message
+ assert_equal "v1.0", obj.name
+ assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", obj.target.oid
+ assert_equal :commit, obj.target_type
+ c = obj.tagger
+ assert_equal "Scott Chacon", c[:name]
+ assert_equal 1288114383, c[:time].to_i
+ assert_equal "schacon@gmail.com", c[:email]
+ end
- it "can read the tag oid only" do
- oid = "0c37a5391bbff43c37f0d0371823a5509eed5b1d"
- obj = @repo.lookup(oid)
+ def test_reading_the_oid_of_a_tag
+ oid = "0c37a5391bbff43c37f0d0371823a5509eed5b1d"
+ obj = @repo.lookup(oid)
- assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", obj.target_oid
- end
+ assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", obj.target_oid
end
end
View
50 test/test_helper.rb
@@ -7,23 +7,11 @@
require 'pp'
module Rugged
- class TestCase < MiniTest::Spec
+ class TestCase < MiniTest::Unit::TestCase
TEST_DIR = File.dirname(File.expand_path(__FILE__))
- private
-
- def temp_repo(repo)
- dir = Dir.mktmpdir 'dir'
- repo_dir = File.join(TEST_DIR, (File.join('fixtures', repo, '.')))
- `git clone #{repo_dir} #{dir}`
- dir
- end
-
- def destroy_temp_repo(path)
- FileUtils.remove_entry_secure(path)
- end
-
- def rm_loose(oid)
+ protected
+ def _rm_loose(oid)
base_path = File.join(@path, "objects", oid[0, 2])
file = File.join(base_path, oid[2, 38])
@@ -47,6 +35,34 @@ def with_default_encoding(encoding, &block)
Encoding.default_internal = old_encoding
end
end
-end
-MiniTest::Spec.register_spec_type(/./, Rugged::TestCase)
+ module RepositoryAccess
+ def setup
+ @path = File.dirname(__FILE__) + '/fixtures/testrepo.git/'
+ @repo = Rugged::Repository.new(@path)
+ end
+ end
+
+ module TempRepositoryAccess
+ def setup
+ @path = temp_repo("testrepo.git")
+ @repo = Rugged::Repository.new(@path)
+ end
+
+ def teardown
+ destroy_temp_repo(@path)
+ end
+
+ protected
+ def temp_repo(repo)
+ dir = Dir.mktmpdir 'dir'
+ repo_dir = File.join(TestCase::TEST_DIR, (File.join('fixtures', repo, '.')))
+ `git clone #{repo_dir} #{dir}`
+ dir
+ end
+
+ def destroy_temp_repo(path)
+ FileUtils.remove_entry_secure(path)
+ end
+ end
+end
View
32 test/tree_test.rb
@@ -1,22 +1,23 @@
require "test_helper"
-describe Rugged::Tree do
- before do
- @path = File.dirname(__FILE__) + '/fixtures/testrepo.git/'
- @repo = Rugged::Repository.new(@path)
+class TreeTest < Rugged::TestCase
+ include Rugged::RepositoryAccess
+
+ def setup
+ super
@oid = "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b"
@tree = @repo.lookup(@oid)
end
- it "can read the tree data" do
+ def test_read_tree_data
assert_equal @oid, @tree.oid
assert_equal :tree, @tree.type
assert_equal 3, @tree.count
assert_equal "1385f264afb75a56a5bec74243be9b367ba4ca08", @tree[0][:oid]
assert_equal "fa49b077972391ad58037050f2a75f74e3671e92", @tree[1][:oid]
end
- it "can read the tree entry data" do
+ def test_read_tree_entry_data
bent = @tree[0]
tent = @tree[2]
@@ -30,31 +31,35 @@
assert_equal :tree, @repo.lookup(tent[:oid]).type
end
- it "can iterate over the tree" do
+ def test_tree_iteration
enum_test = @tree.sort { |a, b| a[:oid] <=> b[:oid] }.map { |e| e[:name] }.join(':')
assert_equal "README:subdir:new.txt", enum_test
enum = @tree.each
assert enum.kind_of? Enumerable
end
- it "can walk the tree, yielding only trees" do
+ def test_tree_walk_only_trees
@tree.walk_trees {|root, entry| assert_equal :tree, entry[:type]}
end
- it "can walk the tree, yielding only blobs" do
+ def test_tree_walk_only_blobs
@tree.walk_blobs {|root, entry| assert_equal :blob, entry[:type]}
end
- it "can iterate over the subtrees a tree" do
+ def test_iterate_subtrees
@tree.each_tree {|tree| assert_equal :tree, tree[:type]}
end
- it "can iterate over the subtrees a tree" do
+ def test_iterate_subtree_blobs
@tree.each_blob {|tree| assert_equal :blob, tree[:type]}
end
+end
+
+class TreeWriteTest < Rugged::TestCase
+ include Rugged::TempRepositoryAccess
- it "can write the tree data" do
+ def test_write_tree_data
entry = {:type => :blob,
:name => "README.txt",
:oid => "1385f264afb75a56a5bec74243be9b367ba4ca08",
@@ -65,8 +70,5 @@
sha = builder.write(@repo)
obj = @repo.lookup(sha)
assert_equal 38, obj.read_raw.len
-
- rm_loose(sha)
end
-
end
View
27 test/walker_test.rb
@@ -1,36 +1,37 @@
require "test_helper"
require 'base64'
-describe Rugged::Walker do
- before do
- @path = File.dirname(__FILE__) + '/fixtures/testrepo.git/'
- @repo = Rugged::Repository.new(@path)
+class WalkerTest < Rugged::TestCase
+ include Rugged::RepositoryAccess
+
+ def setup
+ super
@walker = Rugged::Walker.new(@repo)
end
- it "can walk a simple revlist" do
+ def test_walk_revlist
@walker.push("9fd738e8f7967c078dceed8190330fc8648ee56a")
data = @walker.each.to_a
oids = data.sort { |a, b| a.oid <=> b.oid }.map {|a| a.oid[0,5]}.join('.')
assert_equal "4a202.5b5b0.84960.9fd73", oids
end
- it "can walk a part of a revlist" do
+ def test_walk_partial_revlist
oid = "8496071c1b46c854b31185ea97743be6a8774479"
@walker.push(oid)
walk = @walker.each.to_a
assert_equal oid, walk[0].oid
assert_equal 1, walk.count
end
- it "can hide part of a list" do
+ def test_hide_part_of_list
@walker.push("9fd738e8f7967c078dceed8190330fc8648ee56a")
@walker.hide("5b5b025afb0b4c913b4c338a42934a3863bf3644")
assert_equal 2, @walker.each.count
end
# resetting a walker emtpies the walking queue
- it "can reset a walker" do
+ def test_resetting_walker
oid = "8496071c1b46c854b31185ea97743be6a8774479"
@walker.push(oid)
walk = @walker.each.to_a
@@ -41,7 +42,7 @@
assert_equal 0, walk.count
end
- it "can enumerable" do
+ def test_walk_is_enumberable
@walker.push("9fd738e8f7967c078dceed8190330fc8648ee56a")
enum = @walker.sort { |a, b| a.oid <=> b.oid }.map { |a| a.oid[0, 4] }.join('.')
assert_equal "4a20.5b5b.8496.9fd7", enum
@@ -65,22 +66,22 @@ def is_toposorted(list)
end
end
- it "can sort order by date" do
+ def test_sort_by_date
time = revlist_with_sorting(Rugged::SORT_DATE)
assert_equal "a4a7d.c4780.9fd73.4a202.5b5b0.84960", time
end
- it "can sort order by topo" do
+ def test_sort_by_topo
sort_list = do_sort(Rugged::SORT_TOPO)
assert_equal is_toposorted(sort_list), true
end
- it "can sort order by date reversed" do
+ def test_sort_by_date_reversed
time = revlist_with_sorting(Rugged::SORT_DATE | Rugged::SORT_REVERSE)
assert_equal "84960.5b5b0.4a202.9fd73.c4780.a4a7d", time
end
- it "can sort order by topo reversed" do
+ def test_sort_by_topo_reverse
sort_list = do_sort(Rugged::SORT_TOPO | Rugged::SORT_REVERSE).reverse
assert_equal is_toposorted(sort_list), true
end

0 comments on commit 719c32a

Please sign in to comment.