I'm trying to figure out how to get RubyMine's console to send messages to growl. Specifically, since I run Rspec & Spork through RubyMine, I'd like to get Growl notifications of how many tests passed & failed.
I had the command-line version of this functionality working via the Autotest and RedGreen gems, but neither gem seems to retain its usefulness inside RubyMine.
Has anyone successfully pushed Growl notifications from RubyMine?
Can anyone think of any of the t开发者_JAVA百科ools or mechanisms that could enable notification?
May be This code will help you
# -*- ruby -*-
module Autotest::RedGreen
Autotest.send(:alias_method, :real_ruby, :ruby)
Autotest.send(:define_method, :ruby) do |*args|
real_ruby + %[ -rrubygems -e "require 'redgreen'" ]
end
# Clean the output so other modules can work correctly
Autotest.add_hook :ran_command do |at|
at.results.each do |r|
r.gsub!("\033[31m", "")
r.gsub!("\033[32m", "")
r.gsub!("\033[33m", "")
r.gsub!("\033[0m", "")
end
end
end
module Autotest::Growl
AUTOTEST_IMAGE_ROOT = "~/.autotest_images"
def self.growl(title, msg, img, pri=0, sticky="")
system "growlnotify -n autotest --image #{img} -p #{pri} -m '#{msg.inspect} #{title}' #{sticky}"
end
Autotest.add_hook :red do |at|
growl("FAIL", "#{get_results(at)}", "#{AUTOTEST_IMAGE_ROOT}/fail.png", 2)
end
Autotest.add_hook :green do |at|
growl("Pass", "#{get_results(at)}", "#{AUTOTEST_IMAGE_ROOT}/pass.png")
end
private
def self.get_results(at)
results = [at.results].flatten.join("\n")
if results.include? 'tests'
output = results.slice(/(\d+)\s+tests?,\s*(\d+)\s+assertions?,\s*(\d+)\s+failures? (,\s*(\d+)\s+errors)?/)
else
output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+not implemented)?/)
end
output
end
end
# Esclusioni
Autotest.add_hook :initialize do |at|
%w{.hg .git .svn stories tmtags Rakefile Capfile README spec/spec.opts spec/rcov.opts vendor/gems autotest svn-commit .DS_Store }.each do |exception|
at.add_exception(exception)
end
at.add_mapping(/spec\/defaults.rb/) do |f, _|
at.files_matching %r%^spec/(controllers|helpers|lib|models|views)/.*\.rb$%
end
end
I don’t know about RubyMine but this should do in Terminal:
rake db:setup && growlnotify -m 'Finished DB setup'
You could trigger the rspec run with an AppleScript, then upon completion call Growl.
This applescript integration for RubyMine gives an idea of one way to hook events into Growl.
It's not a complete answer, but it's a reasonable approach.
精彩评论