Skip to content

Commit bcffc9b

Browse files
committed
Throw Thor::Error upon file nonexistence; update specs
1 parent 5901842 commit bcffc9b

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

lib/thor/actions/inject_into_file.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def invoke!
5959
if File.exist?(destination)
6060
replace!(/#{flag}/, content, config[:force])
6161
else
62-
raise MalformattedArgumentError, "The file #{ destination } does not appear to exist"
62+
raise Thor::Error, "The file #{ destination } does not appear to exist"
6363
end
6464
end
6565

spec/actions/inject_into_file_spec.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,19 @@ def file
7171
end
7272

7373
it "does not attempt to change the file if it doesn't exist" do
74-
expect_any_instance_of(Thor::Actions::InjectIntoFile).not_to receive(:replace!)
7574
invoker.inject_into_file "idontexist", :before => "something" do
7675
"any content"
7776
end rescue nil
77+
78+
expect(File.exist?("idontexist")).to be_falsey
7879
end
7980

80-
it "raises a malformatted argument error including filename if file doesn't exist" do
81+
it "raises a Thor error including filename if file doesn't exist" do
8182
expect do
82-
invoker.inject_into_file "idontexist", :before => "something" do
83+
invoke! "idontexist", :before => "something" do
8384
"any content"
8485
end
85-
end.to raise_error(Thor::MalformattedArgumentError, /does not appear to exist/)
86+
end.to raise_error(Thor::Error, /does not appear to exist/)
8687
end
8788

8889
it "does change the file if already includes content and :force is true" do

0 commit comments

Comments
 (0)