0

我在ruby​​-1.9.2-p180上运行rails 2.3.14 我正在尝试让 guard rspec 运行。

我安装了相关的gems,这是我的文件内容,用于Gemfile/spec/spec_helper.rbGuardfile


宝石文件

group :test, :development do
  gem 'rspec-rails', '~> 1.3.2', :require => false
  gem 'simplecov', :require => false
end

group :test do
  gem 'test-unit', '1.2.3', :require => false # for rspec
  gem 'rspec', '~> 1.3.2', '~> 1.2', :require => false
  gem 'guard', :require => false
  gem 'rb-inotify', '~> 0.9', :require => false
  gem 'spork', '~> 0.8', :require => false
  gem 'guard-rspec', :require => false
  gem 'guard-spork', :require => false
  gem 'growl', :require => false      # notifications; optional
  gem 'listen', '>= 0.5.1', :require => false
  gem 'machinist', '~> 2.0', :require => false
  gem 'database_cleaner', '~> 0.9.1', :require => false
end

spec_helper.rb

require 'rubygems'
require 'spork'

Spork.prefork do
  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path(File.join(File.dirname(__FILE__),'..','config','environment'))
  require 'spec/autorun'
  require 'spec/rails'
end

Spork.each_run do
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
end

Spec::Runner.configure do |config|  
  config.use_transactional_fixtures = true
  config.use_instantiated_fixtures  = false
  config.fixture_path = RAILS_ROOT + '/spec/fixtures/'
end

保护文件

# A sample Guardfile
# More info at https://github.com/guard/guard#readme

guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
  watch('config/application.rb')
  watch('config/environment.rb')
  watch('config/environments/test.rb')
  watch(%r{^config/initializers/.+\.rb$})
  watch('Gemfile')
  watch('Gemfile.lock')
  watch('spec/spec_helper.rb') { :rspec }
  watch('test/test_helper.rb') { :test_unit }
  watch(%r{features/support/}) { :cucumber }
end

guard 'rspec', :version => 1 do
  watch(%r{^spec/.+_spec\.rb$})
  watch(%r{^lib/(.+)\.rb$})     { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch('spec/spec_helper.rb')  { "spec" }

  # Rails example
  watch(%r{^app/(.+)\.rb$})                           { |m| "spec/#{m[1]}_spec.rb" }
  watch(%r{^app/(.*)(\.erb|\.haml)$})                 { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
  watch(%r{^app/controllers/(.+)_(controller)\.rb$})  { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
  watch(%r{^spec/support/(.+)\.rb$})                  { "spec" }
  watch('config/routes.rb')                           { "spec/routing" }
  watch('app/controllers/application_controller.rb')  { "spec/controllers" }

  # Capybara request specs
  watch(%r{^app/views/(.+)/.*\.(erb|haml)$})          { |m| "spec/requests/#{m[1]}_spec.rb" }

  # Turnip features and steps
  watch(%r{^spec/acceptance/(.+)\.feature$})
  watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$})   { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end


当我跑

耙规格

它工作正常


但是当我跑步时

警卫

它向我显示了这个错误

13:04:24 - INFO - Guard uses NotifySend to send notifications.
13:04:24 - INFO - Guard uses TerminalTitle to send notifications.
13:04:24 - INFO - Starting Spork for RSpec
Using RSpec
Preloading Rails environment
no such file to load -- /home/francois/sites/easylodge/config/application (LoadError)

更新

当我在Guardfile中注释掉这部分时,它看起来启动正常

# guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
#   watch('config/application.rb')
#   watch('config/environment.rb')
#   watch('config/environments/test.rb')
#   watch(%r{^config/initializers/.+\.rb$})
#   watch('Gemfile')
#   watch('Gemfile.lock')
#   watch('spec/spec_helper.rb') { :rspec }
#   watch('test/test_helper.rb') { :test_unit }
#   watch(%r{features/support/}) { :cucumber }
# end

导致控制台

13:17:01 - INFO - Guard uses NotifySend to send notifications.
13:17:01 - INFO - Guard uses TerminalTitle to send notifications.
13:17:01 - INFO - Guard::RSpec is running, with RSpec 1!
13:17:01 - INFO - Running all specs
13:17:07 - INFO - Guard is now watching at '/home/francois/sites/easylodge'
4

1 回答 1

0

gemfile 中的错误版本:/

新的宝石文件

group :test, :development do
  gem 'rspec-rails', '~> 1.2', :require => false
  gem 'simplecov', :require => false
end

group :test do
  gem 'test-unit', '1.2.3', :require => false # for rspec
  gem 'rspec', '~> 1.2', :require => false
  gem 'guard', :require => false
  gem 'spork', '~> 0.8.0', :require => false
  gem 'guard-rspec', :require => false
  gem 'guard-spork', :require => false
  gem 'growl', :require => false      # notifications; optional
  gem 'listen', '>= 0.5.1', :require => false
  gem 'machinist', '~> 2.0', :require => false
  gem 'database_cleaner', '~> 0.9.1', :require => false
end


感谢这篇文章


在 Rails 2 项目中设置 RSpec、Guard 和 Spork

我已经做过几次了;希望这对需要维护 Rails 2.3 应用程序的人有所帮助。这对我开发的应用程序非常有用,但我欢迎其他人提出额外步骤的建议。

本指南假定Bundler 上的Rails 2.3.x 项目

摆脱了项目中任何旧的 rspec 插件,如果有的话。RSpec 位可能隐藏在:

  • 耙文件
  • lib/tasks/rspec.rake
  • 供应商/插件/rspec
  • (你能找到的任何其他东西)


RSpec 2 与 Rails 2 不兼容;使用 RSpec 1(文档)。将最新的兼容 gem 版本放入您的 Gemfile:

gem 'test-unit', '1.2.3', :require => false # for rspec
gem 'rspec', '~> 1.2', :require => false
gem 'rspec-rails', '~> 1.2', :require => false
gem 'guard', :require => false
gem 'spork', '~> 0.8.0', :require => false
gem 'guard-rspec', :require => false
gem 'guard-spork', :require => false
gem 'growl', :require => false      # notifications; optional
gem 'rb-fsevent', :require => false # for OSX; optional
gem 'listen', '>= 0.5.1', :require => false
gem 'machinist', '~> 2.0', :require => false
gem 'database_cleaner', '~> 0.9.1', :require => false

安装捆绑包。对Gemfile

中已经存在的任何 gem 使用 bundle update 。 确保lib/tasks/rspec.rake spec/spec_helper.rb不存在。





./script/generate rspec



删除添加到config/environments/test.rb的config.gem行;该应用程序使用捆绑器。

spork --bootstrap

然后编辑spec/spec_helper.rb并按照说明进行操作。

将股票spec_helper.rb中的所有内容移动到 prefork 块中,

except:Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}

属于each_run。

安装 database_cleaner。在spec/spec_helper.rb中,在 prefork 块中: require 'database_cleaner' 在 each_run 块中: DatabaseCleaner.clean

初始化 Guardfile

guard init spork

guard init rspec

修改 Guardfile 的 rspec 保护以使用正确的版本和 drb (spork):

guard 'rspec', :version => 1, :cli => '--drb --color' do


根据您的项目 Run rake 规范修改 Guardfile。您应该没有输出(如果您没有测试)。如果您遇到错误,请解决它们。

跑卫。没有错误?太好了,测试一下!
问题?通过运行规范规范而不是重新运行守卫来更快地重试。

于 2013-03-07T12:49:17.197 回答