【问题标题】:Spork running and listening but not workingSpork 跑步和听但不工作
【发布时间】:2012-11-20 09:09:32
【问题描述】:

已解决:取出保护文件中的 spork 代码,然后从我的另一个与 spork 和保护一起使用的应用程序中复制并粘贴一个工作保护文件。

我在我的应用中安装了 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 不能正常工作。

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 guard spork


    【解决方案1】:

    为什么你的guard 文件中有两个guard 'rspec', :version => 2 do?您应该删除第一个。并尝试将其添加到您的保护文件中:

    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
    

    但是,您需要记住:将 Spork 保护放在 RSpec/Cucumber/Test::Unit 保护之前!)。你可以在我的博客hkthanh89 上抢,我总结了一些信息来创建spork 和guard。

    【讨论】:

    • 我用我正在使用的当前代码更新了我的问题,但它仍然无法正常工作。我到处都是意外的结束语法错误。
    • 什么语法错误?,您应该更新问题中的错误
    • 语法错误消失了,但现在出现了其他错误。检查问题以获取更新。
    • 可能是因为你没有使用Rubygems bundler,尝试运行bundle exec guardbundle exec spork
    • 更新您编辑并使用 bundle exec 的保护 spork 后,spork 无法工作。 Guard 当然可以,但我没有看到 spork 在我知道应该有的地方提高速度。
    【解决方案2】:

    取出保护文件中的 spork 代码,然后从我的另一个与 spork 和 guard 一起使用的应用程序中复制并粘贴一个工作保护文件。最后,我的保护文件中不需要 spork 部分。

    【讨论】:

      猜你喜欢
      • 2015-08-02
      • 2011-04-23
      • 2021-08-06
      • 1970-01-01
      • 2021-07-07
      • 2013-04-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-23
      相关资源
      最近更新 更多