A bit of a puzzler - I've got an app using a very simple gem I wrote (UIAvatars) to generate a URL to an Avatar API. This demonstrably working in my Development rails app (the Avatar is displayed with no issues) but when I try to run my controller tests it causes errors like so:
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>'
The method in profiles_helper is:
def profile_image_link_for(profile, **options)
image_tag(
UIAvatars.generateURL(name: profile.full_name, size: "128", background: "random"),
options
).html_safe
end
bundle says it is installed:
% 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
it's in my Gemfile in the default group
gem 'ui_avatars'
Any idea what could be causing this problem?
Answer is that
.ruby-version
had a different version of ruby (2.6.7) than I was actually using (2.6.6) and so ruby could not find the gem installed in the expected path when running minitest.(why it still worked in rails is a question for another day).