Skip to content

Commit e941214

Browse files
mattbrictsonJonRowe
authored andcommitted
Fix "uninitialized constant Gem" and other Travis errors (#1914)
* 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`.
1 parent 301a95e commit e941214

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ sudo: false
2020
# original `cache: bundler` is a better option.
2121
cache: bundler
2222

23-
bundler_args: "--binstubs --without documentation --path ../bundle --retry=3 --jobs=3"
23+
bundler_args: "--binstubs --path ../bundle --retry=3 --jobs=3"
2424

2525
before_install:
2626
- script/clone_all_rspec_repos

Rakefile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ RSpec::Core::RakeTask.new(:spec) do |t|
2727
end
2828

2929
Cucumber::Rake::Task.new(:cucumber) do |t|
30-
version = ENV.fetch("RAILS_VERSION", "~> 4.2.0")
30+
version = ENV.fetch("RAILS_VERSION", "~> 4.2.0")[/\d[\.-]\d/]
3131
tags = []
3232

3333
if version.to_f >= 5.1
@@ -60,12 +60,12 @@ namespace :generate do
6060

6161
# Rails 4 cannot use a `rails` binstub generated by Bundler
6262
sh "rm -f #{bindir}/rails"
63-
sh "bundle exec rails new ./tmp/example_app --skip-javascript --skip-sprockets --skip-git --skip-test-unit --skip-listen --skip-bundle --template=example_app_generator/generate_app.rb"
63+
sh "bundle exec rails new ./tmp/example_app --no-rc --skip-javascript --skip-sprockets --skip-git --skip-test-unit --skip-listen --skip-bundle --template=example_app_generator/generate_app.rb"
6464

6565
in_example_app do
6666
sh "./travis_retry_bundle_install.sh 2>&1"
6767
# Rails 4 cannot use a `rails` binstub generated by Bundler
68-
sh "bundle binstubs rspec-core rake --force"
68+
sh "bundle binstubs bundler rspec-core rake --force"
6969
sh "bundle binstubs railties" unless File.exist?("bin/rails")
7070

7171
application_file = File.read("config/application.rb")
@@ -93,7 +93,8 @@ def in_example_app(*command_opts)
9393
app_dir = opts.fetch(:app_dir, app_dir)
9494
end
9595
Dir.chdir(app_dir) do
96-
Bundler.with_clean_env do
96+
Bundler.with_original_env do
97+
ENV["BUNDLE_GEMFILE"] = "Gemfile"
9798
sh *command_opts unless command_opts.empty?
9899
yield if block_given?
99100
end
@@ -182,12 +183,12 @@ namespace :no_active_record do
182183

183184
# Rails 4 cannot use a `rails` binstub generated by Bundler
184185
sh "rm -f #{bindir}/rails"
185-
sh "bundle exec rails new #{example_app_dir} --skip-active-record --skip-javascript --skip-sprockets --skip-git --skip-test-unit --skip-listen --skip-bundle --template=example_app_generator/generate_app.rb"
186+
sh "bundle exec rails new #{example_app_dir} --no-rc --skip-active-record --skip-javascript --skip-sprockets --skip-git --skip-test-unit --skip-listen --skip-bundle --template=example_app_generator/generate_app.rb"
186187

187188
in_example_app(:app_dir => example_app_dir) do
188189
sh "./travis_retry_bundle_install.sh 2>&1"
189190
# Rails 4 cannot use a `rails` binstub generated by Bundler
190-
sh "bundle binstubs rspec-core rake --force"
191+
sh "bundle binstubs bundler rspec-core rake --force"
191192
sh "bundle binstubs railties" unless File.exist?("bin/rails")
192193

193194
application_file = File.read("config/application.rb")

lib/rspec/rails/example/system_example_group.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def app
4949
dependency on a webserver and `capybara`, please add capybara to
5050
your Gemfile and configure a webserver (e.g. `Capybara.server =
5151
:webrick`) before attempting to use system tests.
52-
""".gsub(/\s+/,' ').strip
52+
""".gsub(/\s+/, ' ').strip
5353
end
5454

5555
original_after_teardown =

0 commit comments

Comments
 (0)