Commit 2fcea0d5 authored by charlie-ablett's avatar charlie-ablett

Refactor out event trigger

parent fe62e59c
PATH
remote: .
specs:
ink_step (0.1.11)
ink_step (0.1.13)
awesome_print
httparty
rubyzip
......@@ -40,4 +40,4 @@ DEPENDENCIES
rspec
BUNDLED WITH
1.13.6
1.14.5
......@@ -31,7 +31,6 @@ module InkStep
def execute(options: {})
@started_at = Time.now
trigger_start_event! if respond_to?(:trigger_start_event!)
check_parameters(options)
create_directory_if_needed(working_directory)
get_input_files
......@@ -39,17 +38,11 @@ module InkStep
perform_step(options: options)
rescue => e
raise_and_log_error(e)
@successful = false
ensure
@finished_at = Time.now
trigger_completion_event! if respond_to?(:trigger_completion_event!)
log_as_step "Finished at #{@finished_at.utc.strftime("%Y-%m-%d %H:%M:%S UTC")}"
log_as_step "Errors: #{@errors}"
if @errors.any?
return
else
return if next_step.nil?
next_step.execute(options: options)
end
end
# A Basic Step on its own doesn't change the file at all
......@@ -80,6 +73,10 @@ module InkStep
raise NotImplementedError.new("You need to provide a Description method in your step (#{self.class.name}) that returns a string - a brief summary of what your step does (see CokoDemoSteps for an example)")
end
def working_directory
@working_directory ||= File.join(chain_file_location, position.to_s)
end
protected
def get_input_files
......@@ -94,10 +91,6 @@ module InkStep
copy_files_recursively(source, working_directory)
end
def working_directory
@working_directory ||= File.join(chain_file_location, position.to_s)
end
def log_as_step(message)
ap "[#{self.class.name}] - #{message}"
end
......
module InkStep
VERSION = '0.1.12'
VERSION = '0.1.13'
end
\ No newline at end of file
......@@ -74,10 +74,7 @@ describe InkStep::Base do
context "if the input file directory doesn't exist" do
it 'throws an error' do
expect(subject).to receive(:raise_and_log_error).with(RuntimeError)
expect(subject).to receive(:ap).with(/Cannot find source directory/)
subject.execute
expect{subject.execute}.to raise_error(/Cannot find source directory/)
end
end
......@@ -89,10 +86,7 @@ describe InkStep::Base do
context 'and it is empty' do
it 'throws an error' do
expect(subject).to receive(:raise_and_log_error).with(RuntimeError)
expect(subject).to receive(:ap).with(/Source directory (.*) is empty/)
subject.execute
expect{subject.execute}.to raise_error(/Source directory (.*) is empty/)
end
end
......@@ -144,17 +138,13 @@ describe InkStep::Base do
it 'with all missing, fails' do
subject.required_parameters = [:a_param, :some_other_param]
subject.execute
expect(subject.errors).to match_array(["Missing parameters: a_param, some_other_param"])
expect{subject.execute}.to raise_error("Missing parameters: a_param, some_other_param")
end
it 'with some missing, fails' do
subject.required_parameters = [:a_param, :some_other_param]
subject.execute(options: {a_param: "whatever"})
expect(subject.errors).to match_array(["Missing parameters: some_other_param"])
expect{subject.execute(options: {a_param: "whatever"})}.to raise_error("Missing parameters: some_other_param")
end
end
end
......
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