File tree Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Expand file tree Collapse file tree 2 files changed +18
-6
lines changed Original file line number Diff line number Diff line change @@ -53,10 +53,12 @@ def invoke!
53
53
replacement + '\0'
54
54
end
55
55
56
- if File . exist? ( destination )
56
+ if exists?
57
57
replace! ( /#{ flag } / , content , config [ :force ] )
58
58
else
59
- raise Thor ::Error , "The file #{ destination } does not appear to exist"
59
+ unless pretend?
60
+ raise Thor ::Error , "The file #{ destination } does not appear to exist"
61
+ end
60
62
end
61
63
end
62
64
@@ -95,7 +97,7 @@ def say_status(behavior)
95
97
# Adds the content to the file.
96
98
#
97
99
def replace! ( regexp , string , force )
98
- return if base . options [ : pretend]
100
+ return if pretend?
99
101
content = File . read ( destination )
100
102
if force || !content . include? ( replacement )
101
103
content . gsub! ( regexp , string )
Original file line number Diff line number Diff line change @@ -73,13 +73,23 @@ def file
73
73
74
74
it "does not attempt to change the file if it doesn't exist - instead raises Thor::Error" do
75
75
expect do
76
- invoke! "idontexist" , :before => "something" do
77
- "any content"
78
- end
76
+ invoke! "idontexist" , :before => "something" do
77
+ "any content"
78
+ end
79
79
end . to raise_error ( Thor ::Error , /does not appear to exist/ )
80
80
expect ( File . exist? ( "idontexist" ) ) . to be_falsey
81
81
end
82
82
83
+ it "does not attempt to change the file if it doesn't exist and pretending" do
84
+ expect do
85
+ invoker :pretend => true
86
+ invoke! "idontexist" , :before => "something" do
87
+ "any content"
88
+ end
89
+ end . not_to raise_error
90
+ expect ( File . exist? ( "idontexist" ) ) . to be_falsey
91
+ end
92
+
83
93
it "does change the file if already includes content and :force is true" do
84
94
invoke! "doc/README" , :before => "__end__" do
85
95
"more content\n "
You can’t perform that action at this time.
0 commit comments