Ruby rspec——drb不使用Spork处理rspec
在完成Michael Hartl的优秀Rails教程后,我决定尝试使用Autotest和Spork来加速我的测试。一切似乎都安装正确,但当我遇到最后一个障碍(使用--drb标志运行rspec)时,我遇到了以下错误:Ruby rspec——drb不使用Spork处理rspec,ruby,ruby-on-rails-3,railstutorial.org,autotest,spork,Ruby,Ruby On Rails 3,Railstutorial.org,Autotest,Spork,在完成Michael Hartl的优秀Rails教程后,我决定尝试使用Autotest和Spork来加速我的测试。一切似乎都安装正确,但当我遇到最后一个障碍(使用--drb标志运行rspec)时,我遇到了以下错误: $ rspec --drb spec/ ***************************************************************** DEPRECATION WARNING: you are using a deprecated constant
$ 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
编辑2:我更改了spec_helper.rb文件中的端点。我不认为我有一个额外的,因为有人建议,但我认为他们是在错误的地方,因为我的一部分穷人缩进。生成的文件(删除了所有注释)如下所示:
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
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,因为我没有其他想法。非常感谢迄今为止提供的所有帮助 您正在使用较旧版本的Spork。您应该尝试升级到v0.9.2,看看是否有帮助。我知道我一直忘记了
bundle exec rspec--在另一个选项卡中运行spork后,drb
。这为我消除了任何奇怪的警告。也许这是针对谷歌的。请参阅lx00st的答案,引用:
原因是RSpec::Core::CommandLine在Rspec3中被删除
将RSpec::Core::CommandLine(从未正式声明为public)合并到RSpec::Core::Runner中。(迈伦·马斯顿)
但是spork依赖于这个代码
spork的github上已经存在一个问题,可以在以下spork的fork中找到解决方案:
一般情况下-更换
::RSpec::Core::CommandLine.new(argv).run(stderr,stdout)
与
::RSpec::Core::Runner.run(argv、stderr、stdout)
在soprks源代码中
它对我来说工作得很好(尽管我怀疑SporkGem更新可能会删除源代码修复)。我刚刚用github建议的内容替换了内容“spork/test_framework/rspec.rb”:
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
要求“rspec/core/version”
类Spork::TestFramework::RSpec
您的spec/spec\u helper.rb是什么样子的?我刚刚将其添加到问题中。您的spec\u helper
中似乎有一个额外的不必要的end
。试着把它拿出来看看是否有用。恐怕不行。我已经解释了我在上面所做的。可能重复的请避免只链接的答案。如果您认为此链接有帮助,请将其放在问题的评论中。虽然此链接可以回答问题,但最好在此处包含答案的基本部分,并提供此链接以供参考。如果链接页面发生更改,仅链接的答案可能会无效。感谢您的反馈@Athimanil,希望答案现在状态更好。@Rorymcrossan,收到您的提示了。请注意,我无法评论最初的问题(没有足够的代表)。