Rails 测试无法正常工作
Posted
技术标签:
【中文标题】Rails 测试无法正常工作【英文标题】:Rails test will not work properly 【发布时间】:2017-01-24 04:55:12 【问题描述】:尝试在 railstutorial.org 上学习 Rails 教程。我目前处于教程的测试部分,并且在执行测试时不断出现错误。我使用“生成静态页面控制器”命令创建的测试文件原样,我根本没有修改它。当我输入命令“rails test”时,出现此错误:
/Users/user/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.1/lib/abstract_controller/helpers.rb:152:in `rescue in block in modules_for_helpers':缺少帮助文件帮助程序//users/user/programming/odin/rails/sample_app/app/helpers/application_helper.rb_helper.rb (AbstractController::Helpers::MissingHelperError)
这是追溯:
来自 /Users/user/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.1/lib/abstract_controller/helpers.rb:149:in
block in modules_for_helpers' from /Users/user/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.1/lib/abstract_controller/helpers.rb:145:in
map!' 来自 /Users/user/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.1/lib/abstract_controller/helpers.rb:145:inmodules_for_helpers' from /Users/user/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.1/lib/action_controller/metal/helpers.rb:93:in
modules_for_helpers' 来自 /Users/user/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.1/lib/abstract_controller/helpers.rb:109:inhelper' from /Users/user/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.1/lib/action_controller/railties/helpers.rb:17:in
inherited' 来自 /Users/user/.rvm/gems/ruby-2.3.0/gems/actionview-5.0.0.1/lib/action_view/test_case.rb:11:in<class:TestCase>' from /Users/user/.rvm/gems/ruby-2.3.0/gems/actionview-5.0.0.1/lib/action_view/test_case.rb:10:in
' 来自 /Users/user/.rvm/gems/ruby-2.3.0/gems/actionview-5.0.0.1/lib/action_view/test_case.rb:8:in<top (required)>' from /Users/user/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in
require' 来自 /Users/user/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:inblock in require' from /Users/user/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in
load_dependency' 来自 /Users/user/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:inrequire' from /Users/user/.rvm/gems/ruby-2.3.0/gems/rails-controller-testing-0.1.1/lib/rails-controller-testing.rb:16:in
block in ' 来自 /Users/user/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:38:ininstance_eval' from /Users/user/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:38:in
execute_hook' 来自 /Users/user/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:45:inblock in run_load_hooks' from /Users/user/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:44:in
each' 来自 /Users/user/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/lazy_load_hooks.rb:44:inrun_load_hooks' from /Users/user/.rvm/gems/ruby-2.3.0/gems/actionview-5.0.0.1/lib/action_view/base.rb:215:in
' 来自 /Users/user/.rvm/gems/ruby-2.3.0/gems/actionview-5.0.0.1/lib/action_view/base.rb:139:in<module:ActionView>' from /Users/user/.rvm/gems/ruby-2.3.0/gems/actionview-5.0.0.1/lib/action_view/base.rb:10:in
' 来自 /Users/user/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:inrequire' from /Users/user/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in
block in require' 来自 /Users/user/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:inload_dependency' from /Users/user/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in
require' 来自 /Users/user/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/debug_exceptions.rb:5:in<top (required)>' from /Users/user/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:in
require' 来自 /Users/user/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:inblock in require' from /Users/user/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:259:in
load_dependency' 来自 /Users/user/.rvm/gems/ruby-2.3.0/gems/activesupport-5.0.0.1/lib/active_support/dependencies.rb:293:inrequire' from /Users/user/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/application/default_middleware_stack.rb:48:in
block in build_stack' 来自 /Users/user/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/application/default_middleware_stack.rb:13:intap' from /Users/user/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/application/default_middleware_stack.rb:13:in
build_stack' 来自 /Users/user/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/application.rb:504:indefault_middleware_stack' from /Users/user/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/engine.rb:506:in
block in app' 来自 /Users/user/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/engine.rb:504:insynchronize' from /Users/user/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/engine.rb:504:in
app' 来自 /Users/user/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/application/finisher.rb:37:inblock in <module:Finisher>' from /Users/user/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:30:in
instance_exec' 来自 /Users/user/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:30:inrun' from /Users/user/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:55:in
block in run_initializers' 来自 /Users/user/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:228:inblock in tsort_each' from /Users/user/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:350:in
block (2 个级别) in each_strongly_connected_component' 来自 /Users/user/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:431:ineach_strongly_connected_component_from' from /Users/user/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:349:in
block in each_strongly_connected_component' 来自 /Users/user/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:347:ineach' from /Users/user/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:347:in
call' 来自 /Users/user/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:347:ineach_strongly_connected_component' from /Users/user/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:226:in
tsort_each' 来自 /Users/user/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/tsort.rb:205:intsort_each' from /Users/user/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/initializable.rb:54:in
run_initializers' 来自 /Users/user/.rvm/gems/ruby-2.3.0/gems/railties-5.0.0.1/lib/rails/application.rb:352:ininitialize!' from /Users/user/Programming/Odin/rails/sample_app/config/environment.rb:5:in
' 来自 /Users/user/.rvm/gems/ruby-2.3.0/gems/spring-1.7.2/lib/spring/application.rb:92:inrequire' from /Users/user/.rvm/gems/ruby-2.3.0/gems/spring-1.7.2/lib/spring/application.rb:92:in
preload' 来自 /Users/user/.rvm/gems/ruby-2.3.0/gems/spring-1.7.2/lib/spring/application.rb:143:inserve' from /Users/user/.rvm/gems/ruby-2.3.0/gems/spring-1.7.2/lib/spring/application.rb:131:in
block in run' 来自 /Users/user/.rvm/gems/ruby-2.3.0/gems/spring-1.7.2/lib/spring/application.rb:125:inloop' from /Users/user/.rvm/gems/ruby-2.3.0/gems/spring-1.7.2/lib/spring/application.rb:125:in
run' 来自 /Users/user/.rvm/gems/ruby-2.3.0/gems/spring-1.7.2/lib/spring/application/boot.rb:19:in<top (required)>' from /Users/user/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in
require' 来自 /Users/user/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:inrequire' from -e:1:in
'
如果这被格式化并询问不正确或者我没有道歉,任何帮助将不胜感激,我绝对难倒。 这是 github 仓库:https://github.com/JDjedi/sample_app
Rails 版本是 5.0,ruby 版本是 2.3.0p0
【问题讨论】:
【参考方案1】:application_helper.rb_helper.rb
- 你是这样称呼你的助手的吗? .rb
是一个扩展。因此,您能否将帮助文件的名称更改为application_helper.rb
,看看是否可行?
编辑:
你看过这个问题吗? Rails: AbstractController::Helpers::MissingHelperError - Missing helper file application_helper.rb_helper.rb
这似乎是一个可行的答案:https://***.com/a/28269245/1010826
只需将根文件夹重命名为相同的名称。不过不知道为什么会这样:)
【讨论】:
在目录中写为'application_helper.rb'。我将在原始帖子中提供对 github 存储库的扩展。 原谅我的无知,但我还是不明白以上是关于Rails 测试无法正常工作的主要内容,如果未能解决你的问题,请参考以下文章