This repository has been archived by the owner on Jun 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
theme pull
to no longer add empty lines on Windows (#1937)
- Loading branch information
Showing
3 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# frozen_string_literal: true | ||
require "test_helper" | ||
require "shopify_cli/theme/file" | ||
|
||
module ShopifyCLI | ||
module Theme | ||
class FileTest < Minitest::Test | ||
def setup | ||
super | ||
@file = File.new("path", root) | ||
@file.stubs(:path).returns(path) | ||
end | ||
|
||
def test_read_when_file_is_a_text | ||
@file.stubs(:text?).returns(true) | ||
|
||
@path.expects(:read).with(universal_newline: true) | ||
@file.read | ||
end | ||
|
||
def test_read_when_file_is_not_a_text | ||
@file.stubs(:text?).returns(false) | ||
|
||
@path.expects(:read).with(mode: "rb") | ||
@file.read | ||
end | ||
|
||
def test_write_when_file_parent_is_not_a_directory | ||
@path.parent.stubs(:directory?).returns(false) | ||
@path.stubs(:write) | ||
|
||
@path.parent.expects(:mkpath) | ||
@file.write("content") | ||
end | ||
|
||
def test_write_when_file_parent_is_a_directory | ||
@path.parent.stubs(:directory?).returns(true) | ||
@path.stubs(:write) | ||
|
||
@path.parent.expects(:mkpath).never | ||
@file.write("content") | ||
end | ||
|
||
def test_write_when_file_is_a_text | ||
@path.parent.stubs(:directory?).returns(true) | ||
@file.stubs(:text?).returns(true) | ||
|
||
@path.expects(:write).with("content", universal_newline: true) | ||
@file.write("content") | ||
end | ||
|
||
def test_write_when_file_is_not_a_text | ||
@path.parent.stubs(:directory?).returns(true) | ||
@file.stubs(:text?).returns(false) | ||
|
||
@path.expects(:write).with("content", 0, mode: "wb") | ||
@file.write("content") | ||
end | ||
|
||
private | ||
|
||
def path | ||
@path = mock | ||
@path.stubs(:parent).returns(mock) | ||
@path | ||
end | ||
|
||
def root | ||
@root = mock | ||
@root.stubs(:expand_path).returns(ShopifyCLI::ROOT) | ||
@root | ||
end | ||
end | ||
end | ||
end |