Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Can you generate a binstub at bundle exec rspec?


Asked by Monica Randolph on Dec 11, 2021 FAQ



Optional: If bundle exec rspec is too verbose for you, you can generate a binstub at bin/rspec and use that instead: RSpec DSL Basics (or, how do I write a spec?) In RSpec, application behavior is described first in (almost) plain English, then again in test code, like so:
In addition,
Essentially, if you would normally have run something like rspec spec/my_spec.rb, and you want to use the gems specified in the Gemfile (5) and installed via bundle install (1), you should run bundle exec rspec spec/my_spec.rb. Note that bundle exec does not require that an executable is available on your shell's $PATH.
Similarly, Binstubs are a shortcut-or alternative- to always using bundle exec. This gives you a file that can be run directly, and one that will always run the correct gem version used by the application. For example, if you run bundle binstubs rspec-core, Bundler will create the file bin/rspec.
In this manner,
Binstubs are scripts that wrap around executables. Bundler creates a small Ruby file (a binstub) that loads Bundler, runs the command, and puts it into bin/. Binstubs are a shortcut-or alternative- to always using bundle exec.
Accordingly,
By default, when attempting to bundle exec to a file with a ruby shebang, Bundler will Kernel.load that file instead of using Kernel.exec. For the vast majority of cases, this is a performance improvement.