rspec-expectations is the gem that adds should
to every object. Requiring rspec
loads only the rspec meta gem (which exists purely to be a single gem install
that provides all of rspec), but does not automatically load rspec-expectations. rspec-core allows you to configure it to use something besides rspec-expectations if you wish (such as the stdlib assertions provided by minitest, or wrong), but it loads rspec-expectations by default. To achieve this, if you do not explicitly configure it, it waits to load rspec-expectations until the first describe
call, for historical reasons, as explained in my blog post.
So, if you want to make Object#should
immediately available, you simply need to require rspec/expectations
. Note that we plan to change the default in RSpec 4 so that should
is not automatically available without extra config. Also, as @JonRowe mentioned, this usage isn't really the intended usage. You can call foo.should
from any context, but the matcher methods that are meant to work with should
are not available in all contexts. You'll need to include RSpec::Matchers
into your context to make them available. Consider also switching to the expect
syntax: it's a newer, non-monkeypatching syntax we've been recommending for a while now.