The ELC Community Blog
A knowledge exchange on Ruby on Rails and Agile Development
Reconciling TextMate With redgreen Tests
by ceberz on August 22, 2007
Many of us use Pat Eyler's redgreen gem for increased readability and aesthetic during our testing. Unfortunately for TextMate users like myself who enjoy using the program's support for invoking tests from within the editor, the redgreen gem conflicts with the editors already decorated output:

TextMate has a modest plethora (if you'll pardon the oxymoron) of environment variables that you can poll to see if the test is running in the scope of the editor. A conditional require in test_helper.rb...
require 'redgreen' if ENV['TM_FILENAME'].nil?
...will prevent the gem from being included when running your tests within TextMate. Tests invoked from the console will, of course, be decorated by the gem as usual.

Timeline
- Swfchart Generator
- ELC Sponsors Bratwurst on Rails
- Ruby on Rails Enterprise - PC World
- Ruby on Rails, C# Use Increasing
- Ruby on Rails Keynote at RailsConf
- Reconciling TextMate With redgreen Tests
- Rails with JRuby and Glassfish
- Scope Controller Model Plugin
- Congratulations to Buy.com, Shoperion and us!
- Migrate Test DB Rake Plugin
- FunnyOrDie.com in Time's 50 Best Websites of 2007
Comments
Awesome Thanks!
Btw, If you freeze the gem using gemsonrails you will need to edit the Init.rb slight to make it work. This is because the gem gets included automatically.
Just rap the code with the if statement. Here is how my init.rb looks like:
if ENV[‘TM_FILENAME’].nil? require_options = [“redgreen”] if require_lib = require_options.find { |path| File.directory?(File.join(File.dirname(FILE), ‘lib’, path)) } require File.join(File.dirname(FILE), ‘lib’, require_lib) else puts msg = “ERROR: Please update #{File.expand_path FILE} with the require path for linked RubyGem redgreen” exit end end