Class: RVM::Tester::Runner
- Inherits:
-
Object
- Object
- RVM::Tester::Runner
- Defined in:
- lib/rvm-tester.rb
Instance Attribute Summary collapse
-
#bundle_install ⇒ Object
Returns the value of attribute bundle_install.
-
#command ⇒ Object
Returns the value of attribute command.
-
#env ⇒ Object
Returns the value of attribute env.
-
#num_workers ⇒ Object
Returns the value of attribute num_workers.
-
#rubies ⇒ Object
Returns the value of attribute rubies.
-
#use_travis ⇒ Object
Returns the value of attribute use_travis.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Instance Method Summary collapse
- #bright(msg) ⇒ Object
- #debug(info) ⇒ Object
- #fail(msg) ⇒ Object
-
#initialize(opts = {}) ⇒ Runner
constructor
A new instance of Runner.
- #load_travis_opts ⇒ Object
- #puts(msg = '') ⇒ Object
- #run ⇒ Object
- #success(msg) ⇒ Object
- #use_gemfile ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Runner
Returns a new instance of Runner.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rvm-tester.rb', line 29 def initialize(opts = {}) super() self.command = "rake" self.num_workers = 3 self.env = {} self.rubies = [] self.verbose = false self.bundle_install = true self.use_travis = true opts.each {|k,v| meth = "#{k}="; send(meth, v) if respond_to?(meth) } load_travis_opts if use_travis end |
Instance Attribute Details
#bundle_install ⇒ Object
Returns the value of attribute bundle_install.
26 27 28 |
# File 'lib/rvm-tester.rb', line 26 def bundle_install @bundle_install end |
#command ⇒ Object
Returns the value of attribute command.
24 25 26 |
# File 'lib/rvm-tester.rb', line 24 def command @command end |
#env ⇒ Object
Returns the value of attribute env.
23 24 25 |
# File 'lib/rvm-tester.rb', line 23 def env @env end |
#num_workers ⇒ Object
Returns the value of attribute num_workers.
21 22 23 |
# File 'lib/rvm-tester.rb', line 21 def num_workers @num_workers end |
#rubies ⇒ Object
Returns the value of attribute rubies.
22 23 24 |
# File 'lib/rvm-tester.rb', line 22 def rubies @rubies end |
#use_travis ⇒ Object
Returns the value of attribute use_travis.
27 28 29 |
# File 'lib/rvm-tester.rb', line 27 def use_travis @use_travis end |
#verbose ⇒ Object
Returns the value of attribute verbose.
25 26 27 |
# File 'lib/rvm-tester.rb', line 25 def verbose @verbose end |
Instance Method Details
#bright(msg) ⇒ Object
135 136 137 |
# File 'lib/rvm-tester.rb', line 135 def bright(msg) puts "\e[1m#{msg}\e[0m" end |
#debug(info) ⇒ Object
122 123 124 125 |
# File 'lib/rvm-tester.rb', line 122 def debug(info) return unless verbose puts(info) end |
#fail(msg) ⇒ Object
131 132 133 |
# File 'lib/rvm-tester.rb', line 131 def fail(msg) puts "\e[31;1m#{msg}\e[0m" end |
#load_travis_opts ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/rvm-tester.rb', line 107 def load_travis_opts return unless File.file?(".travis.yml") debug "Loading options from .travis.yml file" require 'yaml' yaml = YAML.load_file(".travis.yml") self.rubies = yaml['rvm'] if yaml['rvm'] self.command = yaml['script'] if yaml['script'] [yaml['env']].flatten.compact.each do |envvar| envvar.split(/\s+/).each do |subvar| key, value = *subvar.split("=") self.env[key] = value end end end |
#puts(msg = '') ⇒ Object
139 140 141 142 |
# File 'lib/rvm-tester.rb', line 139 def puts(msg = '') super(msg) $stdout.flush end |
#run ⇒ Object
42 43 44 45 46 47 48 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 |
# File 'lib/rvm-tester.rb', line 42 def run exit_status = 0 outputs = [] use_gemfile if bundle_install commands = rubies.map do |ruby| MobSpawner::Command.new( :command => "rvm #{ruby} do #{command}", :env => env, :data => {:ruby => ruby, :time => nil}) end spawner = MobSpawner.new spawner.commands = commands spawner.num_workers = num_workers spawner.before_worker do |data| worker, cmd = data[:worker], data[:command] debug "Worker #{worker} running tests in #{cmd.data[:ruby]}" data[:command].data[:time] = Time.now end spawner.after_worker do |data| worker, cmd = data[:worker], data[:command] next(outputs << data) if data[:output].nil? testinfo = data[:output][/(\d+ examples, \d+ failures)/, 1] testinfo += ", " if testinfo time = Time.now - data[:command].data[:time] passfail = data[:status] == 0 ? "passed" : "failed" msg = "Tests #{passfail} in #{cmd.data[:ruby]} (#{testinfo}#{"%.2f" % time}sec)" if data[:status] == 0 outputs << data if verbose success(msg) else outputs << data exit_status = 255 fail(msg) end end spawner.run return(exit_status) if outputs.size == 0 puts outputs.each do |data| if data[:exception] bright "Exception while running #{data[:command].data[:ruby]}:" puts data[:exception]. puts data[:exception].backtrace else bright "Output for #{data[:command].data[:ruby]} " + "(#{data[:status]}, cmd=#{data[:command].command}):" puts data[:output] end puts end exit_status end |
#success(msg) ⇒ Object
127 128 129 |
# File 'lib/rvm-tester.rb', line 127 def success(msg) puts "\e[32;1m#{msg}\e[0m" end |
#use_gemfile ⇒ Object
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/rvm-tester.rb', line 96 def use_gemfile return unless File.file?("Gemfile") print "Installing Bundler and dependencies on #{rubies.join(",")}..." cmds = rubies.map do |r| ver = r == '1.8.6' ? '-v 1.0.22' : '' # Bundler compat for 1.8.6 "rvm #{r} do gem install bundler #{ver} && rvm #{r} do bundle update" end MobSpawner.new(cmds).run puts "Done." end |