ruby-on-rails - Rails 教程 3.2 没有 growl 通知

标签 ruby-on-rails ruby-on-rails-3.2 autotest growl

迈克尔·哈特尔的精彩Rails Tutorial现在可用于 Rails 3.2。他继续使用 rspec 和 spork 概述 TDD 和 BDD,就像在 3.0 版本中所做的那样,并在 3.2 中添加了防护。在 3.0 版本中,Hartl 包含有关自动测试的信息,我能够让精彩的 growl 通知正常工作。然而,在 3.2 中,他不再包含自动测试或太多 growl 信息。 Guard 与 spork 配合良好,但没有通知。在过去的几个小时里,我自己冒险使用 Hartl 3.0 和一些博客文章,但尝试让自动测试工作仍然会产生“LoadError”和 growl 通知“无法运行测试”。 super 感谢任何想法。我使用的是 OS X 10.7.3。这是我所做的:

$ gem install autotest -v 4.4.6
$ gem install autotest-rails-pure -v 4.1.2
$ gem install autotest-fsevent -v 0.2.8
$ gem install autotest-growl -v 0.2.16

gem 文件

source 'https://rubygems.org'
gem 'rails', '3.2.3'
gem 'pg', '0.12.2'
group :development, :test do 
    gem 'rspec-rails', '2.9.0'
    gem 'guard-rspec', '0.5.5'
end

group :assets do
    gem 'sass-rails','3.2.4' 
    gem 'coffee-rails', '3.2.2'
    gem 'uglifier', '1.2.3' 
end
gem 'jquery-rails', '2.0.0'
group :test do
    gem 'capybara', '1.1.2'
    gem 'rb-fsevent', '0.4.3.1', :require => false
    gem 'growl', '1.0.3'
    gem 'guard-spork', '0.3.2'
    gem 'spork', '0.9.0'
end

~/.autotest

require 'autotest/growl'
require 'autotest/fsevent'
Autotest::Growl::show_modified_files = true
Autotest::Growl::one_notification_per_run = true
Autotest::Growl::clear_terminal = false
Autotest::Growl::hide_label = true

Autotest.add_hook :initialize do |autotest|
  autotest.add_mapping(/^spec\/requests\/.*_spec\.rb$/) do
    autotest.files_matching(/^spec\/requests\/.*_spec\.rb$/)
  end  
end

$自动测试

loading autotest/rails


      --------------------------------------------------------------------------------

/Users/[me]/.rvm/rubies/ruby-1.9.3-p194/bin/ruby -I.:lib:test -rubygems -e "%w[test/unit spec/requests/static_pages_spec.rb].each { |f| require f }"
/Users/[me]/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- spec_helper (LoadError)
    from        /Users/[me]/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from    /Users/[me]/programing/rails/rdale_house/spec/requests/static_pages_spec.rb:1:in `<top (required)>'
    from /Users/[me]/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from /Users/[me]/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
    from -e:1:in `block in <main>'
    from -e:1:in `each'
    from -e:1:in `<main>'

规范/spec_helper.rb

require 'rubygems'
require 'spork'
#uncomment the following line to use spork with the debugger
#require 'spork/ext/ruby-debug'

Spork.prefork do
  # Loading more in this block will cause your tests to run faster. However,
  # if you change any configuration or code from libraries loaded here, you'll
  # need to restart spork for it take effect.

  # This file is copied to spec/ when you run 'rails generate rspec:install'
  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'rspec/autorun'

  # Requires supporting ruby files with custom matchers and macros, etc,
  # in spec/support/ and its subdirectories.
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}

  RSpec.configure do |config|
    # ## Mock Framework
    #
    # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
    #
    # config.mock_with :mocha
    # config.mock_with :flexmock
    # config.mock_with :rr
    config.mock_with :rspec

    # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
    config.fixture_path = "#{::Rails.root}/spec/fixtures"

    # If you're not using ActiveRecord, or you'd prefer not to run each of your
    # examples within a transaction, remove the following line or assign false
    # instead of true.
    config.use_transactional_fixtures = true

    # If true, the base class of anonymous controllers will be inferred
    # automatically. This will be the default behavior in future versions of
    # rspec-rails.
    config.infer_base_class_for_anonymous_controllers = false
  end
end

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

end

最佳答案

我最终也只是使用 Sublime Text 2 来适应 Hartl 的工作流程,但是,我确实想确保如果我愿意的话,我可以切换到带有 Growl 通知的 Guard(据我所知,不需要自动测试)因为我相信这是 Guard 的工作),所以这就是我在我的个人环境设置指南中所做的。希望能给您带来一些帮助。我使用的是 OSX 10.6.8,因此您可能需要在 10.7.3 上执行一些操作:

为 RSpec 测试通知设置 Growl(对于 Mac):
Growl 可能已安装在系统上,但 Growlnotify 可能尚未安装。

  1. here 下载 Growl-1.2.2.dmg 文件
  2. 打开 dmg 文件并转到“附加”>“growlnotify”>“growlnotify.pkg”
  3. 按照向导安装growlnotify

配置应用程序进行测试(RSpec、Cucumber with Spork 和 Guard):

$ rails generate rspec:install
$ rails generate cucumber:install

配置 Spork(针对 RSpec 和 Cucumber)

$ spork --bootstrap
$ spork cucumber --bootstrap

添加环境加载

$ subl spec/spec_helper.rb

将说明下的全部内容移至 Spork.prefork block 中,以便仅加载一次环境,并添加:

config.mock_with :rspec

配置守卫:

$ guard init rspec
$ guard init spork

编辑生成的默认文件,以便 Guard 在失败的测试通过后不会运行所有测试; drb 标志用于 Spork 在分布式 Ruby 中运行。

$ subl Guardfile
guard 'rspec', :version => 2, :all_after_pass => false, :cli => '--drb'  do

配置在分布式 Ruby 中运行测试套件

$ subl .rspec
--drb

用 Spork 启动 Guard

$ guard

...您应该会收到 Growl 通知。

我的Gemfile中的相关 gem 与您的几乎相同。

关于ruby-on-rails - Rails 教程 3.2 没有 growl 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10472532/

相关文章:

ruby-on-rails - Zurb Foundation 单选按钮和复选框在 Rails 中不起作用

postgresql - Rails 3.2 + pg gem : load path issue

tdd - 从 Vagrant Ubuntu VM 向主机发送自动测试/保护桌面通知(W7 和 OS X)

ruby-on-rails - 自动测试不适用于 rspec 共享示例

ruby-on-rails - 在 RubyMine 中运行 rspec 测试得到 `bin/rspec:2: ` $ (' is not allowed as a global variable name`

ruby-on-rails - 哈希内的 Rails 循环

ruby-on-rails - Rails 3 : How to restrict access to the web interface for adding oauth authorized applications using Doorkeeper gem

android - 在未连接 USB 的情况下运行 UiAutomator 2.0 测试用例

ruby-on-rails - Rails 新形式 -> 无

ruby-on-rails - ActionView::Template::不支持错误对象