Add deploy test to execute a test class after deploy

Some small changes made to the way errors are displayed to have clearer
languge with test execution
This commit is contained in:
ViViDboarder 2013-06-03 11:47:35 -07:00
parent af0538de62
commit ca9b5dcd2a
3 changed files with 66 additions and 5 deletions

View File

@ -83,18 +83,26 @@ module AbuseTheForce
end
end
def self.deploy_project(dpath=Atf_Config.get_project_path)
def self.deploy_test(dpath, test_name)
options = { :run_tests => [ test_name ], :rollback_on_error => true }
deploy_project(dpath, options)
end
def self.deploy_project(dpath=Atf_Config.get_project_path, options={ :rollback_on_error => true })
if @client == nil
build_client
end
if File.file? File.join(dpath, 'package.xml')
@client.deploy(File.expand_path(dpath), { :rollback_on_error => true }).
@client.deploy(File.expand_path(dpath), options).
on_complete { |job|
puts "Finished deploy #{job.id}!"
result = job.result
if result != nil
puts "\nDeploy #{result.success ? "SUCCESS" : "FAILURE"}"
# If a failed deploy, print errors
@ -105,18 +113,40 @@ module AbuseTheForce
result.messages = [].push result.messages
end
puts "ERRORS: #{result.messages.size}"
puts "DEPLOY ERRORS: #{result.messages.reject { |m| m.success }.size}"
result.messages.each do |m|
# If the path is not from the project, fix it
unless m.file_name.starts_with? Atf_Config.src
m.file_name = m.file_name.sub(/[a-zA-Z._-]*\//, Atf_Config.src + '/')
end
# Print our error in teh format "filename:line:column type in object message"
if !m.success
puts "#{m.file_name}:#{m.line_number}:#{m.column_number} #{m.problem_type} in #{m.full_name} #{m.problem}"
end
end
# Need messages in an array
if result.run_test_result != nil
unless result.run_test_result.failures.kind_of? Array
result.run_test_result.failures = [].push result.run_test_result.failures
end
puts "TESTS RUN: #{result.run_test_result.num_tests_run} FAILURES: #{result.run_test_result.num_failures}"
result.run_test_result.failures.each do |m|
# Print our error in teh format "filename:line:column type in object message"
if !m.success
puts "#{m.name}.#{m.method_name}: #{m.message}"
puts "Stack Trace: #{m.stack_trace}"
puts ""
end
end
end
end
end
}.
on_error { |job| puts "Something bad happened!" }.

View File

@ -256,6 +256,37 @@ module AbuseTheForce
end
end
desc "test <path to file>", "Deploy and execute a test class"
long_desc <<-LONG_DESC
Deploys file at path <path to file> to the active target and executes tests in that class.
If test fails changes are rolled back
LONG_DESC
def test(fpath)
AbuseTheForce.clean_temp
AbuseTheForce.copy_temp_file fpath
# If a new target was provided, switch to it
if options[:target] != nil
AbuseTheForce.temp_switch_target options[:target]
end
# Get path to temp project directory
temp_path = File.join(Atf_Config.root_dir, TEMP_DIR)
test_name = File.basename fpath, '.*'
# Deploy
AbuseTheForce.deploy_test temp_path, test_name
# if using a temp target, switch back
if options[:target] != nil
AbuseTheForce.temp_switch_target
end
end
desc "list <path to list>", "Deploy a list of files"
long_desc <<-LONG_DESC
Parameter is a path a file containing a realtive list of files to be deployed.

View File

@ -1,3 +1,3 @@
module AbuseTheForce
VERSION = '0.1.0'
VERSION = '0.1.2'
end