Michael Hartl的精彩Rails Tutorial现在可用于Rails 3.2。他继续使用rspec和spork概述TDD和BDD,就像他在3.0版本中所做的那样,并在3.2中增加了后卫。在3.0版本中,Hartl包含有关自动测试的信息,我能够获得精彩的咆哮通知。然而,在3.2中,他不再包括自动测试或咆哮信息。警卫与spork工作得很好,但没有通知。在过去的几个小时里,我使用Hartl的3.0和一些博客文章自己冒险,但试图让自动测试工作仍然会产生“LoadError”和咆哮通知“无法运行测试”。非常感谢任何想法。我在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
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
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>'
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
答案 0 :(得分:4)
我最终只是使用Sublime Text 2来适应Hartl的工作流程,但是,我确实想确保我可以切换到带有Growl通知的Guard,如果我想要的话(我不需要自动测试)知道,因为我相信这是卫兵的工作),所以这就是我在个人环境设置指南中做到的。希望它对你有所帮助。我在OSX 10.6.8上,所以在10.7.3上可能会有一些差异:
为RSpec测试通知设置Growl(适用于Mac):
可能已经在系统上安装了Growl,但是增长可能不是。
配置应用程序进行测试(RSpec,Cucumber with Spork and Guard):
$ rails generate rspec:install
$ rails generate cucumber:install
配置Spork(用于RSpec和黄瓜)
$ spork --bootstrap
$ spork cucumber --bootstrap
添加环境加载
$ subl spec/spec_helper.rb
将指令下的全部内容移到Spork.prefork
块中,只启用一次环境加载,并添加:
config.mock_with :rspec
配置Guard:
$ 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
...你应该收到Growl通知。
我在 Gemfile 中的相关宝石与您的宝石几乎相同。
答案 1 :(得分:1)
错误显示您缺少spec_helper文件。您可以尝试运行rails generate rspec:install
并再次尝试吗?
答案 2 :(得分:0)
我遇到了同样的问题,然后去了Guard的GitHub页面查看他们的文档。相关部分位于:https://github.com/guard/guard#growl
似乎简单的解决方案是在开发组中包含growl gem,而您只将它包含在测试组中。我做了以下工作来实现它:
已安装的Growl通知,如另一个答案中所述:
为RSpec测试通知设置Growl(对于Mac):可能是Growl 已安装在系统上,但growlnotify可能不是。
- 从here
下载Growl-1.2.2.dmg文件- 打开dmg文件,转到Extras&gt; growlnotify&gt; growlnotify.pkg
- 按照向导安装growlnotify
醇>
更新了我的Gemfile(仅限相关部分,其余部分与Rails教程相匹配):
group :development, :test do
gem 'sqlite3', '1.3.5'
gem 'rspec-rails', '2.11.0'
gem 'guard-rspec', '1.2.1'
gem 'guard-spork', '1.2.0'
gem 'childprocess', '0.3.6'
gem 'spork', '0.9.2'
gem 'growl', '1.0.3'
end
跑到终点站:
bundle install
打开一个新的终端窗口并运行:
guard
Growl开始工作了!