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,101 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::File::Differ, '#call' do
|
4
|
-
it "diffs identical content" do
|
5
|
-
string_a = "aaa bbb ccc"
|
6
|
-
|
7
|
-
diff = TTY::File::Differ.new(string_a, string_a).call
|
8
|
-
|
9
|
-
expect(diff).to eq('')
|
10
|
-
end
|
11
|
-
|
12
|
-
it "diffs two files with single line content" do
|
13
|
-
string_a = "aaa bbb ccc"
|
14
|
-
string_b = "aaa xxx ccc"
|
15
|
-
|
16
|
-
diff = TTY::File::Differ.new(string_a, string_b).call
|
17
|
-
|
18
|
-
expect(diff).to eq(strip_heredoc(<<-EOS
|
19
|
-
@@ -1,2 +1,2 @@
|
20
|
-
-aaa bbb ccc
|
21
|
-
+aaa xxx ccc
|
22
|
-
EOS
|
23
|
-
))
|
24
|
-
end
|
25
|
-
|
26
|
-
it "diffs two files with multi line content" do
|
27
|
-
string_a = "aaa\nbbb\nccc\nddd\neee\nfff\nggg\nhhh\niii\njjj\nkkk\nlll\n"
|
28
|
-
string_b = "aaa\nbbb\nzzz\nddd\neee\nfff\nggg\nhhh\niii\njjj\nwww\n"
|
29
|
-
|
30
|
-
diff = TTY::File::Differ.new(string_a, string_b).call
|
31
|
-
|
32
|
-
expect(diff).to eq(strip_heredoc(<<-EOS
|
33
|
-
@@ -1,6 +1,6 @@
|
34
|
-
aaa
|
35
|
-
bbb
|
36
|
-
-ccc
|
37
|
-
+zzz
|
38
|
-
ddd
|
39
|
-
eee
|
40
|
-
fff
|
41
|
-
@@ -8,6 +8,5 @@
|
42
|
-
hhh
|
43
|
-
iii
|
44
|
-
jjj
|
45
|
-
-kkk
|
46
|
-
-lll
|
47
|
-
+www
|
48
|
-
EOS
|
49
|
-
))
|
50
|
-
end
|
51
|
-
|
52
|
-
it "handles differently encoded files" do
|
53
|
-
string_a = "wikipedia".encode('us-ascii')
|
54
|
-
string_b = "ウィキペディア".encode('UTF-8')
|
55
|
-
|
56
|
-
diff = TTY::File::Differ.new(string_a, string_b).call
|
57
|
-
|
58
|
-
expect(diff).to eq(strip_heredoc(<<-EOS
|
59
|
-
@@ -1,2 +1,2 @@
|
60
|
-
-wikipedia
|
61
|
-
+ウィキペディア
|
62
|
-
EOS
|
63
|
-
))
|
64
|
-
end
|
65
|
-
|
66
|
-
it "accepts format" do
|
67
|
-
string_a = "aaa\nbbb\nccc\n"
|
68
|
-
string_b = "aaa\nxxx\nccc\n"
|
69
|
-
|
70
|
-
diff = TTY::File::Differ.new(string_a, string_b, format: :old).call
|
71
|
-
|
72
|
-
expect(diff).to eq(strip_heredoc(<<-EOS
|
73
|
-
1,4c1,4
|
74
|
-
< aaa
|
75
|
-
< bbb
|
76
|
-
< ccc
|
77
|
-
---
|
78
|
-
> aaa
|
79
|
-
> xxx
|
80
|
-
> ccc
|
81
|
-
|
82
|
-
EOS
|
83
|
-
))
|
84
|
-
end
|
85
|
-
|
86
|
-
it "accepts context lines" do
|
87
|
-
string_a = "aaa\nbbb\nccc\nddd\neee\nfff"
|
88
|
-
string_b = "aaa\nbbb\nccc\nddd\nxxx\nfff"
|
89
|
-
|
90
|
-
diff = TTY::File::Differ.new(string_a, string_b, context_lines: 1).call
|
91
|
-
|
92
|
-
expect(diff).to eq(strip_heredoc(<<-EOS
|
93
|
-
@@ -4,3 +4,3 @@
|
94
|
-
ddd
|
95
|
-
-eee
|
96
|
-
+xxx
|
97
|
-
fff
|
98
|
-
EOS
|
99
|
-
))
|
100
|
-
end
|
101
|
-
end
|
@@ -1,68 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::File, '#download_file' do
|
4
|
-
shared_context "downloading a file" do
|
5
|
-
it "downloads a file from remote uri" do
|
6
|
-
body = "##Header1\nCopy text.\n"
|
7
|
-
stub_request(:get, "https://example.com/README.md").to_return(body: body)
|
8
|
-
path = path_factory.call('doc/README.md')
|
9
|
-
|
10
|
-
TTY::File.download_file('https://example.com/README.md', path, verbose: false)
|
11
|
-
|
12
|
-
expect(File.read(path)).to eq(body)
|
13
|
-
end
|
14
|
-
|
15
|
-
it "yields content from remoe uri" do
|
16
|
-
body = "##Header1\nCopy text.\n"
|
17
|
-
stub_request(:get, "https://example.com/README.md").to_return(body: body)
|
18
|
-
path = path_factory.call('doc/README.md')
|
19
|
-
|
20
|
-
TTY::File.download_file('https://example.com/README.md', path, verbose: false) do |content|
|
21
|
-
expect(a_request(:get, 'https://example.com/README.md')).to have_been_made
|
22
|
-
expect(content).to eq(body)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
it "logs file operation" do
|
27
|
-
body = "##Header1\nCopy text.\n"
|
28
|
-
stub_request(:get, "https://example.com/README.md").to_return(body: body)
|
29
|
-
path = path_factory.call('doc/README.md')
|
30
|
-
|
31
|
-
expect {
|
32
|
-
TTY::File.download_file('https://example.com/README.md', path)
|
33
|
-
}.to output(/create(.*)doc\/README.md/).to_stdout_from_any_process
|
34
|
-
end
|
35
|
-
|
36
|
-
it "specifies limit on redirects" do
|
37
|
-
stub_request(:get, "https://example.com/wrong").to_return(status: 302, headers: { location: 'https://example.com/wrong_again'})
|
38
|
-
stub_request(:get, "https://example.com/wrong_again").to_return(status: 302, headers: { location: 'https://example.com/README.md'})
|
39
|
-
|
40
|
-
path = path_factory.call('doc/README.md')
|
41
|
-
|
42
|
-
expect {
|
43
|
-
TTY::File.download_file('https://example.com/wrong', path, verbose: false, limit: 1)
|
44
|
-
}.to raise_error(TTY::File::DownloadError)
|
45
|
-
end
|
46
|
-
|
47
|
-
it "copies the file from relative location if not URI" do
|
48
|
-
src_path = path_factory.call('Gemfile')
|
49
|
-
dest_path = path_factory.call('app/Gemfile')
|
50
|
-
|
51
|
-
TTY::File.get_file(src_path, dest_path, verbose: false)
|
52
|
-
|
53
|
-
exists_and_identical?('Gemfile', 'app/Gemfile')
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context 'when passed a String instance for the file argument' do
|
58
|
-
let(:path_factory) { method(:tmp_path) }
|
59
|
-
|
60
|
-
include_context "downloading a file"
|
61
|
-
end
|
62
|
-
|
63
|
-
context 'when passed a Pathname instance for the file argument' do
|
64
|
-
let(:path_factory) { method(:tmp_pathname) }
|
65
|
-
|
66
|
-
include_context "downloading a file"
|
67
|
-
end
|
68
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::File, '#escape_glob_path' do
|
4
|
-
{
|
5
|
-
"foo?" => "foo\\?",
|
6
|
-
"*foo" => "\\*foo",
|
7
|
-
"foo[bar]" => "foo\\[bar\\]",
|
8
|
-
"foo{bar}" => "foo\\{bar\\}"
|
9
|
-
}.each do |glob, escaped_glob|
|
10
|
-
it "escapes #{glob} to #{escaped_glob}" do
|
11
|
-
expect(TTY::File.escape_glob_path(glob)).to eq(escaped_glob)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,176 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::File, '#inject_into_file' do
|
4
|
-
shared_context "injecting into file" do
|
5
|
-
it "injects content into file :before" do
|
6
|
-
file = path_factory.call('Gemfile')
|
7
|
-
TTY::File.inject_into_file(file, "gem 'tty'\n",
|
8
|
-
before: "gem 'rack', '>=1.0'\n", verbose: false)
|
9
|
-
|
10
|
-
expect(File.read(file)).to eq([
|
11
|
-
"gem 'nokogiri'\n",
|
12
|
-
"gem 'rails', '5.0.0'\n",
|
13
|
-
"gem 'tty'\n",
|
14
|
-
"gem 'rack', '>=1.0'\n",
|
15
|
-
].join)
|
16
|
-
end
|
17
|
-
|
18
|
-
it "injects content into file :after" do
|
19
|
-
file = path_factory.call('Gemfile')
|
20
|
-
|
21
|
-
expect {
|
22
|
-
TTY::File.inject_into_file(file, "gem 'tty'", after: "gem 'rack', '>=1.0'\n")
|
23
|
-
}.to output(/inject/).to_stdout_from_any_process
|
24
|
-
|
25
|
-
expect(File.read(file)).to eq([
|
26
|
-
"gem 'nokogiri'\n",
|
27
|
-
"gem 'rails', '5.0.0'\n",
|
28
|
-
"gem 'rack', '>=1.0'\n",
|
29
|
-
"gem 'tty'"
|
30
|
-
].join)
|
31
|
-
end
|
32
|
-
|
33
|
-
it "accepts content in block" do
|
34
|
-
file = path_factory.call('Gemfile')
|
35
|
-
|
36
|
-
expect {
|
37
|
-
TTY::File.insert_into_file(file, after: "gem 'rack', '>=1.0'\n") do
|
38
|
-
"gem 'tty'"
|
39
|
-
end
|
40
|
-
}.to output(/inject/).to_stdout_from_any_process
|
41
|
-
|
42
|
-
expect(File.read(file)).to eq([
|
43
|
-
"gem 'nokogiri'\n",
|
44
|
-
"gem 'rails', '5.0.0'\n",
|
45
|
-
"gem 'rack', '>=1.0'\n",
|
46
|
-
"gem 'tty'"
|
47
|
-
].join)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "accepts many lines" do
|
51
|
-
file = path_factory.call('Gemfile')
|
52
|
-
|
53
|
-
TTY::File.inject_into_file(file, "gem 'tty'\n", "gem 'loaf'",
|
54
|
-
after: "gem 'rack', '>=1.0'\n", verbose: false)
|
55
|
-
|
56
|
-
expect(File.read(file)).to eq([
|
57
|
-
"gem 'nokogiri'\n",
|
58
|
-
"gem 'rails', '5.0.0'\n",
|
59
|
-
"gem 'rack', '>=1.0'\n",
|
60
|
-
"gem 'tty'\n",
|
61
|
-
"gem 'loaf'"
|
62
|
-
].join)
|
63
|
-
end
|
64
|
-
|
65
|
-
it "logs action" do
|
66
|
-
file = path_factory.call('Gemfile')
|
67
|
-
|
68
|
-
expect {
|
69
|
-
TTY::File.inject_into_file(file, "gem 'tty'\n", "gem 'loaf'",
|
70
|
-
after: "gem 'rack', '>=1.0'\n", verbose: true)
|
71
|
-
}.to output(/\e\[32minject.*Gemfile/).to_stdout_from_any_process
|
72
|
-
end
|
73
|
-
|
74
|
-
it "logs action without color" do
|
75
|
-
file = path_factory.call('Gemfile')
|
76
|
-
|
77
|
-
expect {
|
78
|
-
TTY::File.inject_into_file(file, "gem 'tty'\n", "gem 'loaf'",
|
79
|
-
after: "gem 'rack', '>=1.0'\n", verbose: true, color: false)
|
80
|
-
}.to output(/\s+inject.*Gemfile/).to_stdout_from_any_process
|
81
|
-
end
|
82
|
-
|
83
|
-
it "doesn't inject new content if already present" do
|
84
|
-
file = path_factory.call('Gemfile')
|
85
|
-
TTY::File.inject_into_file(file, "gem 'tty'",
|
86
|
-
after: "gem 'rack', '>=1.0'\n", verbose: false)
|
87
|
-
|
88
|
-
expect(File.read(file)).to eq([
|
89
|
-
"gem 'nokogiri'\n",
|
90
|
-
"gem 'rails', '5.0.0'\n",
|
91
|
-
"gem 'rack', '>=1.0'\n",
|
92
|
-
"gem 'tty'"
|
93
|
-
].join)
|
94
|
-
|
95
|
-
TTY::File.inject_into_file(file, "gem 'tty'",
|
96
|
-
after: "gem 'rack', '>=1.0'\n",
|
97
|
-
force: false, verbose: false)
|
98
|
-
|
99
|
-
expect(File.read(file)).to eq([
|
100
|
-
"gem 'nokogiri'\n",
|
101
|
-
"gem 'rails', '5.0.0'\n",
|
102
|
-
"gem 'rack', '>=1.0'\n",
|
103
|
-
"gem 'tty'"
|
104
|
-
].join)
|
105
|
-
end
|
106
|
-
|
107
|
-
it "checks if a content can be safely injected" do
|
108
|
-
file = path_factory.call('Gemfile')
|
109
|
-
TTY::File.safe_inject_into_file(file, "gem 'tty'",
|
110
|
-
after: "gem 'rack', '>=1.0'\n", verbose: false)
|
111
|
-
expect(::File.read(file)).to eq([
|
112
|
-
"gem 'nokogiri'\n",
|
113
|
-
"gem 'rails', '5.0.0'\n",
|
114
|
-
"gem 'rack', '>=1.0'\n",
|
115
|
-
"gem 'tty'"
|
116
|
-
].join)
|
117
|
-
end
|
118
|
-
|
119
|
-
it "changes content already present if :force flag is true" do
|
120
|
-
file = path_factory.call('Gemfile')
|
121
|
-
|
122
|
-
TTY::File.inject_into_file(file, "gem 'tty'\n",
|
123
|
-
before: "gem 'nokogiri'", verbose: false)
|
124
|
-
|
125
|
-
expect(File.read(file)).to eq([
|
126
|
-
"gem 'tty'\n",
|
127
|
-
"gem 'nokogiri'\n",
|
128
|
-
"gem 'rails', '5.0.0'\n",
|
129
|
-
"gem 'rack', '>=1.0'\n",
|
130
|
-
].join)
|
131
|
-
|
132
|
-
TTY::File.inject_into_file(file, "gem 'tty'\n",
|
133
|
-
before: "gem 'nokogiri'", verbose: false, force: true)
|
134
|
-
|
135
|
-
expect(File.read(file)).to eq([
|
136
|
-
"gem 'tty'\n",
|
137
|
-
"gem 'tty'\n",
|
138
|
-
"gem 'nokogiri'\n",
|
139
|
-
"gem 'rails', '5.0.0'\n",
|
140
|
-
"gem 'rack', '>=1.0'\n",
|
141
|
-
].join)
|
142
|
-
end
|
143
|
-
|
144
|
-
it "fails to inject into non existent file" do
|
145
|
-
file = path_factory.call('unknown')
|
146
|
-
|
147
|
-
expect {
|
148
|
-
TTY::File.inject_into_file(file, "gem 'tty'", after: "gem 'rack', '>=1.0'\n")
|
149
|
-
}.to raise_error(ArgumentError, /File path (.)* does not exist/)
|
150
|
-
end
|
151
|
-
|
152
|
-
it "doesn't change content when :noop flag is true" do
|
153
|
-
file = path_factory.call('Gemfile')
|
154
|
-
TTY::File.inject_into_file(file, "gem 'tty'\n",
|
155
|
-
before: "gem 'nokogiri'", verbose: false, noop: true)
|
156
|
-
|
157
|
-
expect(File.read(file)).to eq([
|
158
|
-
"gem 'nokogiri'\n",
|
159
|
-
"gem 'rails', '5.0.0'\n",
|
160
|
-
"gem 'rack', '>=1.0'\n",
|
161
|
-
].join)
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
context "when passed a String instance for the file argument" do
|
166
|
-
let(:path_factory) { method(:tmp_path) }
|
167
|
-
|
168
|
-
include_context "injecting into file"
|
169
|
-
end
|
170
|
-
|
171
|
-
context "when passed a Pathname instance for the file argument" do
|
172
|
-
let(:path_factory) { method(:tmp_pathname) }
|
173
|
-
|
174
|
-
include_context "injecting into file"
|
175
|
-
end
|
176
|
-
end
|
@@ -1,124 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
RSpec.describe TTY::File, '#prepend_to_file' do
|
4
|
-
shared_context "prepending to a file" do
|
5
|
-
it "appends to file" do
|
6
|
-
file = path_factory.call('Gemfile')
|
7
|
-
|
8
|
-
result = TTY::File.prepend_to_file(file, "gem 'tty'\n", verbose: false)
|
9
|
-
|
10
|
-
expect(result).to eq(true)
|
11
|
-
expect(File.read(file)).to eq([
|
12
|
-
"gem 'tty'\n",
|
13
|
-
"gem 'nokogiri'\n",
|
14
|
-
"gem 'rails', '5.0.0'\n",
|
15
|
-
"gem 'rack', '>=1.0'\n",
|
16
|
-
].join)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "prepends multiple lines to file" do
|
20
|
-
file = path_factory.call('Gemfile')
|
21
|
-
|
22
|
-
TTY::File.prepend_to_file(file, "gem 'tty'\n", "gem 'rake'\n", verbose: false)
|
23
|
-
|
24
|
-
expect(File.read(file)).to eq([
|
25
|
-
"gem 'tty'\n",
|
26
|
-
"gem 'rake'\n",
|
27
|
-
"gem 'nokogiri'\n",
|
28
|
-
"gem 'rails', '5.0.0'\n",
|
29
|
-
"gem 'rack', '>=1.0'\n",
|
30
|
-
].join)
|
31
|
-
end
|
32
|
-
|
33
|
-
it "prepends content in a block" do
|
34
|
-
file = path_factory.call('Gemfile')
|
35
|
-
|
36
|
-
TTY::File.prepend_to_file(file, verbose: false) { "gem 'tty'\n"}
|
37
|
-
|
38
|
-
expect(File.read(file)).to eq([
|
39
|
-
"gem 'tty'\n",
|
40
|
-
"gem 'nokogiri'\n",
|
41
|
-
"gem 'rails', '5.0.0'\n",
|
42
|
-
"gem 'rack', '>=1.0'\n",
|
43
|
-
].join)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "doesn't prepend if already present" do
|
47
|
-
file = path_factory.call('Gemfile')
|
48
|
-
|
49
|
-
TTY::File.prepend_to_file(file, "gem 'nokogiri'\n", force: false, verbose: false)
|
50
|
-
|
51
|
-
expect(::File.read(file)).to eq([
|
52
|
-
"gem 'nokogiri'\n",
|
53
|
-
"gem 'rails', '5.0.0'\n",
|
54
|
-
"gem 'rack', '>=1.0'\n",
|
55
|
-
].join)
|
56
|
-
end
|
57
|
-
|
58
|
-
it "checks if a content can be safely prepended" do
|
59
|
-
file = path_factory.call('Gemfile')
|
60
|
-
TTY::File.safe_prepend_to_file(file, "gem 'nokogiri'\n", verbose: false)
|
61
|
-
expect(::File.read(file)).to eq([
|
62
|
-
"gem 'nokogiri'\n",
|
63
|
-
"gem 'rails', '5.0.0'\n",
|
64
|
-
"gem 'rack', '>=1.0'\n",
|
65
|
-
].join)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "doesn't prepend if already present for multiline content" do
|
69
|
-
file = path_factory.call('Gemfile')
|
70
|
-
|
71
|
-
TTY::File.prepend_to_file(file, "gem 'nokogiri'\n", verbose: false)
|
72
|
-
TTY::File.prepend_to_file(file, "gem 'nokogiri'\n", "gem 'nokogiri'\n", force: false, verbose: false)
|
73
|
-
|
74
|
-
expect(::File.read(file)).to eq([
|
75
|
-
"gem 'nokogiri'\n",
|
76
|
-
"gem 'nokogiri'\n",
|
77
|
-
"gem 'rails', '5.0.0'\n",
|
78
|
-
"gem 'rack', '>=1.0'\n",
|
79
|
-
].join)
|
80
|
-
end
|
81
|
-
|
82
|
-
it "prepends multiple times if forced" do
|
83
|
-
file = path_factory.call('Gemfile')
|
84
|
-
|
85
|
-
TTY::File.prepend_to_file(file, "gem 'nokogiri'\n", force: true, verbose: false)
|
86
|
-
TTY::File.prepend_to_file(file, "gem 'nokogiri'\n", "gem 'nokogiri'\n", force: true, verbose: false)
|
87
|
-
|
88
|
-
expect(::File.read(file)).to eq([
|
89
|
-
"gem 'nokogiri'\n",
|
90
|
-
"gem 'nokogiri'\n",
|
91
|
-
"gem 'nokogiri'\n",
|
92
|
-
"gem 'nokogiri'\n",
|
93
|
-
"gem 'rails', '5.0.0'\n",
|
94
|
-
"gem 'rack', '>=1.0'\n"
|
95
|
-
].join)
|
96
|
-
end
|
97
|
-
|
98
|
-
it "logs action" do
|
99
|
-
file = path_factory.call('Gemfile')
|
100
|
-
expect {
|
101
|
-
TTY::File.prepend_to_file(file, "gem 'tty'")
|
102
|
-
}.to output(/\e\[32mprepend\e\[0m.*Gemfile/).to_stdout_from_any_process
|
103
|
-
end
|
104
|
-
|
105
|
-
it "logs action without color" do
|
106
|
-
file = path_factory.call('Gemfile')
|
107
|
-
expect {
|
108
|
-
TTY::File.prepend_to_file(file, "gem 'tty'", color: false)
|
109
|
-
}.to output(/\s+prepend.*Gemfile/).to_stdout_from_any_process
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
context "when passed a String instance for the file argument" do
|
114
|
-
let(:path_factory) { method(:tmp_path) }
|
115
|
-
|
116
|
-
include_context "prepending to a file"
|
117
|
-
end
|
118
|
-
|
119
|
-
context "when passed a Pathname instance for the file argument" do
|
120
|
-
let(:path_factory) { method(:tmp_pathname) }
|
121
|
-
|
122
|
-
include_context "prepending to a file"
|
123
|
-
end
|
124
|
-
end
|