Commit 41f37a78 authored by charlie-ablett's avatar charlie-ablett

Logging available per step execution.

parent c445a0dc
PATH
remote: .
specs:
ink_step (0.1.14)
ink_step (0.1.15)
awesome_print
httparty
rubyzip
......@@ -11,7 +11,7 @@ GEM
specs:
awesome_print (1.7.0)
diff-lcs (1.2.5)
httparty (0.14.0)
httparty (0.15.5)
multi_xml (>= 0.5.2)
multi_xml (0.6.0)
rake (11.3.0)
......
......@@ -11,6 +11,7 @@ module InkStep
attr_accessor :next_step, :errors, :status_code, :required_parameters, :process_step,
:started_at, :finished_at, :position, :chain_file_location, :successful, :notes
:process_log
INPUT_FILE_DIRECTORY_NAME = "input_files"
OUTPUT_FILE_DIRECTORY_NAME = "output_files"
......@@ -77,6 +78,10 @@ module InkStep
@working_directory ||= File.join(chain_file_location, position.to_s)
end
def process_log
@process_log ||= []
end
protected
def get_input_files
......@@ -92,7 +97,9 @@ module InkStep
end
def log_as_step(message)
ap "#{Time.now.utc.strftime("%y-%m-%d %H:%M:%S")} [#{self.class.name}] - #{message}"
message_with_metadata = "#{Time.now.utc.strftime("%y-%m-%d %H:%M:%S")} [#{self.class.name}] - #{message}"
ap message_with_metadata
process_log << message_with_metadata.gsub(working_directory, "$working_directory")
end
def success!
......
module InkStep
VERSION = '0.1.14'
VERSION = '0.1.15'
end
\ No newline at end of file
......@@ -11,13 +11,13 @@ describe InkStep::Base do
let!(:input_file_path) { File.join(chain_file_location, InkStep::Base::INPUT_FILE_DIRECTORY_NAME) }
let!(:subject) { InkStep::Base.new(chain_file_location: chain_file_location, position: 1) }
let!(:working_directory) { subject.send(:working_directory) }
before do
create_directory_if_needed(chain_file_location)
end
describe '#find_source_files' do
let!(:working_directory) { subject.send(:working_directory) }
let(:doc1) { 'foo/bar baz/document.html' }
let(:doc2) { 'secret doc.docx' }
let(:file_list) { [doc1, doc2] }
......@@ -66,6 +66,41 @@ describe InkStep::Base do
end
describe "#log_as_step" do
context 'for a message without a path' do
let(:message) { "A nice message" }
it 'prints it to the log' do
expect(subject).to receive(:ap).with(/#{message}/)
subject.send(:log_as_step, message)
end
it 'saves the line in the log array' do
subject.send(:log_as_step, message)
expect(subject.process_log).to match_array([/#{message}/])
end
end
context 'for a message without a path' do
let(:message) { "#{working_directory}/input_files/input_file.html is a great file!" }
it 'strips the absolute path info from the process log' do
subject.send(:log_as_step, message)
expect(subject.process_log).to_not include(/#{working_directory}/)
expect(subject.process_log).to include(/\$working_directory\/input_files\/input_file\.html is a great file!/)
end
it 'includes the absolute path in the server logs' do
expect(subject).to receive(:ap).with(/#{message}/)
subject.send(:log_as_step, message)
end
end
end
describe '#execute' do
before do
allow(subject).to receive(:raise_and_log_error).and_call_original
......@@ -91,8 +126,6 @@ describe InkStep::Base do
end
context 'and it has something in it' do
let!(:working_directory) { subject.send(:working_directory) }
before do
FileUtils.cp(target_file, input_file_path)
end
......@@ -108,8 +141,6 @@ describe InkStep::Base do
end
describe 'required parameters' do
let!(:working_directory) { subject.send(:working_directory) }
before do
create_directory_if_needed(input_file_path)
FileUtils.cp(target_file, input_file_path)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment