class Crew::Task::Test
Public Class Methods
new(task, test_path_prefix, index, skip, test_blk)
click to toggle source
# File lib/crew/task/test.rb, line 40 def initialize(task, test_path_prefix, index, skip, test_blk) @task, @test_path_prefix, @index, @skip, @test_blk = task, test_path_prefix, index, skip, test_blk end
Public Instance Methods
clear_cached_result!()
click to toggle source
# File lib/crew/task/test.rb, line 108 def clear_cached_result! FileUtils.rm_rf(test_cache_path) end
has_cached_result?()
click to toggle source
# File lib/crew/task/test.rb, line 93 def has_cached_result? File.exist?(test_cache_path) end
logger()
click to toggle source
# File lib/crew/task/test.rb, line 119 def logger @task.home.logger end
record_test_result(status, extras = nil)
click to toggle source
# File lib/crew/task/test.rb, line 101 def record_test_result(status, extras = nil) FileUtils.mkdir_p(File.dirname(test_cache_path)) File.open(test_cache_path, "w") do |f| f << {status: status, extras: extras}.to_json end end
result()
click to toggle source
# File lib/crew/task/test.rb, line 44 def result if File.exist?(test_cache_path) result = JSON.parse(File.read(test_cache_path)) Result.new(@task.context.name, @task.name, @index, result['status'], result['extras']) else Result.new(@task.context.name, @task.name, @index, "missing", {}) end end
run_test!(fail_fast = false)
click to toggle source
# File lib/crew/task/test.rb, line 53 def run_test!(fail_fast = false) test_name = "#{@task.name} ##{@index + 1}" logger.test(test_name) do if has_cached_result? logger.info "Test already has a cached result" else clear_cached_result! if @skip logger.skip_test test_name record_test_result "skip" else status = "error" extra = {} @task.reset! extra[:start_time] = Time.new.to_f begin @task.context.with_callbacks do @task.instance_eval(&@test_blk) end rescue => e extra.merge!(exception: {backtrace: e.backtrace, message: e.message, class: e.class.to_s}) status = "fail" logger.fail_test(test_name) else status = "pass" logger.pass_test(test_name) end extra[:end_time] = Time.new.to_f record_test_result status, extra if status == 'fail' puts puts result raise FailedException if fail_fast end end end end result end
test_cache_path()
click to toggle source
# File lib/crew/task/test.rb, line 97 def test_cache_path File.join(@test_path_prefix, "#{@index}.json") end