Bird
0
0

Consider this command run inside a Ruby project folder:

medium📝 Debug Q14 of 15
Ruby - Gems and Bundler

Consider this command run inside a Ruby project folder:
rspec spec/test_spec.rb
The test fails due to a gem version conflict. How can you fix this using bundle exec?

ARun <code>gem install rspec</code> to update the gem globally
BRun <code>bundle exec rspec spec/test_spec.rb</code> to use project gems
CRun <code>rspec --update</code> to fix conflicts automatically
DDelete the Gemfile and try again
Step-by-Step Solution
Solution:
  1. Step 1: Identify cause of failure

    Failure is due to gem version conflict between global and project gems.
  2. Step 2: Use bundle exec to isolate gems

    Running bundle exec rspec spec/test_spec.rb forces use of project Gemfile gems, resolving conflicts.
  3. Final Answer:

    Run bundle exec rspec spec/test_spec.rb to use project gems -> Option B
  4. Quick Check:

    bundle exec fixes gem conflicts = A [OK]
Quick Trick: Use bundle exec before commands to fix gem conflicts [OK]
Common Mistakes:
  • Trying to update gems globally instead of isolating
  • Using invalid rspec options
  • Deleting Gemfile which breaks project setup

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes