From 0c25d8b59f98226230e3e26aa7d3e43d8c5169ec Mon Sep 17 00:00:00 2001 From: "Erik T. Madsen" Date: Sat, 2 Nov 2024 16:31:26 +0100 Subject: [PATCH] Refactoring towards Diff, step 5 --- lib/files_in_my_diff/git.rb | 5 ++--- test/git/diff_test.rb | 34 ++++++++++++++-------------------- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/lib/files_in_my_diff/git.rb b/lib/files_in_my_diff/git.rb index 22df8f1..536df62 100644 --- a/lib/files_in_my_diff/git.rb +++ b/lib/files_in_my_diff/git.rb @@ -5,10 +5,9 @@ module Git class DiffError < Error; end class Diff - def initialize(folder:, revision:, adapter: Adapter.new(folder:)) + def initialize(object:, revision:) + @object = object @revision = revision - @adapter = adapter - @object = adapter.object(@revision) end def validate! diff --git a/test/git/diff_test.rb b/test/git/diff_test.rb index dde6858..4b03d41 100644 --- a/test/git/diff_test.rb +++ b/test/git/diff_test.rb @@ -6,9 +6,8 @@ module FilesInMyDiff module Git class DiffTest < Minitest::Test def test_it_validates_that_revision_exists - adapter = adapter_stub(revision_exists: false) assert_raises(ValidationError) do - subject(adapter:).validate! + subject(object: nil).validate! end end @@ -17,9 +16,8 @@ def test_it_returns_the_sha_of_the_revision end def test_that_error_on_diff_calculation_is_propagated - adapter = adapter_stub(diff_success: false) assert_raises(Git::DiffError) do - subject(adapter:).changes + subject(object: git_object_stub(diff_success: false)).changes end end @@ -29,23 +27,12 @@ def test_it_returns_the_changes_since_the_parent_revision private - def subject(adapter: adapter_stub) - Diff.new(folder: 'x', revision: 'y', adapter:) + def subject(object: git_object_stub, revision: 'y') + Diff.new(object:, revision:) end - def adapter_stub(revision_exists: true, diff_success: true) - AdapterStub.new(revision_exists, diff_success) - end - - class AdapterStub - def initialize(revision_exists, diff_success) - @revision_exists = revision_exists - @diff_success = diff_success - end - - def object(_revision) - @revision_exists ? GitObjectStub.new(@diff_success) : nil - end + def git_object_stub(diff_success: true) + GitObjectStub.new(diff_success) end class GitObjectStub @@ -60,7 +47,14 @@ def diff_parent end end - Change = Data.define(:path, :type) + class Change + attr_reader :path, :type + + def initialize(path, type) + @path = path + @type = type + end + end end end end