How to Send RubyMine Notifications to Growl?
Asked Answered
Z

3

47

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 tools or mechanisms that could enable notification?

Zapata answered 13/4, 2011 at 19:22 Comment(1)
@NewAlexandria Your last edit has the keyword "tools" in it -- requests/recommendations for off-site resources will get this question closed quickly. I'd yank the word tools.Dartmouth
Z
1

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
Zed answered 20/8, 2014 at 14:9 Comment(1)
If someone tests this and verifies that it works, please comment here and I'll mark this as answered. I'm no longer working in RubyMine and am unable to verify.Zapata
B
0

I don’t know about RubyMine but this should do in Terminal:

rake db:setup && growlnotify -m 'Finished DB setup'
Bushranger answered 9/3, 2015 at 11:27 Comment(0)
I
-1

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.

Indeterminable answered 6/10, 2012 at 20:28 Comment(3)
I'm coordinating with the author to reinstate the original repo. Putting some code here is still preferable — but in this case it was long and perhaps any version of this answer would have included much volume. In either case, and my 'rep' aside, I disagree with the knee-jerk downvoting that occurs here without attempting to solicit discussion, as I do not consider it quality moderation, but obv. YMMV.Indeterminable
@NewAlexandria I'm happy to back out the downvote upon your edit. Tag me in a comment when your edit's been completed. The system won't let me back out my vote right now.Dartmouth
@LynnCrumbling I have updated the link (FWIW this far later)Indeterminable

© 2022 - 2024 — McMap. All rights reserved.