首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >rspec --drb不适用于带Spork的RSpec

rspec --drb不适用于带Spork的RSpec
EN

Stack Overflow用户
提问于 2012-08-14 19:55:10
回答 3查看 3.5K关注 0票数 1

在完成Michael Hartl的优秀的Rails教程后,我决定尝试使用Autotest和Spork来加速我的测试。一切似乎都安装正确,但当我遇到最后一个障碍(使用--drb标志运行rspec )时,我得到了以下错误:

代码语言:javascript
复制
$ rspec --drb spec/
*****************************************************************
DEPRECATION WARNING: you are using a deprecated constant that will
be removed from a future version of RSpec.

/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/lib/spork/run_strategy/forking.rb:13:in `run'

* Spec is deprecated.
* RSpec is the new top-level module in RSpec-2
*****************************************************************

Exception encountered: #<NameError: uninitialized constant RSpec::Runner::CommandLine>
backtrace:
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/lib/spork/test_framework/rspec.rb:6:in     `run_tests'
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/lib/spork/run_strategy/forking.rb:13:in `run'
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/lib/spork/forker.rb:21:in `initialize'
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/lib/spork/forker.rb:18:in `fork'
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/lib/spork/forker.rb:18:in `initialize'
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/lib/spork/run_strategy/forking.rb:9:in `new'
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/lib/spork/run_strategy/forking.rb:9:in `run'
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/lib/spork/server.rb:48:in `run'
/usr/lib/ruby/1.8/drb/drb.rb:1558:in `__send__'
/usr/lib/ruby/1.8/drb/drb.rb:1558:in `perform_without_block'
/usr/lib/ruby/1.8/drb/drb.rb:1518:in `perform'
/usr/lib/ruby/1.8/drb/drb.rb:1592:in `main_loop'
/usr/lib/ruby/1.8/drb/drb.rb:1588:in `loop'
/usr/lib/ruby/1.8/drb/drb.rb:1588:in `main_loop'
/usr/lib/ruby/1.8/drb/drb.rb:1584:in `start'
/usr/lib/ruby/1.8/drb/drb.rb:1584:in `main_loop'
/usr/lib/ruby/1.8/drb/drb.rb:1433:in `run'
/usr/lib/ruby/1.8/drb/drb.rb:1430:in `start'
/usr/lib/ruby/1.8/drb/drb.rb:1430:in `run'
/usr/lib/ruby/1.8/drb/drb.rb:1350:in `initialize'
/usr/lib/ruby/1.8/drb/drb.rb:1630:in `new'
/usr/lib/ruby/1.8/drb/drb.rb:1630:in `start_service'
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/lib/spork/server.rb:29:in `listen'
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/lib/spork/server.rb:20:in `run'
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/bin/../lib/spork/runner.rb:75:in `run'
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/bin/../lib/spork/runner.rb:10:in `run'
/usr/lib/ruby/gems/1.8/gems/spork-0.9.0.rc8/bin/spork:10
/usr/lib/ruby/gems/1.8/bin/spork:23:in `load'
/usr/lib/ruby/gems/1.8/bin/spork:23

如果我只需输入$ rspec spec/,测试就可以完美地工作,但是,当然,速度非常慢。所以看起来问题可能出在我对Spork做的一些事情上。我遵循了http://ruby.railstutorial.org/chapters/static-pages?version=3.0#sec:spork上的说明(我一开始就使用v3.0而不是v3.2 )。

请注意,我在Windows上运行Cygwin,这意味着我使用的是Rubyv1.8.7,而不是1.9.2+。我不知道这会不会有什么不同。

如果您对如何使用Spork (Autotest似乎还不错)有任何想法,我们将非常感激。

提前感谢!

抢夺

PS我的spec/spec_helper.rb如下所示:

代码语言:javascript
复制
require 'rubygems'
require 'spork'

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

    # 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

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

end

  def test_sign_in(user)
    controller.current_user = user
  end
end

编辑2:我更改了spec_helper.rb文件中的端点。我不认为我有一个额外的,但我认为他们在错误的地方,由于我的一部分不好的缩进。生成的文件(删除了所有注释)如下所示:

代码语言:javascript
复制
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 :rspec

    config.fixture_path = "#{::Rails.root}/spec/fixtures"

    config.use_transactional_fixtures = true

    config.infer_base_class_for_anonymous_controllers = false
  end
end

Spork.each_run do
end

def test_sign_in(user)
  controller.current_user = user
end

错误消息仍然相同。明天,如果有机会,我会尝试卸载Ruby v1.8.7,然后安装v1.9.2或3,因为没有其他想法。非常感谢到目前为止所提供的所有帮助!

EN

回答 3

Stack Overflow用户

发布于 2012-08-17 00:07:17

您使用的是较旧版本的Spork。您应该尝试升级到v0.9.2,看看这是否有帮助。

票数 2
EN

Stack Overflow用户

发布于 2012-09-10 22:09:03

我知道在另一个选项卡中运行了spork之后,我一直忘记了bundle exec rspec . --drb。对我来说,这消除了任何奇怪的警告。也许这是为谷歌准备的。

票数 1
EN

Stack Overflow用户

发布于 2014-08-10 20:30:53

参见lx00st对spork 0.9.2 and rspec 3.0.0 = uninitialized constant RSpec::Core::CommandLine (NameError)的回答,引用:

原因是在Rspec3 https://github.com/rspec/rspec-core/blob/master/Changelog.md中删除了RSpec::Core::CommandLine

将RSpec::Core::CommandLine (从未正式声明为public)合并到RSpec::Core::Runner中。(Myron Marston)

但是spork依赖于这个代码。

在spork的github上已经存在一个问题,可以在以下spork的fork中找到解决方案:

https://github.com/codecarson/spork/commit/38c79dcedb246daacbadb9f18d09f50cc837de51#diff-937afaa19ccfee172d722a05112a7c6fL6

一般情况下-替换

::RSpec::Core::CommandLine.new(argv).run(stderr,标准输出)

使用

::RSpec::Core::Runner.run(argv、stderr、stdout)

在soprks源代码中

它对我来说工作得很好(尽管我怀疑spork gem的更新可能会删除源代码修复)。我只是将内容'spork/test_framework/rspec.rb‘替换为来自github的建议内容:

代码语言:javascript
复制
require 'rspec/core/version'

class Spork::TestFramework::RSpec < Spork::TestFramework
  DEFAULT_PORT = 8989
  HELPER_FILE = File.join(Dir.pwd, "spec/spec_helper.rb")

  def run_tests(argv, stderr, stdout)
    if rspec1?
      ::Spec::Runner::CommandLine.run(
        ::Spec::Runner::OptionParser.parse(argv, stderr, stdout)
      )
    elsif rspec3?
      options = ::RSpec::Core::ConfigurationOptions.new(argv)
      ::RSpec::Core::Runner.new(options).run(stderr, stdout)
    else
      ::RSpec::Core::CommandLine.new(argv).run(stderr, stdout)
    end
  end

  def rspec3?
    return false if !defined?(::RSpec::Core::Version::STRING)
    ::RSpec::Core::Version::STRING =~ /^3\./
  end

  def rspec1?
    defined?(Spec) && !defined?(RSpec)
  end
end
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11951731

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档