0

I've got a Rails project with a test suite that uses Test::Unit. I'm trying to set up Guard and Spork to run my tests automatically and fire notifications on pass/fail; Guard and Spork are running fine, and fire a notification when they start up, but I can't get any test notifications to work. I've tried using both Growl and Mac OS X notifications with terminal-notifier-guard.

Here's the relevant part of my Gemfile:

group :test do
  gem 'sqlite3'
  gem 'selenium-webdriver'
  gem 'rr', :require => false
  gem 'capybara'
  gem 'database_cleaner'
  gem 'timecop'
end

group :test, :development do
  gem 'guard'
  gem 'spork'
  gem 'spork-testunit'
  gem 'guard-test'
  gem 'guard-rake'
  gem 'guard-spork'
  gem 'terminal-notifier-guard', :require => false
  gem 'rb-inotify', require: false
  gem 'rb-fsevent', require: false
  gem 'rb-fchange', require: false
end

And test_helper.rb:

# -*- encoding : utf-8 -*-
require 'rubygems'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require 'spork'

Spork.prefork do
  require 'rubygems'
  ENV["RAILS_ENV"] = "test"
  require 'capybara/rails'
  require 'database_cleaner'
  require 'rr'
  require 'ostruct'
  require "#{Rails.root}/test/test_support"

  class ActionController::TestCase
    include Devise::TestHelpers
    def teardown
      super
      Timecop.return
    end
  end

  class ActionDispatch::IntegrationTest
    self.use_transactional_fixtures = false
    include Capybara::DSL
    Capybara.default_driver = :selenium
    DatabaseCleaner.strategy = :truncation

    def setup
      super
      DatabaseCleaner.clean
    end

    def teardown
      super
      DatabaseCleaner.clean
      Timecop.return
    end

    def login_admin(admin=nil)
      admin = Admin.create!(:email => "super_badass@wickedawesome.com", :password => "sloppy") if !admin
      visit "/admins/sign_in"
      fill_in "admin_email", :with => admin.email
      fill_in "admin_password", :with => admin.password
      click_on "log in"
      admin
    end
  end
end

Spork.each_run do
  # This code will be run each time you run your specs.

end

I'm at a loss. Any help would be greatly appreciated.

foobarPho
  • 35
  • 11
amd
  • 512
  • 1
  • 5
  • 13
  • It looks like this is a problem with `guard-test`. According to [the docs](https://github.com/guard/guard-test#drb-option), notifications aren't possible when using DRb. I've had some success using `guard-minitest` instead. – amd Jul 07 '13 at 03:55

2 Answers2

0

Try to use growl for notifications.

To do this, comment #gem "terminal-notifier-guard" and add

gem 'growl', require: false

Add the following to the beginning of Guardfile: notification :growl, sticky: true

Verify Growl installed and works, run: rails c and the following

Growl.notify {
  self.message = 'Hello World'
  self.icon = :jpeg
  sticky!
}

Guard should work now with Growl.

dpaluy
  • 3,537
  • 1
  • 28
  • 42
  • Still no luck. I can fire notifications in the console, and during the `Spork.each_run` block, but I'm still not seeing anything when the tests run. – amd Jul 07 '13 at 03:52
0

I've been fighting this same problem for months and just fixed it this morning. I used to be trying the gem growl as suggested in the other answer, but this morning I found in the documentation that they suggest you try ruby_gntp first and then use growl if you have problems.

Change your Gemfile to use gem ruby_gntp

Ensure you have Growl v.>=1.3

Add this line to the top of your Guardfile:

notification :gntp, :sticky => true, :host => '127.0.0.1'

and everything just clicked in place for me. I also had to make sure Growl was active on my machine, not just installed. I have v.2.0.1 from the App Store personally so I just launch it at start up. Hope this helps!

Brad Rice
  • 1,334
  • 2
  • 17
  • 36
  • I'm getting the same results as in the other answer; I can fire notifications in the console and in the `each_run` block, but I'm not seeing anything when the tests run. – amd Jul 07 '13 at 03:53
  • What is the output of Guard when you launch it? Is it saying `Guard uses _____ for notifications` or anything like that? Before I made these changes, my Guard was listing out two forms of notification, which I thought was odd. After I added the line to my Guardfile, the second line went away. – Brad Rice Jul 07 '13 at 18:21
  • I had been getting both `TerminalNotifier` and `TerminalTitle`; I added `notification :terminal_notifier` to my Guardfile and now I only get `TerminalNotifier`. Still doesn't generate notifications when using `guard-test` – amd Jul 08 '13 at 18:13