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?

New Alexandria
  • 6,951
  • 4
  • 57
  • 77
D. Simpson
  • 1,882
  • 17
  • 32
  • @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`. – Lynn Crumbling Mar 09 '15 at 21:44

3 Answers3

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
Ashraf.Shk786
  • 618
  • 1
  • 11
  • 23
  • 2
    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. – D. Simpson Sep 02 '14 at 19:02
0

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

rake db:setup && growlnotify -m 'Finished DB setup'
rene
  • 41,474
  • 78
  • 114
  • 152
-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.

New Alexandria
  • 6,951
  • 4
  • 57
  • 77
  • 1
    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. – New Alexandria Mar 09 '15 at 20:23
  • 1
    @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. – Lynn Crumbling Mar 09 '15 at 21:42
  • @LynnCrumbling I have updated the link (FWIW this far later) – New Alexandria Oct 07 '15 at 16:14