【问题标题】:Rails: Gemspec is not valid. Please fix this gemspecRails:Gemspec 无效。请修复此 gemspec
【发布时间】:2012-10-24 16:50:40
【问题描述】:

当我从 github 安装 gem 时,它给了我错误:

number_internationalizer at /usr/local/rvm/gems/ruby-1.9.3-p194@number_internationalizer/bundler/gems/number_internationalizer-c0d642b04e87 did not have a valid gemspec.
This prevents bundler from installing bins or native extensions, but that may not affect its functionality.
The validation message from Rubygems was:
  "FIXME" or "TODO" is not a description

gemspec 是:

# -*- encoding: utf-8 -*-
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'number_internationalizer/version'

Gem::Specification.new do |gem|
  gem.name          = "number_internationalizer"
  gem.version       = NumberInternationalizer::VERSION
  gem.authors       = ["Myself"]
  gem.email         = ["myemail@email.com"]
  gem.description   = %q{Internationalize numbers adding normalization, validation and modifying the number field to restor the value to its original if validation fails}
  gem.summary       = gem.description
  gem.homepage      = ""

  gem.files         = `git ls-files`.split($/)
  gem.executables   = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
  gem.test_files    = gem.files.grep(%r{^(test|spec|features)/})
  gem.require_paths = ["lib"]
end

我该如何解决这个错误?

【问题讨论】:

  • 你是怎么解决这个问题的?我也有类似的!

标签: ruby-on-rails rubygems gemspecs


【解决方案1】:

错误似乎与您显示的 gemspec 不同步,错误表明 gem.descripton 无效。根据错误,您正在使用来自 git 的 Gem,它有一个 commit fixing the invalid gem.description

将 Bundler 更新到最新的number_internationalizer 提交:

bundle update

【讨论】:

  • 我这样做了,现在我在尝试运行rails s 时得到Could not find i18n-0.6.1 in any of the sources。我运行bundle show i18n,答案是/usr/local/rvm/gems/ruby-1.9.3-p194@number_internationalizer/gems/i18n-0.6.1。我不确定为什么会出现 @number_internationalizer
  • 我找到了新错误的解决方案。我以前用过rvm gemset use number_internationalizer。我不得不重置 rvm。
【解决方案2】:

这个答案并不适用于所有情况,但如果你有这样的blob.gemspec文件:

  spec.summary       = "TODO: Write a short summary, because Rubygems requires one."
  spec.homepage      = "TODO: Put your gem's website or public repo URL here."

你应该从中删除“TODO”字样,并为spec.homepage提供一个有效的HTTP URI,你可以像这样替换它:

  spec.summary       = "Write a short summary, because Rubygems requires one."
  spec.homepage      = "http://website.com"

【讨论】:

    【解决方案3】:

    我强烈认为在解释器解析您的 gemspec 时会检查 TODOFIXME。如果它看到这两个单词中的任何一个,此检查已被编程为抛出错误。我遇到了同样的问题,我通过删除我的 gemspec 中对 TODO 的任何引用来解决它。我在主页会话中放了一个有效的 uri,一切又开始正常工作了

    【讨论】:

    • TODO 更改为FARTbundle install 成功
    【解决方案4】:

    只是添加到Ashkan Nasirzadeh's answer

    在 Rails 6.0.2.2 应用程序中使用 Rails 引擎时,我也遇到过类似情况。

    诀窍是

    1. 删除your_engine.gemspec 文件中所有出现的TODO
    2. 用双引号将您选择的网站添加到spec.homepage
    3. 确保在删除了每次出现 TODO 的值周围使用双引号,以避免出现 undefined method of for main:Object 错误。

    以下是经过适当修改的示例your_engine.gemspec 文件。

    $:.push File.expand_path("lib", __dir__)
    
    # Maintain your gem's version:
    require "app_component/version"
    
    # Describe your gem and declare its dependencies:
    Gem::Specification.new do |spec|
      spec.name        = "app_component"
      spec.version     = AppComponent::VERSION
      spec.authors     = ["Promise Preston"]
      spec.email       = ["promise@gmail.com"]
      spec.homepage    = "http://website.com"
      spec.summary     = "Summary of AppComponent"
      spec.description = "Description of AppComponent"
      spec.license     = "MIT"
    
      # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
      # to allow pushing to a single host or delete this section to allow pushing to any host.
      if spec.respond_to?(:metadata)
        spec.metadata["allowed_push_host"] = "Set to 'http://mygemserver.com'"
      else
        raise "RubyGems 2.0 or newer is required to protect against " \
          "public gem pushes."
      end
    
      spec.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
    
      spec.add_dependency "rails", "~> 6.0.2", ">= 6.0.2.2"
    
      spec.add_development_dependency "sqlite3"
    end
    

    就是这样。

    我希望这会有所帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-09
      • 2019-12-28
      • 1970-01-01
      相关资源
      最近更新 更多