Skip to content

Commit bcf2cf4

Browse files
committed
Locating files in Main
1 parent f691352 commit bcf2cf4

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

lib/files_in_my_diff/commit.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ def call
1414
validate_folder!
1515
diff = @git_strategy.diff(@revision)
1616
diff.validate!
17-
diff.changes
1817
dir = @file_strategy.create_tmp_dir(diff.sha)
1918
@git_strategy.checkout_worktree(dir, diff.sha)
20-
# @file_strategy.locate_files(dir, changes)
21-
{ dir:, sha: diff.sha }
19+
decorated = @file_strategy.locate_files(dir, diff.changes)
20+
{ dir:, sha: diff.sha, changes: decorated }
2221
end
2322

2423
private

lib/files_in_my_diff/tmp_dir.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module FilesInMyDiff
44
module TmpDir
55
class DirectoryError < FilesInMyDiff::Error; end
6+
class FileError < FilesInMyDiff::Error; end
67

78
module FileStrategy
89
def self.dir_exists?(folder)
@@ -16,6 +17,11 @@ def self.create_tmp_dir(sha)
1617
rescue StandardError => e
1718
raise DirectoryError, "Failed to create tmp dir for #{sha}: #{e.message}"
1819
end
20+
21+
def self.locate_files(_dir, changes)
22+
# TODO
23+
changes
24+
end
1925
end
2026
end
2127
end

test/commit/main_test.rb

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,40 @@ def test_that_error_on_checkout_is_propagated
4444
end
4545
end
4646

47+
def test_that_error_on_locating_files_is_propagated
48+
file_strategy = file_strategy_stub(locate_files_success: false)
49+
assert_raises(TmpDir::FileError) do
50+
subject(file_strategy:).call
51+
end
52+
end
53+
54+
def test_that_main_returns_dir_and_sha_and_changes
55+
result = subject.call
56+
57+
refute_empty result[:dir]
58+
refute_empty result[:sha]
59+
refute_empty result[:changes]
60+
end
61+
4762
private
4863

4964
def subject(folder: 'x', revision: 'HEAD', file_strategy: file_strategy_stub, git_strategy: git_strategy_stub)
5065
Main.new(folder:, revision:, file_strategy:, git_strategy:)
5166
end
5267

53-
def file_strategy_stub(dir_exists: true, create_success: true)
54-
FileStrategyStub.new(dir_exists, create_success)
68+
def file_strategy_stub(dir_exists: true, create_success: true, locate_files_success: true)
69+
FileStrategyStub.new(dir_exists, create_success, locate_files_success)
5570
end
5671

5772
def git_strategy_stub(revision_exists: true, diff_success: true, checkout_success: true)
5873
GitStrategyStub.new(revision_exists, diff_success, checkout_success)
5974
end
6075

6176
class FileStrategyStub
62-
def initialize(dir_exists, create_success)
77+
def initialize(dir_exists, create_success, locate_files_success)
6378
@dir_exists = dir_exists
6479
@create_success = create_success
80+
@locate_files_success = locate_files_success
6581
end
6682

6783
def dir_exists?(_folder)
@@ -73,6 +89,12 @@ def create_tmp_dir(_sha)
7389

7490
'some_tpm_dir'
7591
end
92+
93+
def locate_files(_dir, _changes)
94+
raise TmpDir::FileError unless @locate_files_success
95+
96+
[{}, {}]
97+
end
7698
end
7799

78100
class GitStrategyStub

0 commit comments

Comments
 (0)