0

Versions

  • Ruby: 2.3.3
  • Bundler: 1.14.6
  • Rails: 5.0.2
  • acts-as-taggable-on: 4.0.0
  • Rspec: 3.5.4

Gemfile

gem 'rails', '~> 5.0.0', '>= 5.0.0.1'
gem 'acts-as-taggable-on', '~> 4.0'

group :development, :test do
  gem 'rspec-rails', '~> 3.5'
end

Logic

lib/acts_as_taggable_on/generic_parser.rb

class MyParser < ActsAsTaggableOn::GenericParser
  def parse
    ActsAsTaggableOn::TagList.new.tap do |tag_list|
      tag_list.add @tag_list.split(',').map(&:strip).reject(&:empty?)
    end
  end
end

Exception

When running rpsec, got these errors:

/Users/user/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/bundler-1.14.6/lib/bundler/runtime.rb:94:in `rescue in block (2 levels) in require': There was an error while trying to load the gem 'acts-as-taggable-on'. (Bundler::GemRequireError)
Gem Load Error is: uninitialized constant ActsAsTaggableOn::GenericParser

How to fix it?

Jingqiang Zhang
  • 1,039
  • 2
  • 13
  • 24
  • did you try with `gem update bundler` https://stackoverflow.com/questions/15060011/nameerror-uninitialized-constant-gemsourceindex#15937572 – Fabrizio Bertoglio Aug 30 '17 at 03:18
  • @FabrizioBertoglio Thank you for your comment. I tried `gem update bundler` just now. Now bundler version became `1.15.4`, but the same error happened when run `rspec`. – Jingqiang Zhang Aug 30 '17 at 03:21
  • ok what about upgrading to `gem 'acts-as-taggable-on', '~> 5.0'` and `gem 'bundler', '~> 1.15', '>= 1.15.4'` and `gem 'rspec', '~> 3.6'`? Sorry this is really a stupid advise, but you are using `rails 5` so why not use the latest versions of everything? maybe this problem was solved with the later versions? For the latest versions refer to https://rubygems.org/ – Fabrizio Bertoglio Aug 30 '17 at 03:39
  • @FabrizioBertoglio Your advise is a way. I used a logic includes `ActsAsTaggableOn::GenericParser` and I added the source to the question. Now I am trying to use another way to realize the same result then remove that source. And rspec works. Maybe that's the version problem between several gems. Thank you very much for your follow. – Jingqiang Zhang Aug 30 '17 at 03:59
  • Please provide full trace, not only exception. – Greg Aug 31 '17 at 06:48
  • also - how do you run your rspecs? Did you try `bundle exec rspec`? – Greg Aug 31 '17 at 06:49
  • @meta I have changed method and the error didn't happened. It must be a bug I think. I used `bundle exec rspec`, but not that problem. – Jingqiang Zhang Aug 31 '17 at 06:58

1 Answers1

1

Your file name is incorrect, you have

lib/acts_as_taggable_on/generic_parser.rb

If the class is MyParser Rails need to map to that class via the name of the file which should be my_parser.rb and thus it should be

lib/acts_as_taggable_on/my_parser.rb
Daniel
  • 14,004
  • 16
  • 96
  • 156