Skip to content

Commit efe79b5

Browse files
authored
Merge pull request #708 from scambra/patch-1
Fix for #707
2 parents dcc2bf3 + baf7e46 commit efe79b5

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/thor/actions/inject_into_file.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,14 @@ def say_status(behavior, warning: nil, color: nil)
106106
# Adds the content to the file.
107107
#
108108
def replace!(regexp, string, force)
109-
return if pretend?
110109
content = File.read(destination)
111110
before, after = content.split(regexp, 2)
112111
snippet = (behavior == :after ? after : before).to_s
113112

114113
if force || !snippet.include?(replacement)
115114
success = content.gsub!(regexp, string)
116115

117-
File.open(destination, "wb") { |file| file.write(content) }
116+
File.open(destination, "wb") { |file| file.write(content) } unless pretend?
118117
success
119118
end
120119
end

spec/actions/inject_into_file_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ def file
7272
expect(invoke!("doc/README", "\nmore content", :after => "__start__")).to eq(" insert doc/README\n")
7373
end
7474

75+
it "logs status if pretending" do
76+
invoker(:pretend => true)
77+
expect(invoke!("doc/README", "\nmore content", :after => "__start__")).to eq(" insert doc/README\n")
78+
end
79+
7580
it "does not change the file if pretending" do
7681
invoker :pretend => true
7782
invoke! "doc/README", "\nmore content", :after => "__start__"

0 commit comments

Comments
 (0)