【问题标题】:Getting spork to work with Ruby 1.9.2/3 + Rails 3.1 + Rspec?让 spork 与 Ruby 1.9.2/3 + Rails 3.1 + Rspec 一起工作?
【发布时间】:2011-11-07 02:30:46
【问题描述】:

那里有很多可靠的教程,而且我过去没有遇到太多麻烦。但是,经过几个小时的尝试,我一定错过了一些东西。

我已经完成了标准安装说明,并启动了 spork 服务器:

Using RSpec
Preloading Rails environment
Loading Spork.prefork block...
Spork is ready and listening on 8989!

看起来不错。

然后,我跳到一个新标签并运行我的规范:

$ rspec spec

此命令仅运行一瞬间后不返回任何内容。所以我跳回 spork 服务器查看发生了什么并得到:

Using RSpec
Preloading Rails environment
Loading Spork.prefork block...
Spork is ready and listening on 8989!
Running tests with args ["--color", "spec"]...
Exception encountered: #<DRb::DRbConnError: druby://localhost:56736 - #<Errno::ECONNREFUSED: Connection refused - connect(2)>>
backtrace:
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:736:in `rescue in block in open'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:730:in `block in open'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:729:in `each'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:729:in `open'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:1191:in `initialize'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:1171:in `new'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:1171:in `open'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:1087:in `block in method_missing'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:1105:in `with_friend'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:1086:in `method_missing'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:1074:in `respond_to?'
/Users/briancody/.rvm/gems/ruby-1.9.3-p0@scholastica/gems/spork-0.9.0.rc9/lib/spork/run_strategy/forking.rb:10:in `block in run'
/Users/briancody/.rvm/gems/ruby-1.9.3-p0@scholastica/gems/spork-0.9.0.rc9/lib/spork/forker.rb:21:in `block in initialize'
/Users/briancody/.rvm/gems/ruby-1.9.3-p0@scholastica/gems/spork-0.9.0.rc9/lib/spork/forker.rb:18:in `fork'
/Users/briancody/.rvm/gems/ruby-1.9.3-p0@scholastica/gems/spork-0.9.0.rc9/lib/spork/forker.rb:18:in `initialize'
/Users/briancody/.rvm/gems/ruby-1.9.3-p0@scholastica/gems/spork-0.9.0.rc9/lib/spork/run_strategy/forking.rb:9:in `new'
/Users/briancody/.rvm/gems/ruby-1.9.3-p0@scholastica/gems/spork-0.9.0.rc9/lib/spork/run_strategy/forking.rb:9:in `run'
/Users/briancody/.rvm/gems/ruby-1.9.3-p0@scholastica/gems/spork-0.9.0.rc9/lib/spork/server.rb:48:in `run'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:1548:in `perform_without_block'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:1508:in `perform'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:1586:in `block (2 levels) in main_loop'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:1582:in `loop'
/Users/briancody/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/drb/drb.rb:1582:in `block in main_loop'
Done.

由于某种原因,drb 连接失败?我疯狂地用谷歌搜索,但似乎没有任何帮助。

一些可能的线索

  • 每次我尝试运行套件时,端口(在本例中为 56736)都会发生变化
  • 我在 ruby​​ 1.9.2 和 ruby​​ 1.9.3 上得到相同的结果
  • 我使用的是 mac(雪豹)并且防火墙已禁用
  • 我已经在完全不同的 mac(也是雪豹)上进行了尝试,结果相同。
  • 我正在使用最新版本的 cucumber、rspec 和 spork。
  • 我也设置了黄瓜叉,但同样失败了。

如您所见,我一直在努力解决这个问题。我的项目使用了很多 gem,而没有 spork 会使测试变得非常非常糟糕。请帮忙...

更新

这是我的spec_helper

require 'spork'

Spork.prefork do
  ENV["RAILS_ENV"] ||= 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require "email_spec"
  require 'webmock/rspec'
  require 'vcr'
  require 'database_cleaner'

  include Devise::TestHelpers
  include EmailSpec::Helpers
  include EmailSpec::Matchers

  # Stub all updates to search indexes
  class Profile
    def update_tank_indexes ; end
    def delete_tank_indexes ; end
  end
  class Journal
    def update_tank_indexes ; end
  end

  # Apparently rspec doesn't understand <tt>main_app</tt> so stub it out.
  def main_app ; self ; end


  # 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|

    config.mock_with :rspec

    # 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
    config.extend VCR::RSpec::Macros

    # Always clean the database after running describe/context blocks to ensure a
    # consistent state. This is especially important when using the <tt>rspec-set</tt>
    # method. This method creates setup object once -- and only once -- proir to
    # running an entire describe/context block. In this way, it's similar to using
    # <tt>before(:all)</tt> except that <tt>set</tt> is better because:
    #
    #   * It automatically reloads the object before each example, making it much
    #     safer than before(:all) which can cause bugs if you're not careful.
    #   * It's lazily evaluated.
    #
    # You can read more at:
    #
    #   * eggsonbread.com/2010/05/25/speed-up-your-specs-with-set/
    #   * github.com/pcreux/rspec-set
    #
    # Note: This is not part of default configuration. Be sure to retain this snippet
    # when upgrading.
    #
    DatabaseCleaner.strategy = :truncation
    config.before(:all) do
      DatabaseCleaner.clean
    end
    config.after(:suite) do
      DatabaseCleaner.clean
    end
  end

end

Spork.each_run do
  # This code will be run each time you run your specs.
end

【问题讨论】:

  • 您好,也许您的 spec_helper 文件可以帮助我们朝着正确的方向前进?

标签: ruby-on-rails rspec cucumber spork drb


【解决方案1】:

我为此问题开了一张票,但在过去 3.5 个月内没有任何结果:https://github.com/sporkrb/spork/issues/133

更新:我找到了解决方案,并向那张票报告了一切。 tl;dr:将“always_validate_ssl_certifitcates”的 Gemfile 条目更改为包含 :require =&gt; false

【讨论】:

  • 嘿嘿嘿,调试了好久,终于搞明白了!你可以在上面链接的票上阅读完整的故事,但简短的版本是:从你的 Gemfile 中删除“always_verify_ssl_certificates”。固定。
  • indirect 做了一些很棒的工作来解决这个问题。我还在他上面提到的同一张票上发布了我的想法/修复。如果您遇到此错误,请查看该票证。您可能会找到解决方案。
【解决方案2】:

你能回滚到 spork 0.8.5 看看它是否有效吗?我刚刚验证了它的工作原理。

【讨论】:

  • 你会回答很有趣。在寻找替代解决方案(“spork is a bandaid”)时,我正在观看您的演讲。我尝试回滚到 0.8.5,没有运气。我一定是做了什么把事情搞砸了,因为这似乎不是一个常见的问题。无论如何,升级到 1.9.3 确实在一定程度上加快了启动时间。展望未来,肯定会按照您的建议考虑混入 PORO。在此期间您有什么建议:specjour?并行测试?还有什么?
猜你喜欢
  • 2012-02-21
  • 1970-01-01
  • 2011-04-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-31
相关资源
最近更新 更多