如何解决rails6 应用程序:minitest 失败,ActionView::Template::Error:未初始化的常量
有点令人困惑 - 我有一个应用程序,它使用我编写的一个非常简单的 gem (UIAvatars) 来生成一个指向 Avatar API 的 URL。这在我的 Development rails 应用程序中明显有效(Avatar 显示没有问题)但是当我尝试运行我的控制器测试时,它会导致如下错误:
Error:
InitiativesControllerTest#test_should_get_new:
ActionView::Template::Error: uninitialized constant ProfilesHelper::UIAvatars
app/helpers/profiles_helper.rb:17:in `profile_image_link_for'
app/views/layouts/_header.html.erb:62
app/views/layouts/application.html.erb:23
test/controllers/initiatives_controller_test.rb:15:in \`block in <class:InitiativesControllerTest>'
profiles_helper 中的方法是:
def profile_image_link_for(profile,**options)
image_tag(
UIAvatars.generateURL(name: profile.full_name,size: "128",background: "random"),options
).html_safe
end
bundle 说它已安装:
% bundle info ui_avatars
* ui_avatars (0.0.1)
Summary: Generate avatars with initials from names using https://ui-avatars.com
Homepage: https://rubygems.org/gems/ui_avatars
Path: /Users/thatsme/.rvm/gems/ruby-2.6.6/gems/ui_avatars-0.0.1
它在我的 Gemfile 中的默认组
gem 'ui_avatars'
知道是什么导致了这个问题吗?
解决方法
答案是 .ruby-version
的 ruby (2.6.7) 版本与我实际使用的 (2.6.6) 版本不同,因此 ruby 在运行 minitest 时找不到安装在预期路径中的 gem。
(为什么它仍然在 Rails 中工作是另一个问题)。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。