Programming Ruby 3.2 (5th Edition): B1.0 page 269, cd gems/aaagmnr


page 269, running rspec

These tests pass (after you update the .gemspec file):

$ rspec spec/aaagmnr/options_spec.rb

It would be worth to explicitly mention to cd to code/gems/aaagmnr before running the test. As I work in code, I had an error :

% rspec -fd gems/aaagmnr/spec/aaagmnr/options_spec.rb

An error occurred while loading ./gems/aaagmnr/spec/aaagmnr/options_spec.rb.
    RSpec.describe Options do
  uninitialized constant Aaagmnr::Options
0 examples, 0 failures, 1 error occurred outside of examples

I was able to solve it by adding

require_relative '../../lib/aaagmnr'

in options_spec.rb, but it’s not what you have planned.

The trick is that if we are in code/gems/aaagmnr, RSpec can silently load .rspec

--format documentation
--require spec_helper

which requires spec/spec_helper.rb. Thanks to require "aaagmnr" in spec_helper, all the required files are loaded.
Without this infrastructure in code/gems/aaagmnr, for example if I delete .rspec or spec_helper.rb, nothing works :

% rspec spec/aaagmnr/options_spec.rb
Resolving dependencies...

An error occurred while loading spec_helper.
Failure/Error: __send__(method, file)

  cannot load such file -- spec_helper