Permalink
Browse files

Use Rails-recommended binstub for RSpec

Some Ruby gems provide an executable to run its contained Ruby program.
We most commonly use `rails`, `rspec`, and `rake`.

When we type `rspec` within the root of our project, Rubygems will use
the latest version of the RSpec gem, not the version specified in the
project's `Gemfile`. That's a problem that Bundler's `bundle exec`
solves.

It's tedious to type `bundle exec`, however. We previously solved that
problem via a directory convention for Bundler's binstubs and adding
that directory to our shell's `PATH`.

Running `bundle binstub rspec` generates a binstub file in the `bin`
directory. Running `./bin/rspec` is now the same thing as running
`bundle exec rspec`.

Adding `export PATH=".git/safe/../../bin:$PATH"` and running `mkdir
.git/safe` in the root of repositories you trust lets us just type
`rspec`, have the binstub be invoked, and therefore the correct version
of RSpec be used for the project.

rbenv/rbenv#309

We previously used `./bin/stubs` as our binstubs directory convention
and ignored the directory in version control. We used that convention
instead of `./bin` because we didn't want to gitignore the
already-existing `./bin` directory and we didn't want to replace the
critical `bin/rails`.

The community is moving towards a convention of using `./bin`:

* Rails is using `./bin` instead of `./script` starting with Rails 4.
* The default Bundler behavior is to use `./bin`.
  • Loading branch information...
1 parent 66a26d3 commit 87a471f9c14b0455a4f18742960cdd0edd998d21 @croaky croaky committed Sep 6, 2013
Showing with 7 additions and 2 deletions.
  1. +5 −0 lib/suspenders/app_builder.rb
  2. +2 −1 lib/suspenders/generators/app_generator.rb
  3. +0 −1 templates/suspenders_gitignore
@@ -134,6 +134,11 @@ def configure_rspec
copy_file 'spec_helper.rb', 'spec/spec_helper.rb'
end
+ def use_rspec_binstub
+ run 'bundle binstub rspec-core'
+ run 'rm bin/autospec'
+ end
+
def configure_background_jobs_for_rspec
copy_file 'background_jobs_rspec.rb', 'spec/support/background_jobs.rb'
run 'rails g delayed_job:active_record'
@@ -49,7 +49,7 @@ def remove_files_we_dont_need
def customize_gemfile
build :replace_gemfile
build :set_ruby_to_version_being_used
- bundle_command 'install --binstubs=bin/stubs'
+ bundle_command 'install'
end
def setup_database
@@ -76,6 +76,7 @@ def setup_test_environment
build :test_factories_first
build :generate_rspec
build :configure_rspec
+ build :use_rspec_binstub
build :configure_background_jobs_for_rspec
build :enable_database_cleaner
build :configure_capybara_webkit
@@ -4,7 +4,6 @@
*.swp
.bundle
.sass-cache/
-bin/stubs
coverage/*
db/*.sqlite3
db/schema.rb

0 comments on commit 87a471f

Please sign in to comment.