I am trying to make Rubypond as universal an option as possible, and to that end, I am using Wayne E. Seguin’s excellent RVM to test across a number of ruby installations. For test suites using test/unit or something similar, RVM has the handy command
but this has been giving me problems when trying to run a test suite written in rspec. I don’t know whether it’s something I’m doing wrong, or something anyone else has run into, but I decided I’d just go ahead and write my own quick solution. So here’s what I ended up with:
begin
require ‘crayon’
rescue
module Crayon
def method_missing(m, *a, &b)
a.first
end
end
end
module RVM
def self.use(version)
system("rvm use #{version.to_s}")
end
def self.rubies
`rvm list | ack -o "32m[^\s]+"`.
split("\n").map{|r| r.gsub(/(32m|\e\(B\e\[m)/, "")}
end
end
RVM.rubies.each do |version|
if RVM.use(version)
if system("spec -fl rubypond_spec.rb")
puts Crayon.green("fine")
else
puts Crayon.red("less fine")
end
end
end
RVM.use(:system)
Crayon is my own library for colored terminal output. If it’s not installed, you get a ‘mock’ module that will print non-colored text, but saves you having to worry about requirement errors.
I created a small module RVM to hold wrappers for a couple command line methods because, well
if RVM.use(version)
…code…
end
end
is cleaner Ruby than having a bunch of `command line method` mixed in there.
The output in the event of failure is not particularly helpful in tracking down exact errors, but I like the concision of being able to keep the results on a single screen. And, of course, you can always change the spec command to provide more detailed output (the -fl option runs the ‘silent’ RSpec formatter).
Again, it’s entirely possible there’s a simpler way to do this, but given that this took about 10 minutes to throw together, and that about 5 of those were figuring out the ack and gsub commands to get a clean array of installed rubies, I feel the experimentation was worth it.
