gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 22:43:02 35 4
gpt4 key购买 nike

Michael Hartl 的精彩 Rails Tutorial现在可用于 Rails 3.2。他继续使用 rspec 和 spork 概述 TDD 和 BDD,就像他在 3.0 版中所做的那样,并在 3.2 中添加了 guard。在 3.0 版中,Hartl 包含有关自动测试的信息,我能够让美妙的 growl 通知正常工作。然而,在 3.2 中,他不再包含自动测试或大量 growl 信息。 Guard 与 spork 配合得很好,但没有通知。在过去的几个小时里,我自己冒险使用 Hartl 的 3.0 和一些博客文章,但尝试让自动测试工作仍然会产生“LoadError”和“无法运行测试”的 growl 通知。非常感谢任何想法。我在 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 文件并转到 Extras > growlnotify > growlnotify.pkg
  3. 按照向导安装growlnotify

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

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

配置 Spork(针对 RSpec 和 Cucumber)

$ spork --bootstrap
$ spork cucumber --bootstrap

添加环境加载

$ subl spec/spec_helper.rb

将 Instructions 下的全部内容移动到 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/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com