0
0
Ruby on Railsframework~20 mins

Gemfile and dependency management in Ruby on Rails - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Gemfile Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when you run bundle install with a Gemfile.lock present?

You have a Gemfile and a Gemfile.lock in your Rails project. You run bundle install. What does Bundler do?

AIt ignores <code>Gemfile.lock</code> and installs the latest versions allowed by <code>Gemfile</code>.
BIt deletes <code>Gemfile.lock</code> and installs gems fresh from the internet.
CIt installs the exact gem versions listed in <code>Gemfile.lock</code>, ignoring version changes in <code>Gemfile</code>.
DIt only updates gems that are missing, leaving others untouched regardless of <code>Gemfile</code>.
Attempts:
2 left
💡 Hint

Think about how Bundler ensures consistent gem versions across machines.

📝 Syntax
intermediate
2:00remaining
Which Gemfile syntax correctly specifies a gem only for the development environment?

You want to add the gem pry only for development. Which Gemfile snippet is correct?

A
group :dev do
  gem 'pry'
end
Bgem 'pry', group: :development
Cgem 'pry', only: :development
D
group :development do
  gem 'pry'
end
Attempts:
2 left
💡 Hint

Remember the standard way to group gems by environment in Bundler.

🔧 Debug
advanced
2:00remaining
Why does bundle exec rails server fail with 'Could not find gem' error after adding a new gem?

You added a new gem to your Gemfile and ran bundle install. But running bundle exec rails server gives an error: 'Could not find gem ...'. What is the likely cause?

AYou did not run <code>bundle install</code> after adding the gem to Gemfile.
BYou added the gem but did not run <code>bundle update</code> to update Gemfile.lock.
CYou forgot to restart your terminal or shell session after installing the gem.
DYou installed the gem globally instead of using Bundler.
Attempts:
2 left
💡 Hint

Think about how Bundler uses Gemfile.lock to track installed gems.

🧠 Conceptual
advanced
2:00remaining
What is the purpose of the source line in a Gemfile?

In a Gemfile, you often see a line like source 'https://rubygems.org'. What does this line do?

AIt sets the environment variable for gem installation.
BIt tells Bundler where to fetch gems from when installing dependencies.
CIt defines the local path where gems are stored on your machine.
DIt specifies the Ruby version to use for the project.
Attempts:
2 left
💡 Hint

Think about where gems come from when you run bundle install.

state_output
expert
3:00remaining
What is the content of Gemfile.lock after running bundle install with this Gemfile?

Given this Gemfile:

source 'https://rubygems.org'
gem 'rails', '~> 7.0.0'
group :development do
  gem 'pry'
end

You run bundle install on a fresh project. What will Gemfile.lock contain regarding the pry gem?

Ruby on Rails
source 'https://rubygems.org'
gem 'rails', '~> 7.0.0'
group :development do
  gem 'pry'
end
A<p><code>pry</code> and its dependencies are listed under the <code>development</code> group section in <code>Gemfile.lock</code>.</p>
B<p><code>pry</code> is listed under the <code>default</code> group in <code>Gemfile.lock</code>.</p>
C<p><code>pry</code> is not listed anywhere in <code>Gemfile.lock</code> because it's only for development.</p>
D<p><code>pry</code> is listed but without any group information in <code>Gemfile.lock</code>.</p>
Attempts:
2 left
💡 Hint

Consider how Bundler groups gems in the lockfile.