gpt4 book ai didi

ruby-on-rails - cucumber 在没有 spork 的情况下工作正常,但是 spork 给了我 "uninitialized constant Cucumber::Rails"

转载 作者:行者123 更新时间:2023-12-04 06:24:00 24 4
gpt4 key购买 nike

我现有的 rspecs 和 Cucumber 功能都运行良好。

我正在安装 spork(实际上是 spork-rails)以提高重新运行速度。

我有 spork 的 rspec 运行良好。

我刚刚按照说明修改了 env.rb(与 spec_helper.rb 的 mod 非常相似),但我得到了 uninitialized constant Cucumber::Rails当我尝试运行时 bundle exec cucubmer --drb .

顺便说一下,R​​ails 3.2

有任何想法吗?

这是我的 env.rb:

require 'rubygems'
require 'spork'
#uncomment the following line to use spork with the debugger
require 'spork/ext/ruby-debug'


if Spork.using_spork?
Spork.prefork do

require 'rails'
require 'cucumber/rails'

Capybara.default_selector = :css

begin
DatabaseCleaner.strategy = :transaction
rescue NameError
raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
end

end

Spork.each_run do
# This code will be run each time you run your specs.
require 'cucumber/rails'
Cucumber::Rails::Database.javascript_strategy = :truncation

ActionController::Base.allow_rescue = false


module NavigationHelpers
def path_to(page_name)
case page_name

when /the home page/
root_path
# Add more page name => path mappings here
else
if path = match_rails_path_for(page_name)
path
else
raise "Can't find mapping from \"#{page_name}\" to a path.\n" +
"Now, go and add a mapping in features/support/paths.rb"
end
end
end

def match_rails_path_for(page_name)
if page_name.match(/the (.*) page/)
return send "#{$1.gsub(" ", "_")}_path" rescue nil
end
end
end

World(NavigationHelpers)
end
else

#omitted
end

最佳答案

记下我为解决此问题所做的工作,以供将来引用。最后,我认为在 Gemfile 中稍微错误地引用了 cucumber rails 是一个奇怪的症状。

我也收到错误说:

WARNING: Cucumber-rails required outside of env.rb. 
The rest of loading is being defered until env.rb is called.
To avoid this warning, move 'gem cucumber-rails' under only
group :test in your Gemfile

按照 https://github.com/cucumber/cucumber/issues/249 中的说明进行操作,我通过在我的 Gemfile 中添加 require: false 来解决这个问题,如下所示:

group :test do
gem 'cucumber-rails', require:false
#....
end

关于ruby-on-rails - cucumber 在没有 spork 的情况下工作正常,但是 spork 给了我 "uninitialized constant Cucumber::Rails",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10783871/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com