guard / guard-minitest

Guard::Minitest automatically run your tests (much like autotest)
https://rubygems.org/gems/guard-minitest
MIT License
249 stars 88 forks source link

Display notification only on fail as an option? #134

Open Fedcomp opened 8 years ago

Fedcomp commented 8 years ago

Could be there option to display notification only when tests fail? Right now it spams me with every running, even if tests are not failing.

e2 commented 8 years ago

I don't use notification myself, but I'm guessing people use notification to know "if tests finished".

But it seems useful to opt out.

I don't know what notification backend you're using (depends on your OS and settings), but I think this could be a generic feature.

If you like, you can quickly hack a solution yourself and then send a PR if it works.

I'm not sure what kind of API/configuration would be best, but let's say it's:

notification(:tmux, {
  ignored_notifications: [:success] # < ---- maybe an option like this?
  success: 'colour150',
  failure: 'colour174',
  pending: 'colour179',
}) if ENV['TMUX']

And then in:

https://github.com/guard/notiffany/blob/fc138bb63ed94d754a0091a3813d3938db3c41a5/lib/notiffany/notifier/base.rb#L72

You'd skip the _perform_notify if the current notification type is in the "ignored" list.

polarlights commented 8 years ago

As I use minitest-reporter gem, I made a monkey patch in my test_helper.rb file.

module NofityFailureTest
  def record(test)
    super

    if test.error? || test.failure
      e = test.failure
      TerminalNotifier::Guard.notify(e.message, title: File.basename(e.location))
    end
  end
end

module Minitest
  module Reporters
    class  BaseReporter
      include NofityFailureTest if RUBY_PLATFORM =~ /darwin/ && `which terminal-notifier`.present?
    end
  end
end

You can monkey patch minitest gem If you like. It's in Minitest::Reporters::BaseReporter.