tty-file 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/lib/tty/file.rb +75 -85
- data/lib/tty/file/create_file.rb +5 -5
- data/lib/tty/file/differ.rb +5 -4
- data/lib/tty/file/digest_file.rb +4 -4
- data/lib/tty/file/download_file.rb +5 -5
- data/lib/tty/file/version.rb +1 -1
- metadata +19 -56
- data/Rakefile +0 -10
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/spec/fixtures/cli_app/%name%_cli.rb +0 -2
- data/spec/fixtures/cli_app/commands/subcommand.rb +0 -2
- data/spec/fixtures/cli_app/excluded/%name%_cli.rb +0 -2
- data/spec/fixtures/templates/%file_name%.rb +0 -1
- data/spec/fixtures/templates/unit_test.rb +0 -1
- data/spec/spec_helper.rb +0 -94
- data/spec/unit/append_to_file_spec.rb +0 -110
- data/spec/unit/binary_spec.rb +0 -230
- data/spec/unit/checksum_file_spec.rb +0 -48
- data/spec/unit/chmod_spec.rb +0 -92
- data/spec/unit/copy_directory_spec.rb +0 -120
- data/spec/unit/copy_file_spec.rb +0 -172
- data/spec/unit/create_directory_spec.rb +0 -93
- data/spec/unit/create_file_spec.rb +0 -130
- data/spec/unit/diff_spec.rb +0 -107
- data/spec/unit/differ/call_spec.rb +0 -101
- data/spec/unit/download_file_spec.rb +0 -68
- data/spec/unit/escape_glob_path_spec.rb +0 -14
- data/spec/unit/inject_into_file_spec.rb +0 -176
- data/spec/unit/prepend_to_file_spec.rb +0 -124
- data/spec/unit/read_to_char_spec.rb +0 -24
- data/spec/unit/remove_file_spec.rb +0 -67
- data/spec/unit/replace_in_file_spec.rb +0 -140
- data/spec/unit/tail_file_spec.rb +0 -77
- data/tasks/console.rake +0 -11
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -29
- data/tty-file.gemspec +0 -33
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::File, "#read_to_char" do
|
4
|
-
before do
|
5
|
-
@saved_verbosity = $VERBOSE
|
6
|
-
@saved_encoding = Encoding.default_external
|
7
|
-
$VERBOSE = nil
|
8
|
-
Encoding.default_external = Encoding::UTF_8
|
9
|
-
end
|
10
|
-
|
11
|
-
after do
|
12
|
-
Encoding.default_external = @saved_encoding
|
13
|
-
$VERBOSE = @saved_verbosity
|
14
|
-
end
|
15
|
-
|
16
|
-
it "reads file up to valid char", unless: RSpec::Support::OS.windows? do
|
17
|
-
file = tmp_pathname("binary", "unicode.txt")
|
18
|
-
bytes = 4096
|
19
|
-
|
20
|
-
content = TTY::File.read_to_char(file, bytes)
|
21
|
-
|
22
|
-
expect(content.bytesize).to eq(bytes + 2)
|
23
|
-
end
|
24
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::File, '#remove_file' do
|
4
|
-
shared_context "removing a file" do
|
5
|
-
it "removes a given file", unless: RSpec::Support::OS.windows? do
|
6
|
-
src_path = path_factory.call('Gemfile')
|
7
|
-
|
8
|
-
TTY::File.remove_file(src_path, verbose: false)
|
9
|
-
|
10
|
-
expect(::File.exist?(src_path)).to be(false)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "removes a directory" do
|
14
|
-
src_path = path_factory.call('templates')
|
15
|
-
|
16
|
-
TTY::File.remove_file(src_path, verbose: false)
|
17
|
-
|
18
|
-
expect(::File.exist?(src_path)).to be(false)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "pretends removing file" do
|
22
|
-
src_path = path_factory.call('Gemfile')
|
23
|
-
|
24
|
-
TTY::File.remove_file(src_path, noop: true, verbose: false)
|
25
|
-
|
26
|
-
expect(::File.exist?(src_path)).to be(true)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "removes files in secure mode" do
|
30
|
-
src_path = path_factory.call('Gemfile')
|
31
|
-
allow(::FileUtils).to receive(:rm_r)
|
32
|
-
|
33
|
-
TTY::File.remove_file(src_path, verbose: false, secure: false)
|
34
|
-
|
35
|
-
expect(::FileUtils).to have_received(:rm_r).
|
36
|
-
with(src_path.to_s, force: nil, secure: false)
|
37
|
-
end
|
38
|
-
|
39
|
-
it "logs status" do
|
40
|
-
src_path = path_factory.call('Gemfile')
|
41
|
-
|
42
|
-
expect {
|
43
|
-
TTY::File.remove_file(src_path, noop: true)
|
44
|
-
}.to output(/\e\[31mremove\e\[0m(.*)Gemfile/).to_stdout_from_any_process
|
45
|
-
end
|
46
|
-
|
47
|
-
it "logs status without color" do
|
48
|
-
src_path = path_factory.call('Gemfile')
|
49
|
-
|
50
|
-
expect {
|
51
|
-
TTY::File.remove_file(src_path, noop: true, color: false)
|
52
|
-
}.to output(/\s+remove(.*)Gemfile/).to_stdout_from_any_process
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "when passed a String instance for the file argument" do
|
57
|
-
let(:path_factory) { method(:tmp_path) }
|
58
|
-
|
59
|
-
include_context "removing a file"
|
60
|
-
end
|
61
|
-
|
62
|
-
context "when passed a Pathname instance for the file argument" do
|
63
|
-
let(:path_factory) { method(:tmp_pathname) }
|
64
|
-
|
65
|
-
include_context "removing a file"
|
66
|
-
end
|
67
|
-
end
|
@@ -1,140 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::File, '#replace_in_file' do
|
4
|
-
shared_context "replacing in a file" do
|
5
|
-
it "replaces file content with a matching string" do
|
6
|
-
file = path_factory.call('Gemfile')
|
7
|
-
status = nil
|
8
|
-
expect {
|
9
|
-
status = TTY::File.replace_in_file(file, /gem 'rails'/, "gem 'hanami'")
|
10
|
-
}.to output(/replace/).to_stdout_from_any_process
|
11
|
-
|
12
|
-
expect(status).to eq(true)
|
13
|
-
expect(File.read(file)).to eq([
|
14
|
-
"gem 'nokogiri'\n",
|
15
|
-
"gem 'hanami', '5.0.0'\n",
|
16
|
-
"gem 'rack', '>=1.0'\n"
|
17
|
-
].join)
|
18
|
-
end
|
19
|
-
|
20
|
-
it "replaces file content with a matching block value" do
|
21
|
-
file = path_factory.call('Gemfile')
|
22
|
-
status = nil
|
23
|
-
expect {
|
24
|
-
status =TTY::File.replace_in_file(file, /gem 'rails'/, verbose: false) do |match|
|
25
|
-
match = "gem 'hanami'"
|
26
|
-
end
|
27
|
-
}.to_not output(/replace/).to_stdout_from_any_process
|
28
|
-
|
29
|
-
expect(status).to eq(true)
|
30
|
-
expect(File.read(file)).to eq([
|
31
|
-
"gem 'nokogiri'\n",
|
32
|
-
"gem 'hanami', '5.0.0'\n",
|
33
|
-
"gem 'rack', '>=1.0'\n"
|
34
|
-
].join)
|
35
|
-
end
|
36
|
-
|
37
|
-
it "doesn't match file content" do
|
38
|
-
file = path_factory.call('Gemfile')
|
39
|
-
content = ::File.read(file)
|
40
|
-
status = TTY::File.replace_in_file(file, /unknown/, 'Hello', verbose: false)
|
41
|
-
|
42
|
-
expect(status).to eq(false)
|
43
|
-
expect(::File.read(file)).to eq(content)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "silences verbose output" do
|
47
|
-
content = "gem 'hanami'"
|
48
|
-
file = path_factory.call('Gemfile')
|
49
|
-
expect {
|
50
|
-
TTY::File.replace_in_file(file, /gem 'rails'/, content, verbose: false)
|
51
|
-
}.to_not output(/replace/).to_stdout_from_any_process
|
52
|
-
end
|
53
|
-
|
54
|
-
it "fails to replace content when missing correct file path" do
|
55
|
-
expect {
|
56
|
-
TTY::File.replace_in_file(path_factory.call('non-existent-path'),
|
57
|
-
/gem 'rails'/, "gem 'hanami'", verbose: false)
|
58
|
-
}.to raise_error(ArgumentError, /File path (.)* does not exist/)
|
59
|
-
end
|
60
|
-
|
61
|
-
it "logs action" do
|
62
|
-
content = "gem 'hanami'"
|
63
|
-
file = path_factory.call('Gemfile')
|
64
|
-
|
65
|
-
expect {
|
66
|
-
TTY::File.replace_in_file(file, /gem 'rails'/, content, noop: true)
|
67
|
-
}.to output(/\e\[32mreplace\e\[0m(.*)Gemfile/).to_stdout_from_any_process
|
68
|
-
end
|
69
|
-
|
70
|
-
it "logs action without color" do
|
71
|
-
content = "gem 'hanami'"
|
72
|
-
file = path_factory.call('Gemfile')
|
73
|
-
|
74
|
-
expect {
|
75
|
-
TTY::File.replace_in_file(file, /gem 'rails'/, content,
|
76
|
-
noop: true, color: false)
|
77
|
-
}.to output(/\s+replace(.*)Gemfile/).to_stdout_from_any_process
|
78
|
-
end
|
79
|
-
|
80
|
-
it "allows for noop run" do
|
81
|
-
content = "gem 'hanami'"
|
82
|
-
file = path_factory.call('Gemfile')
|
83
|
-
|
84
|
-
TTY::File.replace_in_file(file, /gem 'rails'/, content,
|
85
|
-
noop: true, verbose: false)
|
86
|
-
|
87
|
-
expect(File.read(file)).to eq([
|
88
|
-
"gem 'nokogiri'\n",
|
89
|
-
"gem 'rails', '5.0.0'\n",
|
90
|
-
"gem 'rack', '>=1.0'\n"
|
91
|
-
].join)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "doesn't replace content when no match found" do
|
95
|
-
content = "gem 'hanami'"
|
96
|
-
file = path_factory.call('Gemfile')
|
97
|
-
|
98
|
-
status = TTY::File.gsub_file(file, /gem 'rails'/, content, verbose: false)
|
99
|
-
expect(status).to eq(true)
|
100
|
-
expect(File.read(file)).to eq([
|
101
|
-
"gem 'nokogiri'\n",
|
102
|
-
"gem 'hanami', '5.0.0'\n",
|
103
|
-
"gem 'rack', '>=1.0'\n"
|
104
|
-
].join)
|
105
|
-
|
106
|
-
status = TTY::File.gsub_file(file, /gem 'rails'/, content, verbose: false)
|
107
|
-
expect(status).to eq(false)
|
108
|
-
|
109
|
-
expect(File.read(file)).to eq([
|
110
|
-
"gem 'nokogiri'\n",
|
111
|
-
"gem 'hanami', '5.0.0'\n",
|
112
|
-
"gem 'rack', '>=1.0'\n"
|
113
|
-
].join)
|
114
|
-
end
|
115
|
-
|
116
|
-
it "replaces with multibyte content" do
|
117
|
-
content = "gem 'ようこそ'"
|
118
|
-
file = path_factory.call('Gemfile')
|
119
|
-
|
120
|
-
TTY::File.gsub_file(file, /gem 'rails'/, content, verbose: false)
|
121
|
-
expect(File.open(file, 'r:UTF-8', &:read)).to eq([
|
122
|
-
"gem 'nokogiri'\n",
|
123
|
-
"#{content}, '5.0.0'\n",
|
124
|
-
"gem 'rack', '>=1.0'\n"
|
125
|
-
].join)
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
context "when passed a String instance for the file argument" do
|
130
|
-
let(:path_factory) { method(:tmp_path) }
|
131
|
-
|
132
|
-
include_context "replacing in a file"
|
133
|
-
end
|
134
|
-
|
135
|
-
context "when passed a Pathname instance for the file argument" do
|
136
|
-
let(:path_factory) { method(:tmp_pathname) }
|
137
|
-
|
138
|
-
include_context "replacing in a file"
|
139
|
-
end
|
140
|
-
end
|
data/spec/unit/tail_file_spec.rb
DELETED
@@ -1,77 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::File, '#tail_file' do
|
4
|
-
shared_context "tailing a file" do
|
5
|
-
it "tails file for lines with chunks smaller than file size" do
|
6
|
-
file = path_factory.call('tail/lines')
|
7
|
-
|
8
|
-
lines = TTY::File.tail_file(file, 5, chunk_size: 2**3)
|
9
|
-
|
10
|
-
expect(lines).to eq([
|
11
|
-
"line12",
|
12
|
-
"line13",
|
13
|
-
"line14",
|
14
|
-
"line15",
|
15
|
-
"line16"
|
16
|
-
])
|
17
|
-
end
|
18
|
-
|
19
|
-
it "tails file for lines with chunks equal file size" do
|
20
|
-
file = path_factory.call('tail/lines')
|
21
|
-
|
22
|
-
lines = TTY::File.tail_file(file, 5, chunk_size: file.size)
|
23
|
-
|
24
|
-
expect(lines).to eq([
|
25
|
-
"line12",
|
26
|
-
"line13",
|
27
|
-
"line14",
|
28
|
-
"line15",
|
29
|
-
"line16"
|
30
|
-
])
|
31
|
-
|
32
|
-
end
|
33
|
-
|
34
|
-
it "tails file for lines with chunks larger than file size" do
|
35
|
-
file = path_factory.call('tail/lines')
|
36
|
-
|
37
|
-
lines = TTY::File.tail_file(file, 5, chunk_size: 2**9)
|
38
|
-
|
39
|
-
expect(lines).to eq([
|
40
|
-
"line12",
|
41
|
-
"line13",
|
42
|
-
"line14",
|
43
|
-
"line15",
|
44
|
-
"line16"
|
45
|
-
])
|
46
|
-
end
|
47
|
-
|
48
|
-
it "tails file and yields lines" do
|
49
|
-
file = path_factory.call('tail/lines')
|
50
|
-
lines = []
|
51
|
-
|
52
|
-
TTY::File.tail_file(file, 5, chunk_size: 8) do |line|
|
53
|
-
lines << line
|
54
|
-
end
|
55
|
-
|
56
|
-
expect(lines).to eq([
|
57
|
-
"line12",
|
58
|
-
"line13",
|
59
|
-
"line14",
|
60
|
-
"line15",
|
61
|
-
"line16"
|
62
|
-
])
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
context "when passed a String instance for the file argument" do
|
67
|
-
let(:path_factory) { method(:tmp_path) }
|
68
|
-
|
69
|
-
include_context "tailing a file"
|
70
|
-
end
|
71
|
-
|
72
|
-
context "when passed a Pathname instance for the file argument" do
|
73
|
-
let(:path_factory) { method(:tmp_pathname) }
|
74
|
-
|
75
|
-
include_context "tailing a file"
|
76
|
-
end
|
77
|
-
end
|
data/tasks/console.rake
DELETED
data/tasks/coverage.rake
DELETED
data/tasks/spec.rake
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
begin
|
4
|
-
require 'rspec/core/rake_task'
|
5
|
-
|
6
|
-
desc 'Run all specs'
|
7
|
-
RSpec::Core::RakeTask.new(:spec) do |task|
|
8
|
-
task.pattern = 'spec/{unit,integration}{,/*/**}/*_spec.rb'
|
9
|
-
end
|
10
|
-
|
11
|
-
namespace :spec do
|
12
|
-
desc 'Run unit specs'
|
13
|
-
RSpec::Core::RakeTask.new(:unit) do |task|
|
14
|
-
task.pattern = 'spec/unit{,/*/**}/*_spec.rb'
|
15
|
-
end
|
16
|
-
|
17
|
-
desc 'Run integration specs'
|
18
|
-
RSpec::Core::RakeTask.new(:integration) do |task|
|
19
|
-
task.pattern = 'spec/integration{,/*/**}/*_spec.rb'
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
rescue LoadError
|
24
|
-
%w[spec spec:unit spec:integration].each do |name|
|
25
|
-
task name do
|
26
|
-
$stderr.puts "In order to run #{name}, do `gem install rspec`"
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
data/tty-file.gemspec
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
lib = File.expand_path('../lib', __FILE__)
|
2
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
-
require 'tty/file/version'
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = "tty-file"
|
7
|
-
spec.version = TTY::File::VERSION
|
8
|
-
spec.authors = ["Piotr Murach"]
|
9
|
-
spec.email = ["me@piotrmurach.com"]
|
10
|
-
|
11
|
-
spec.summary = %q{File manipulation utility methods.}
|
12
|
-
spec.description = %q{File manipulation utility methods.}
|
13
|
-
spec.homepage = "https://piotrmurach.github.io/tty"
|
14
|
-
spec.license = "MIT"
|
15
|
-
|
16
|
-
spec.files = Dir['{lib,spec}/**/*.rb']
|
17
|
-
spec.files += Dir['{bin,tasks}/*', 'tty-file.gemspec']
|
18
|
-
spec.files += Dir['README.md', 'CHANGELOG.md', 'LICENSE.txt', 'Rakefile']
|
19
|
-
spec.bindir = "exe"
|
20
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
-
spec.require_paths = ["lib"]
|
22
|
-
|
23
|
-
spec.required_ruby_version = '>= 2.0.0'
|
24
|
-
|
25
|
-
spec.add_dependency 'pastel', '~> 0.7.2'
|
26
|
-
spec.add_dependency 'tty-prompt', '~> 0.18'
|
27
|
-
spec.add_dependency 'diff-lcs', '~> 1.3'
|
28
|
-
|
29
|
-
spec.add_development_dependency 'bundler', '>= 1.5'
|
30
|
-
spec.add_development_dependency 'rake'
|
31
|
-
spec.add_development_dependency 'rspec', '~> 3.0'
|
32
|
-
spec.add_development_dependency 'webmock', '~> 3.4'
|
33
|
-
end
|