rubygems / rfcs

RubyGems + Bundler RFCs
45 stars 40 forks source link

Skip gemspec validations in gem development #16

Closed skalee closed 5 years ago

skalee commented 5 years ago

When I creating a new gem with Bundler, the autogenerated gemspec is not valid. It is generally expected and correct, however it prevents gem from being loaded in development.

Actual behaviour

Given freshly created gem named "store":

$ bundle gem store --test=rspec

When I run specs with:

$ bundle exec rspec

Then it crashes without running any test, printing following message:

Gem::InvalidSpecificationException: The gemspec at <path>/store/store.gemspec is not valid. Please fix this gemspec.
The validation error was 'metadata['homepage_uri'] has invalid link: "TODO: Put your gem's website or public repo URL here."'

Also, when I load IRB console:

$ bin/console

It crashes with following output:

Gem::InvalidSpecificationException: The gemspec at <path>/store/store.gemspec is not valid. Please fix this gemspec.
The validation error was 'metadata['homepage_uri'] has invalid link: "TODO: Put your gem's website or public repo URL here."'

This issue is not limited to homepage_uri metadata. More values are invalid.

Expected behaviour

No matter if all attributes in gemspec have valid values or not, bin/console launches IRB session, and bundle exec rspec runs tests. Moreover, yet another test is added to the autogenerated test suite, which succeeds if and only if gemspec is all valid.

Rationale

Gem validation is a good thing in general. However, in the first phases of development, I may be unwilling to fill in all the details. Possible reasons include:

Currently, Bundler requiers me to provide all the metadata in advance. But in fact, it actually encourages to either remove invalid entries, or to replace placeholders with gibberish which passes validations, "just for now". In my opinion, both are bad practices, which shouldn't be promoted.

Note that in Ruby Gems these validations can be overriden, as gem executable allows for building from invalid (but syntatically correct) gemspecs with --force option. Perhaps a similar option should be added to the Bundler.require and Bundler.setup methods, e.g.:

Bundler.require :default, :development, validate: false

The exact synopsis is to be defined though, I'm not proficient with Bundler's internals.

skalee commented 5 years ago

Alternatively, a --skip-gemspec-validation command line option could be added.

Pros: Gemfile is free of initial development setup. Preference to skip gemspec validation is local. Cons: This option must be somehow set in CI anyway. Hence, people will probably write it in .travis.yml etc, making this setting not local.

indirect commented 5 years ago

Thanks for the suggestion! If you are interested in having the team possibly accept this idea, please submit a pull request containing an RFC, as described in the readme for this repository.