在使用 Rails 5 和 acts-as-taggable-on 时不能 运行 rspec 4

Can't run rspec when using Rails 5 and acts-as-taggable-on 4

版本

宝石文件

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

逻辑

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

异常

当 运行 rpsec 时,出现以下错误:

/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

如何解决?

你的文件名不正确,你有

lib/acts_as_taggable_on/generic_parser.rb

如果 class 是 MyParser Rails 需要通过文件名映射到那个 class 应该是 my_parser.rb 因此它应该是

lib/acts_as_taggable_on/my_parser.rb