./test/dolt/git/repository_test.rb in dolt-0.1.1 vs ./test/dolt/git/repository_test.rb in dolt-0.2.0

- old
+ new

@@ -15,95 +15,46 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. #++ require "test_helper" require "dolt/git/repository" -require "dolt/async/when" -class FakeGit - attr_reader :cmds, :deferreds - - def initialize - @cmds = [] - @deferreds = [] - end - - def show(path, ref) - git("show", path, ref) - end - - def ls_tree(path, ref) - git("ls-tree", path, ref) - end - - def git(*args) - cmds << args - deferred = When::Deferred.new - deferreds << deferred.resolver - deferred.promise - end - - def last_command; cmds.last; end - def last_resolver; deferreds.last; end -end - describe Dolt::Git::Repository do - before { @git = FakeGit.new } + include EM::MiniTest::Spec - describe "#blob" do - it "uses git-show to cat file at ref" do - repo = Dolt::Git::Repository.new("gitorious", @git) - repo.blob("models/repository.rb", "master") + describe "#blame" do + before { @repository = Dolt::Git::Repository.new(".") } - assert_equal ["show", "models/repository.rb", "master"], @git.last_command + it "returns deferrable" do + deferrable = @repository.blame("master", "Gemfile") + assert deferrable.respond_to?(:callback) + assert deferrable.respond_to?(:errback) end - it "defaults to showing the file at HEAD" do - repo = Dolt::Git::Repository.new("gitorious", @git) - repo.blob("models/repository.rb") - - assert_equal ["show", "models/repository.rb", "HEAD"], @git.last_command - end - - it "invokes callback with blob object" do - repo = Dolt::Git::Repository.new("gitorious", @git) - d = repo.blob("models/repository.rb") - - d.callback do |blob| - assert_equal "class Repository;end", blob.raw + it "yields blame" do + @repository.blame("master", "Gemfile").callback do |blame| + assert Dolt::Git::Blame === blame + done! end - - @git.last_resolver.resolve("class Repository;end") + wait! end end - describe "#tree" do - it "uses git ls-tree to list tree" do - repo = Dolt::Git::Repository.new("gitorious", @git) - repo.tree("app/models", "master") + describe "#log" do + before { @repository = Dolt::Git::Repository.new(".") } - assert_equal ["ls-tree", "app/models", "master"], @git.last_command + it "returns deferrable" do + deferrable = @repository.log("master", "Gemfile", 1) + assert deferrable.respond_to?(:callback) + assert deferrable.respond_to?(:errback) end - it "defaults to listing tree at HEAD" do - repo = Dolt::Git::Repository.new("gitorious", @git) - repo.tree("app/models") - - assert_equal ["ls-tree", "app/models", "HEAD"], @git.last_command - end - - it "invokes callback with tree object" do - repo = Dolt::Git::Repository.new("gitorious", @git) - d = repo.tree("app/models") - - d.callback do |tree| - assert_equal 3, tree.entries.length + it "yields commits" do + @repository.log("master", "dolt.gemspec", 2).callback do |log| + assert_equal 2, log.length + assert Hash === log[0] + done! end - - @git.last_resolver.resolve(<<-GIT) -100644 blob e90021f89616ddf86855d05337c188408d3b417e .gitmodules -100644 blob c80ee3697054566d1a4247d80be78ec3ddfde295 Gemfile -100644 blob 0053b3c95b0d9faa4916f7cd5e559c2b0f138027 Gemfile.lock - GIT + wait! end end end