通知不适用于Mac上的Test :: Unit

时间:2013-07-06 19:08:06

标签: ruby-on-rails ruby testing guard testunit

我有一个带有Test :: Unit的测试套件的Rails项目。我正在尝试设置Guard和Spork以自动运行我的测试并在通过/失败时触发通知; Guard和Spork正常运行,并在启动时发出通知,但我无法获得任何测试通知。我已经尝试将Growl和Mac OS X通知与终端通知器保护同时使用。

这是我的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

和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

我很茫然。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

尝试使用growl进行通知。

为此,请评论#gem "terminal-notifier-guard"并添加

gem 'growl', require: false

将以下内容添加到 Guardfile 的开头:notification :growl, sticky: true

验证Growl已安装并正常运行,运行:rails c和以下

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

Guard现在应该使用Growl。

答案 1 :(得分:0)

我几个月来一直在解决同样的问题,今天早上就修好了。我曾经按照其他答案中的建议尝试gem growl,但今天早上我在documentation中发现他们建议您首先尝试ruby_gntp然后再使用growl你有问题。

更改您的Gemfile以使用gem ruby_gntp

确保您拥有Growl v。> = 1.3

将此行添加到Guardfile的顶部:

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

所有内容都为我点击了。我还必须确保Growl在我的机器上运行,而不仅仅是安装。我亲自从App Store获得v.2.0.1,所以我只是在启动时启动它。希望这有帮助!