Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Don't package test files with gem #3207

Merged
merged 1 commit into from
Oct 8, 2014
Merged

Don't package test files with gem #3207

merged 1 commit into from
Oct 8, 2014

Conversation

sferik
Copy link
Member

@sferik sferik commented Oct 8, 2014

I just 🚢 a new version of the rails_admin gem and it took longer to push than I expected. Upon investigating, I realized that was because the gem had grown to 8.1 MB:exclamation: Digging deeper, I was astonished to realize that all but 229 KB were tests! This means that hundreds of thousands of people were downloading a file 36X bigger than necessary to get tests they would almost certainly never run.

This may be an extreme example, as RailsAdmin embeds a full Rails app in the spec directory in order to mount itself as a Rails engine. That said, this problem affects almost every gem, albeit to a lesser extent, and I can’t think of a good reason why any gem should package its tests.

Back in the day, there was a service called Gem Testers (originally at gem-testers.org and eventually at test.rubygems.org) and a corresponding rubygems-test gem that automatically ran the test suite of a every gem on install, however, this service never gained traction and is now offline.

If someone wants to run the tests for a particular gem, they can easily find the source code at the project’s homepage. Ninety-nine percent of the time, when someone installs a gem it’s because they want to execute the code, not the tests. I believe changing this default will improve the health of the RubyGems ecosystem and the Ruby community. If everyone adopts this change, bundle install will be significantly faster, especially in places where bandwidth is constrained (e.g. in hotels, at conferences, on airplanes, when tethered to a 3G connection, and in much of the developing world).

This patch excludes test files from the bundle gem template as well as from Bundler’s own gemspec.

@GeekOnCoffee
Copy link
Contributor

I notice Rails uses examples, is that another one that should be excluded?

@hone
Copy link
Contributor

hone commented Oct 8, 2014

Off the top of my head, I'm 👍 this.

@parndt
Copy link
Contributor

parndt commented Oct 8, 2014

👍 I'm all for smaller gems.. I've had some terrible Internet connections this year and bundling has been painful

@simi
Copy link
Member

simi commented Oct 8, 2014

all in

there should be only code in gems, no docs, tests, etc...

@sferik
Copy link
Member Author

sferik commented Oct 8, 2014

@simi To be clear, this patch says nothing about documentation, only tests. I think there’s a good case to be made for packaging documentation, even if that documentation is also available online.

@GeekOnCoffee Rails examples are more like documentation than executable tests. Even if we wanted to exclude such code from gems, this patch is not intended to be comprehensive, just to be a better default. People obviously can (and will, and should) edit their gemspecs after they are generated by Bundler.

@simi
Copy link
Member

simi commented Oct 8, 2014

I was thinking about separated docs packages. Something similar to gem install --no-ri --no-rdoc. Docs should be installed (and generated) only when you need them (probably default to true). But there's a lot of cases where you don't need them (servers). Good example of this is pure rails gem (1,4MB of guides).

Maybe time to move this idea to mail-list.

@indirect
Copy link
Member

indirect commented Oct 8, 2014

Given the prevailing climate of every gem's source being on github (rather than vanishing as individual websites go down or expire), I think this makes sense. It also helps with situations like Bundler itself, where the tests only pass if run from the git repo.

@sferik
Copy link
Member Author

sferik commented Oct 8, 2014

Cool. Thanks for the feedback.

sferik added a commit that referenced this pull request Oct 8, 2014
Don't package test files with gem
@sferik sferik merged commit a36485d into master Oct 8, 2014
@hone hone deleted the test_files branch October 8, 2014 15:45
sferik referenced this pull request in collectiveidea/delayed_job Oct 9, 2014
sferik referenced this pull request in omniauth/omniauth Oct 16, 2014
yujinakayama added a commit to yujinakayama/transpec that referenced this pull request Dec 13, 2014
iainbeeston added a commit to voxpupuli/json-schema that referenced this pull request Feb 28, 2015
Should reduce the size of the gem. The default for new gems (created by bundler) is not to include test files. See rubygems/bundler#3207
michaelherold added a commit to michaelherold/omniauth-eventbrite that referenced this pull request Apr 28, 2015
See [this issue on the Bundler repository][issue3207] for reasoning.

Basically the test files are available on at the gem's site (Github) and
aren't needed for executing the code. If you want to hack on the gem,
get it with git.

[issue3207]: rubygems/bundler#3207
iainbeeston added a commit to iainbeeston/teaspoon that referenced this pull request Jul 2, 2015
I was just looking through the code installed for teaspoon, and I noticed that the /spec/dummy directory is huge. It turns out that rubygems is packaging up not only /spec/dummy, but also all the tempfiles and logfiles there *at the time of packaging*.

The latest consensus is that test_files shouldn't be packaged with a gem anyway (see rubygems/bundler#3207) because they're never used, so rather than filtering out /spec/dummy/log and /spec/dummy/tmp I've prevented rubygems from packing test files at all.
iainbeeston pushed a commit to iainbeeston/factory_girl that referenced this pull request Jan 18, 2016
Tests aren't useful for end users of the gem, and excluding them from
the gem them reduces the size of the download.

Since rubygems/bundler#3207 this has been the default for gems created
using `bundler gem`, and I've taken the code for excluding them from
there.
joshuaclayton pushed a commit to thoughtbot/factory_bot that referenced this pull request Feb 5, 2016
Tests aren't useful for end users of the gem, and excluding them from
the gem them reduces the size of the download.

Since rubygems/bundler#3207 this has been the default for gems created
using `bundler gem`, and I've taken the code for excluding them from
there.
teeparham added a commit to teeparham/google-api-ruby-client that referenced this pull request Apr 17, 2016
* Do not distribute test files
* Do not distribute the intermediate api_names_out.yaml file

> Reduces the packaged gem size from 1.8Mb to 1.6Mb

The practice of not distributing test files with a gem was originally
discussed and adopted by the Bundler team here:
rubygems/bundler#3207
JuanitoFatas added a commit to gjtorikian/html-pipeline that referenced this pull request Jul 1, 2016
JuanitoFatas added a commit to gjtorikian/html-pipeline that referenced this pull request Jul 2, 2016
JuanitoFatas added a commit to gjtorikian/html-pipeline that referenced this pull request Jul 3, 2016
@coilysiren coilysiren modified the milestone: Release Archive Oct 9, 2016
dmeremyanin added a commit to dmeremyanin/rpm that referenced this pull request May 16, 2017
It reduces the size of the gem by half, from 645K to 294K. The default
for new gems (created by bundler) is not to include test files. See
rubygems/bundler#3207
dmeremyanin added a commit to dmeremyanin/riddle that referenced this pull request May 16, 2017
It drastically reduces the size of the gem, from 1.9M to 32K. The
default for new gems (created by bundler) is not to include test files.
See rubygems/bundler#3207
newrelicbot pushed a commit to newrelic/newrelic-ruby-agent that referenced this pull request May 25, 2017
It reduces the size of the gem by half, from 645K to 294K. The default
for new gems (created by bundler) is not to include test files. See
rubygems/bundler#3207
mjankowski pushed a commit to thoughtbot/flutie that referenced this pull request Sep 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants