diff --git a/lib/foreman/cli.rb b/lib/foreman/cli.rb index 67d697ab..9cd51786 100644 --- a/lib/foreman/cli.rb +++ b/lib/foreman/cli.rb @@ -69,8 +69,9 @@ def export(format, location=nil) def check check_procfile! engine.load_procfile(procfile) - error "no processes defined" unless engine.processes.length > 0 puts "valid procfile detected (#{engine.process_names.join(', ')})" + rescue Foreman::Procfile::EmptyFileError + error "no processes defined" end desc "run COMMAND [ARGS...]", "Run a command using your application's environment" diff --git a/lib/foreman/procfile.rb b/lib/foreman/procfile.rb index b896dab3..74887212 100644 --- a/lib/foreman/procfile.rb +++ b/lib/foreman/procfile.rb @@ -10,6 +10,8 @@ # class Foreman::Procfile + EmptyFileError = Class.new(StandardError) + # Initialize a Procfile # # @param [String] filename (nil) An optional filename to read from @@ -60,7 +62,11 @@ def delete(name) # @param [String] filename The filename of the +Procfile+ to load # def load(filename) - @entries.replace parse(filename) + parse_data = parse(filename) + + raise EmptyFileError if parse_data.empty? + + @entries.replace parse_data end # Save a Procfile to a file diff --git a/spec/foreman/procfile_spec.rb b/spec/foreman/procfile_spec.rb index 71c15ea9..ae604245 100644 --- a/spec/foreman/procfile_spec.rb +++ b/spec/foreman/procfile_spec.rb @@ -22,6 +22,14 @@ expect(procfile["foo_bar"]).to eq("./foo_bar") end + it "raises an error if Procfile is empty" do + write_file "Procfile" do |procfile| + procfile.puts + end + + expect { Foreman::Procfile.new("Procfile") }.to raise_error described_class::EmptyFileError + end + it 'only creates Procfile entries for lines matching regex' do write_procfile procfile = Foreman::Procfile.new("Procfile")