Class: Abt::TestWorker

Inherits:
IronWorker::Base
  • Object
show all
Defined in:
lib/abt/test_worker.rb

Overview

class MiniTestWithHooks < MiniTest::Unit

def before_suites
end

def after_suites
end

def _run_suites(suites, type)
  puts 'run_suites ' + suites.inspect + ' type=' + type.inspect
  begin
    before_suites
    super(suites, type)
  ensure
    after_suites
  end
end

def _run_suite(suite, type)
  puts 'run_suite ' + suite.inspect + ' type=' + type.inspect
  begin
    # suite.before_suite
    super(suite, type)
  ensure
    # suite.after_suite
  end
end

end

..

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#git_urlObject

Returns the value of attribute git_url.



46
47
48
# File 'lib/abt/test_worker.rb', line 46

def git_url
  @git_url
end

#notifiersObject

Returns the value of attribute notifiers.



46
47
48
# File 'lib/abt/test_worker.rb', line 46

def notifiers
  @notifiers
end

#notify_everyObject

Returns the value of attribute notify_every.



46
47
48
# File 'lib/abt/test_worker.rb', line 46

def notify_every
  @notify_every
end

#test_configObject

Returns the value of attribute test_config.



46
47
48
# File 'lib/abt/test_worker.rb', line 46

def test_config
  @test_config
end

Instance Method Details

#add_notifier(notifier_name, notifier_details = {}) ⇒ Object



48
49
50
51
# File 'lib/abt/test_worker.rb', line 48

def add_notifier(notifier_name, notifier_details={})
  @notifiers||=[]
  @notifiers<<{"notifier_name"=>notifier_name, "notifier_details"=>notifier_details}
end

#runObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/abt/test_worker.rb', line 53

def run
  if is_remote?
    require File.join(File.dirname(__FILE__), '/gems/minitest/lib/minitest/unit')
    require File.join(File.dirname(__FILE__), '/gems/test-unit/lib/test/unit/priority')
    require File.join(File.dirname(__FILE__), '/gems/test-unit/lib/test/unit/testcase')
    require File.join(File.dirname(__FILE__), '/gems/test-unit/lib/test/unit/assertions')
    require File.join(File.dirname(__FILE__), '/gems/test-unit/lib/test/unit')
    require File.join(File.dirname(__FILE__), '/gems/minitest/lib/minitest/autorun')
  end
    # Test::Unit.run = false
    #MiniTest::Unit.runner = MiniTestWithHooks.new
    # g = Git.open(user_dir, :log => Logger.new(STDOUT))
  clone_dir = 'cloned'
  x = File.join(user_dir, clone_dir)
  p x
  if is_local?
    FileUtils.rm_rf(File.join(user_dir, clone_dir))
  end

  $abt_config = self.test_config

  puts "cloning #{git_url}..."
  g = Git.clone(git_url, clone_dir, :path => user_dir)
  old_specs = nil
  current_gemfile = File.join(File.expand_path(user_dir+clone_dir+'/test'), 'Gemfile')
  log "GEMFILE:#{current_gemfile}"
  log "DIR:#{File.join(user_dir+clone_dir+'/test')}"
  if File.exist?(current_gemfile)
    log "Bundling gems"
    system "cd #{File.join(user_dir+clone_dir+'/test')}; bundle install --deployment"
    log "Gemfile:#{current_gemfile}"
    old_specs = Gem.loaded_specs.dup
    Gem.loaded_specs.clear
    ENV['BUNDLE_GEMFILE'] = current_gemfile
    log "Bundling!"
    require 'bundler/setup'
    log "List of gems from Gemfile: #{Gem.loaded_specs.inspect}"
  end
  Dir.glob(File.join(user_dir, clone_dir, 'test', 'test_*')).each { |f|
    puts "requiring #{f}"
    require f
  }

  Test::Unit::Notify::Notifier.add_params({:notify_every=>notify_every}) if notify_every
  if notifiers
    notifiers.each do |notifier|
      puts "NOTIFIER:#{notifier.inspect}"
      Test::Unit::Notify::Notifier.add_notifier(Kernel.const_get(notifier["notifier_name"]).new(notifier["notifier_details"]))
    end
  end
  Test::Unit::AutoRunner.run

  if old_specs
    Gem.loaded_specs.clear
    old_specs.each do |k, v|
      log "Loading gem:#{k}"
      Gem.loaded_specs[k]=v
    end
    log "Full list of gems: #{Gem.loaded_specs.inspect}"
  end

end