Class: Abt::AbtWorker

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAbtWorker

Returns a new instance of AbtWorker.



24
25
26
# File 'lib/abt/abt_worker.rb', line 24

def initialize
  @notifiers = []
end

Instance Attribute Details

#git_urlObject

merge_folder ‘notifiers’



22
23
24
# File 'lib/abt/abt_worker.rb', line 22

def git_url
  @git_url
end

#notifiersObject

merge_folder ‘notifiers’



22
23
24
# File 'lib/abt/abt_worker.rb', line 22

def notifiers
  @notifiers
end

#notify_everyObject

merge_folder ‘notifiers’



22
23
24
# File 'lib/abt/abt_worker.rb', line 22

def notify_every
  @notify_every
end

#test_configObject

merge_folder ‘notifiers’



22
23
24
# File 'lib/abt/abt_worker.rb', line 22

def test_config
  @test_config
end

Instance Method Details

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



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/abt/abt_worker.rb', line 28

def add_notifier(notifier_class, notifier_details={})
  p notifier_class
  p notifier_details
  notifier_entry = {}
  if notifier_class.instance_of?(Symbol)
    p Abt.notifiers
    n = Abt.notifiers[notifier_class]
    puts "n=" + n.inspect
    raise "Notifier not found: #{notifier_class}" if n.nil?
    self.class.merge n[:file]
    notifier_entry["class_name"] = n[:class_name]
    notifier_entry["config"] = notifier_details[:config]
  else
    self.class.merge notifier_class
    raise "Must include :class option" if notifier_details[:class_name].nil?
    notifier_entry["class_name"] = notifier_details[:class_name]
    notifier_entry["config"] = notifier_details[:config]
  end
  @notifiers << notifier_entry
end

#runObject



49
50
51
52
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
# File 'lib/abt/abt_worker.rb', line 49

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
  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["class_name"]).new(notifier["config"]))
    end
  end
  puts 'Starting autorunner'
  Test::Unit::AutoRunner.run
  puts 'Autorunner finished'

  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