Google Groups

Re: [Rails] Re: TDD killing my joy of Rails


Phlip Plumlee Nov 30, 2006 7:58 PM
Posted in group: Ruby on Rails: Talk
Brian Hogan wrote:

> Even better... install ZenTest
>
> gem install ZenTest
>
> autotest --rails
>
> Tests run when you save the corresponding file.  Makes it almost too easy.

My command line:

trigger 'rake recent' `find test -name \\*.rb` app/*/*.rb
app/views/*/*.rhtml

The utterly ugly and distastefully hacked-together contents of trigger are
below my sig.

Any editor, folks. Any editor. I don't even need to look at the console to
hear the results. If the punk rock ain't up too loud!

--
  Phlip
  http://www.greencheese.us/ZeekLand <-- NOT a blog!!!

#!/usr/bin/env ruby


 #  lazy-loop until a file changes, then run a command


def syntax()
    puts 'syntax: trigger "command...args" files...'
    exit 1
end

#  TODO  support **

syntax()  if 0 == ARGV.size

command = ARGV.shift
$fileTimes = {}


def anyFileChanged()
    anyChanged = false

    ARGV.each do |fn|  #  TODO  option to do Dir here
        begin
          mod = File.mtime(fn)
          anyChanged = true  if $fileTimes[fn] != mod
          $fileTimes[fn] = mod
        rescue
          puts $!
          sleep 2
        end
    end

    return anyChanged
end


anyFileChanged()  #  prime the pump

while true
    sleep 0.333
    if anyFileChanged()
        got = system(command)

        sound  = got ?  'drumloop.wav' :   'jaguar.wav'

        weWin32 = RUBY_PLATFORM.include?('mswin32')

        if weWin32
            system('"C:\\Program Files\\Windows Media Player\\mplayer2.exe"
/play /close s:\\bin\\' + sound)
        else
            system('aplay ~/bin/' + sound)
        end

    end
end


#One way is to use Win32API:

SND_MEMORY   = 0x00000004   # from "mmsystem.h"
SND_FILENAME = 0x00020000

def playSound()

  pPlaySound = Win32API.new("winmm", "PlaySound", ['P', 'L', 'L'], 'I')

  # play from file:
  pPlaySound.call("C:/your/sound.wav", 0, SND_FILENAME)

# play from memory:
  #wav = File.open("C:/your/sound.wav", File::RDONLY) {|f| f.binmode;
f.read }
  # PlaySound.call(wav, 0, SND_MEMORY)

end