Spec'ing the existence of #require

I looked through the mailing list archive but unfortunately my search
terms are too generic (spec and require…).

I am writing ruby code that runs under jruby in an embedded
environment. Periodically I will install new code that passes all
specs only to have it fail when it can’t find a new class I defined
(missing #require).

My spec_helper.rb file does a wildcard search and loads all rb files
in the tree, so it always picks up new files. Clearly I need to change
that and be more specific in my require lines.

Any suggestions on how to best accomplish this?

cr

Could you put a mocking expectation on Kernel? (which is where
#require is defined)

Kernel.should_receive(:require).with(expected_file_name)

On Aug 31, 2008, at 10:36 AM, Chuck R. wrote:

I looked through the mailing list archive but unfortunately my
search terms are too generic (spec and require…).

I am writing ruby code that runs under jruby in an embedded
environment. Periodically I will install new code that passes all
specs only to have it fail when it can’t find a new class I defined
(missing #require).

My spec_helper.rb file does a wildcard search and loads all rb files
in the tree,

Why? Why don’t you just have it load lib/your_project_name.rb, which
requires everything else?

Scott

On Aug 31, 2008, at 12:42 PM, Scott T. wrote:

My spec_helper.rb file does a wildcard search and loads all rb
files in the tree,

Why? Why don’t you just have it load lib/your_project_name.rb,
which requires everything else?

I don’t know. Is that the right way to do it? The way I am doing it
now mimics how the rspec gem includes all of the rspec files for
testing, so I took that as an accepted practice. I’ll be happy to try
your method if it doesn’t have a hidden gotcha too.

cr

On Aug 31, 2008, at 2:58 PM, David C. wrote:

terms are too generic (spec and require…).

are you thinking of when you say the gem includes all the files for
testing?

You are right. That is not what rspec does. I know I copied
this from some major gem that used rspec but now I can’t find it. I
retract what I said about rspec including everything (via the
spec_helper.rb).

I’ll try creating a single file that #requires everything I need and
see if that accomplishes all I need. Thanks for the tips.

cr

On Sun, Aug 31, 2008 at 2:38 PM, Chuck R. [email protected]
wrote:

Periodically I will install new code that passes all specs only to have it
fail when it can’t find a new class I defined (missing #require).

My spec_helper.rb file does a wildcard search and loads all rb files in
the tree,

Why? Why don’t you just have it load lib/your_project_name.rb, which
requires everything else?

I don’t know. Is that the right way to do it? The way I am doing it now
mimics how the rspec gem includes all of the rspec files for testing,

It does? What I see is that the spec files all include spec_helper.rb,
which, in turn, adds lib to the path and then requires ‘spec’. What
are you thinking of when you say the gem includes all the files for
testing?