已解决:取出保护文件中的spork代码,并从我的另一个与spork和guard一起使用的应用程序中复制并粘贴一个有效的保护文件。
我将Guard和Spork安装到我的应用程序中。 Guard工作正常,但是当我运行Spork时,Spork会加载并准备好听。一旦我打开一个新终端并启动rspec,Spork就会在第一个终端被杀死,这就出现了...
jason@jason:~/ror/blog$ guard
14:57:44 - INFO - Guard here! It looks like your project has a Gemfile, yet you are
running
> [#] `guard` outside of Bundler. If this is your intent, feel free to ignore this
> [#] message. Otherwise, consider using `bundle exec guard` to ensure your
> [#] dependencies are loaded correctly.
> [#] (You can run `guard` with --no-bundler-warning to get rid of this message.)
14:57:45 - INFO - Guard uses NotifySend to send notifications.
14:57:45 - INFO - Guard uses TerminalTitle to send notifications.
14:57:45 - INFO - Guard is now watching at '/home/jason/ror/blog'
14:57:45 - INFO - Starting Spork for RSpec
Using RSpec
Preloading Rails environment
WARNING: Nokogiri was built against LibXML version 2.7.8, but has dynamically loaded
2.8.0
Loading Spork.prefork block...
Spork is ready and listening on 8989!
14:58:02 - INFO - Spork server for RSpec successfully started
14:58:03 - INFO - Guard::RSpec is running, with RSpec 2!
14:58:03 - INFO - Running all specs
在原始终端上显示...
jason@jason:~/ror/blog$ spork
Using RSpec
Preloading Rails environment
WARNING: Nokogiri was built against LibXML version 2.7.8, but has dynamically loaded
2.8.0
Loading Spork.prefork block...
Spork is ready and listening on 8989!
Killed
jason@jason:~/ror/blog$
这是我的spec_helper文件
require 'rubygems'
require 'spork'
Spork.prefork do
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
# 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"
config.use_transactional_fixtures = true
config.infer_base_class_for_anonymous_controllers = false
config.treat_symbols_as_metadata_keys_with_true_values = true
config.filter_run :focus => true
config.run_all_when_everything_filtered = true
end
end
Spork.each_run do
FactoryGirl.reload
end
这是我的Guardfile
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
require 'active_support/core_ext'
guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV'
=> 'test' } do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.+\.rb$})
watch(%r{^config/initializers/.+\.rb$})
watch('spec/spec_helper.rb')
watch(%r{^spec/support/.+\.rb$})
end
guard 'rspec', :version => 2, :all_after_pass => false 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
我的gemfile包含
group :test do
gem 'capybara', '1.1.2'
gem 'rb-inotify', '0.8.8'
gem 'libnotify', '0.5.9'
gem 'factory_girl_rails', '4.1.0'
gem 'cucumber-rails', '1.2.1', :require => false
gem 'database_cleaner', '0.7.0'
end
group :development, :test do
gem 'rspec-rails', '2.11.0'
gem 'guard-rspec', '1.2.1'
gem 'guard-spork', '1.2.0'
gem 'spork', '0.9.2'
end
虽然看起来它正常工作,但测试花费的时间相同,所以我知道spork无法正常工作。
答案 0 :(得分:0)
为什么guard 'rspec', :version => 2 do
文件中有两个guard
?你应该删除第一个。并尝试将此添加到您的保护文件中:
guard 'spork', :rspec_env => { 'RAILS_ENV' => 'test' } do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.+\.rb$})
watch(%r{^config/initializers/.+\.rb$})
watch('Gemfile')
watch('Gemfile.lock')
watch('spec/spec_helper.rb')
watch('test/test_helper.rb')
watch('spec/support/')
end
但是,你需要记住:在RSpec / Cucumber / Test ::单位守卫之前放置Spork守卫!)。你可以在我的博客hkthanh89上获取战利品,我总结了一些信息来创建spork和后卫。
答案 1 :(得分:0)
在护卫文件中取出spork代码,然后从另一个与spork和guard一起使用的应用程序中复制并粘贴一个工作的guardfile。最后,我在护卫文件中不需要spork部分。