Skip to content

Fix "uninitialized constant Gem" and other Travis errors #1914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 15, 2017

Conversation

mattbrictson
Copy link
Contributor

@mattbrictson mattbrictson commented Nov 14, 2017

The Travis builds have been failing for the past couple weeks. This PR makes them green again ✅

It seems that the trigger for the failures was the recent release of Bundler 1.16.0, which brings some subtly different behavior regarding environment variables and binstubs. Here are the changes I made in this PR to get Travis working:

  1. Fix a RuboCop violation that snuck in with Fix Ruby warning: character class has duplicated range #1913.
  2. Add bundler to the list of binstubs that we explicitly generate when creating the test Rails app. The bin/bundle binstub that ships as part of rails new is in the pre-1.16 format, and conflicts with the 1.16 format binstubs that are generated for rake and rspec (see 1.16.0 is intercepting binstub arguments and throwing 'unknown switches' error rubygems/bundler#6149). Fix this by replacing the default bin/bundle with a fresh one generated by bundle binstubs bundler --force.
  3. The Bundle.with_clean_env wrapper seems to remove some important information from the environment that causes binstubs to fail with errors like uninitialized constant Gem (NameError). Fix this by using Bundle.with_original_env instead (which is what the Bundler documentation recommends). Because Travis also sets its own BUNDLER_GEMFILE variable, I had to also reset that one manually.
  4. The RAILS_VERSION variable was not being parsed correctly, causing incorrect Cucumber tags to be used. Fixed by using a regex to extract the version number.
  5. Part of the Travis script runs bin/yard doc. This was failing because gems where missing. Fix by removing --without documentation from the bundler command.

Along the way I also added --no-rc to the sample app setup command to fix conflicts in my local development environment.

@JonRowe
Copy link
Member

JonRowe commented Nov 15, 2017

❤️

@mattbrictson
Copy link
Contributor Author

Getting close! 🤞

This commit fixes Travis failures due to the recent introduction of
Bundler 1.16.0. Both are related to the new style of binstubs that are
generated by 1.16.0.

First, add `bundler` to the list of binstubs that we explicitly generate
when creating the test Rails app. The `bin/bundle` binstub that ships as
part of `rails new` is in the pre-1.16 format, and conflicts with the
1.16 format binstubs that are generated for rake and rspec. Fix this by
replacing the default `bin/bundle` with a fresh one generated by
`bundle binstubs bundler --force`.

Second, the `Bundle.with_clean_env` wrapper seems to remove some
important information from the environment that causes binstubs to fail
with errors like `uninitialized constant Gem (NameError)`. Fix this by
using `Bundle.with_original_env` instead (which is what the Bundler
documentation recommends). Because Travis also sets its own
`BUNDLER_GEMFILE` variable, I had to also reset that one manually.
The rspec-rails acceptance tests use `rails new` to generate a sample
app for running tests. If a developer running the rspec-rails test suite
has a `.railsrc` file, this will affect the app that is generated,
causing specs to fail.

This commit fixes this by passing the `--no-rc` flag so that `rails new`
ignores the developer's local `.railsrc`.
@mattbrictson mattbrictson changed the title [WIP] Fix "uninitialized constant Gem" Travis errors Fix "uninitialized constant Gem" Travis errors Nov 15, 2017
@mattbrictson mattbrictson changed the title Fix "uninitialized constant Gem" Travis errors Fix "uninitialized constant Gem" and other Travis errors Nov 15, 2017
@JonRowe JonRowe merged commit e9949e7 into rspec:master Nov 15, 2017
@JonRowe
Copy link
Member

JonRowe commented Nov 15, 2017

Zomg amazing :) Thanks! ❤️

@mattbrictson mattbrictson deleted the fix-travis-failures branch November 15, 2017 22:43
JonRowe pushed a commit that referenced this pull request Nov 20, 2017
* Fix RuboCop violation

* Update test harness for Bundler 1.16 compatibility

This commit fixes Travis failures due to the recent introduction of
Bundler 1.16.0. Both are related to the new style of binstubs that are
generated by 1.16.0.

First, add `bundler` to the list of binstubs that we explicitly generate
when creating the test Rails app. The `bin/bundle` binstub that ships as
part of `rails new` is in the pre-1.16 format, and conflicts with the
1.16 format binstubs that are generated for rake and rspec. Fix this by
replacing the default `bin/bundle` with a fresh one generated by
`bundle binstubs bundler --force`.

Second, the `Bundle.with_clean_env` wrapper seems to remove some
important information from the environment that causes binstubs to fail
with errors like `uninitialized constant Gem (NameError)`. Fix this by
using `Bundle.with_original_env` instead (which is what the Bundler
documentation recommends). Because Travis also sets its own
`BUNDLER_GEMFILE` variable, I had to also reset that one manually.

* Choose cuke tags based on correct RAILS_VERSION

* Travis needs doc gems in order to run bin/yard

* Add --no-rc flag for more reliable local testing

The rspec-rails acceptance tests use `rails new` to generate a sample
app for running tests. If a developer running the rspec-rails test suite
has a `.railsrc` file, this will affect the app that is generated,
causing specs to fail.

This commit fixes this by passing the `--no-rc` flag so that `rails new`
ignores the developer's local `.railsrc`.
sebjacobs pushed a commit to futurelearn/rspec-rails that referenced this pull request Mar 15, 2019
* Fix RuboCop violation

* Update test harness for Bundler 1.16 compatibility

This commit fixes Travis failures due to the recent introduction of
Bundler 1.16.0. Both are related to the new style of binstubs that are
generated by 1.16.0.

First, add `bundler` to the list of binstubs that we explicitly generate
when creating the test Rails app. The `bin/bundle` binstub that ships as
part of `rails new` is in the pre-1.16 format, and conflicts with the
1.16 format binstubs that are generated for rake and rspec. Fix this by
replacing the default `bin/bundle` with a fresh one generated by
`bundle binstubs bundler --force`.

Second, the `Bundle.with_clean_env` wrapper seems to remove some
important information from the environment that causes binstubs to fail
with errors like `uninitialized constant Gem (NameError)`. Fix this by
using `Bundle.with_original_env` instead (which is what the Bundler
documentation recommends). Because Travis also sets its own
`BUNDLER_GEMFILE` variable, I had to also reset that one manually.

* Choose cuke tags based on correct RAILS_VERSION

* Travis needs doc gems in order to run bin/yard

* Add --no-rc flag for more reliable local testing

The rspec-rails acceptance tests use `rails new` to generate a sample
app for running tests. If a developer running the rspec-rails test suite
has a `.railsrc` file, this will affect the app that is generated,
causing specs to fail.

This commit fixes this by passing the `--no-rc` flag so that `rails new`
ignores the developer's local `.railsrc`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants