Skip to content

Commit 0c25d8b

Browse files
committed
Refactoring towards Diff, step 5
1 parent 57b532e commit 0c25d8b

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

lib/files_in_my_diff/git.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ module Git
55
class DiffError < Error; end
66

77
class Diff
8-
def initialize(folder:, revision:, adapter: Adapter.new(folder:))
8+
def initialize(object:, revision:)
9+
@object = object
910
@revision = revision
10-
@adapter = adapter
11-
@object = adapter.object(@revision)
1211
end
1312

1413
def validate!

test/git/diff_test.rb

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ module FilesInMyDiff
66
module Git
77
class DiffTest < Minitest::Test
88
def test_it_validates_that_revision_exists
9-
adapter = adapter_stub(revision_exists: false)
109
assert_raises(ValidationError) do
11-
subject(adapter:).validate!
10+
subject(object: nil).validate!
1211
end
1312
end
1413

@@ -17,9 +16,8 @@ def test_it_returns_the_sha_of_the_revision
1716
end
1817

1918
def test_that_error_on_diff_calculation_is_propagated
20-
adapter = adapter_stub(diff_success: false)
2119
assert_raises(Git::DiffError) do
22-
subject(adapter:).changes
20+
subject(object: git_object_stub(diff_success: false)).changes
2321
end
2422
end
2523

@@ -29,23 +27,12 @@ def test_it_returns_the_changes_since_the_parent_revision
2927

3028
private
3129

32-
def subject(adapter: adapter_stub)
33-
Diff.new(folder: 'x', revision: 'y', adapter:)
30+
def subject(object: git_object_stub, revision: 'y')
31+
Diff.new(object:, revision:)
3432
end
3533

36-
def adapter_stub(revision_exists: true, diff_success: true)
37-
AdapterStub.new(revision_exists, diff_success)
38-
end
39-
40-
class AdapterStub
41-
def initialize(revision_exists, diff_success)
42-
@revision_exists = revision_exists
43-
@diff_success = diff_success
44-
end
45-
46-
def object(_revision)
47-
@revision_exists ? GitObjectStub.new(@diff_success) : nil
48-
end
34+
def git_object_stub(diff_success: true)
35+
GitObjectStub.new(diff_success)
4936
end
5037

5138
class GitObjectStub
@@ -60,7 +47,14 @@ def diff_parent
6047
end
6148
end
6249

63-
Change = Data.define(:path, :type)
50+
class Change
51+
attr_reader :path, :type
52+
53+
def initialize(path, type)
54+
@path = path
55+
@type = type
56+
end
57+
end
6458
end
6559
end
6660
end

0 commit comments

Comments
 (0)