简体   繁体   English

Rails:Gemspec 无效。 请修复这个 gemspec

[英]Rails: Gemspec is not valid. Please fix this gemspec

When I install a gem from github it gives me the error:当我从 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

The gemspec is:宝石规格是:

# -*- 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

How can I fix that error?我该如何修复该错误?

The error seems out of sync with the gemspec you show, the error indicates the gem.descripton is invalid.该错误似乎与您显示的 gemspec 不同步,该错误表明gem.descripton无效。 According to the error, you are using the Gem from git, which has a commit fixing the invalid gem.description .根据错误,您正在使用来自 git 的 Gem,它有一个修复无效 gem.description提交

Have Bundler update to the latest number_internationalizer commit:让 Bundler 更新到最新的number_internationalizer提交:

bundle update

this answer is not for all situations but if you have sth like this in you blob.gemspec file:这个答案并不适用于所有情况,但如果你的blob.gemspec文件中有这样的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."

you should remove "TODO" word from it and also provide a valid HTTP URI for spec.homepage , you can just replace it like this:您应该从中删除“TODO”字样,并为spec.homepage提供一个有效的 HTTP URI,您可以像这样替换它:

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

I strongly feel there is a check for TODO or FIXME while the interpreter is parsing your gemspec.我强烈认为在解释器解析您的 gemspec 时会检查TODOFIXME This check has been programmed to throw an error if it sees any one of these two words.此检查已被编程为在看到这两个单词中的任何一个时抛出错误。 I had this same issue and I resolved it by removing any reference to TODO in my gemspec.我遇到了同样的问题,我通过删除 gemspec 中对 TODO 的任何引用来解决它。 I put a valid uri in the homepage session and everything started working fine again我在主页会话中放置了一个有效的 uri,一切又开始正常工作了

Just to add to Ashkan Nasirzadeh's answer .只是为了添加Ashkan Nasirzadeh 的回答

I had a similar when working with Rails Engines in a Rails 6.0.2.2 Application.在 Rails 6.0.2.2 应用程序中使用 Rails 引擎时,我有类似的情况。

The trick is to :诀窍是

  1. Remove every occurrence of TODO in the your_engine.gemspec file.删除your_engine.gemspec文件中出现的所有TODO
  2. Add a website of your choice in double-quotes to the spec.homepage .用双引号将您选择的网站添加到spec.homepage
  3. Ensure that you maintain the double quotes around the values where you removed every occurrence of TODO to avoid the undefined method of for main:Object error.确保在删除每次出现的TODO的值周围保留双引号,以避免undefined method of for main:Object错误的undefined method of for main:Object

Below is a sample your_engine.gemspec file that has been properly modified.下面是一个经过适当修改的示例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

That's all.就这样。

I hope this helps .我希望这会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM