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.
-
#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.
- #puts(msg = '') ⇒ Object
- #run ⇒ Object
- #success(msg) ⇒ Object
- #use_gemfile ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Runner
Returns a new instance of Runner.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rvm-tester.rb', line 26 def initialize(opts = {}) super() self.command = "rake" self.num_workers = 3 self.env = {} self.rubies = [] self.verbose = false self.bundle_install = true opts.each {|k,v| meth = "#{k}="; send(meth, v) if respond_to?(meth) } end |
Instance Attribute Details
#bundle_install ⇒ Object
Returns the value of attribute bundle_install.
24 25 26 |
# File 'lib/rvm-tester.rb', line 24 def bundle_install @bundle_install end |
#command ⇒ Object
Returns the value of attribute command.
22 23 24 |
# File 'lib/rvm-tester.rb', line 22 def command @command end |
#env ⇒ Object
Returns the value of attribute env.
21 22 23 |
# File 'lib/rvm-tester.rb', line 21 def env @env end |
#num_workers ⇒ Object
Returns the value of attribute num_workers.
19 20 21 |
# File 'lib/rvm-tester.rb', line 19 def num_workers @num_workers end |
#rubies ⇒ Object
Returns the value of attribute rubies.
20 21 22 |
# File 'lib/rvm-tester.rb', line 20 def rubies @rubies end |
#verbose ⇒ Object
Returns the value of attribute verbose.
23 24 25 |
# File 'lib/rvm-tester.rb', line 23 def verbose @verbose end |
Instance Method Details
#bright(msg) ⇒ Object
116 117 118 |
# File 'lib/rvm-tester.rb', line 116 def bright(msg) puts "\e[1m#{msg}\e[0m" end |
#debug(info) ⇒ Object
103 104 105 106 |
# File 'lib/rvm-tester.rb', line 103 def debug(info) return unless verbose puts(info) end |
#fail(msg) ⇒ Object
112 113 114 |
# File 'lib/rvm-tester.rb', line 112 def fail(msg) puts "\e[31;1m#{msg}\e[0m" end |
#puts(msg = '') ⇒ Object
120 121 122 123 |
# File 'lib/rvm-tester.rb', line 120 def puts(msg = '') super(msg) $stdout.flush end |
#run ⇒ Object
37 38 39 40 41 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 |
# File 'lib/rvm-tester.rb', line 37 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
108 109 110 |
# File 'lib/rvm-tester.rb', line 108 def success(msg) puts "\e[32;1m#{msg}\e[0m" end |
#use_gemfile ⇒ Object
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/rvm-tester.rb', line 92 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 |