Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9197917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:10:42+00:00 2026-06-17T22:10:42+00:00

RSpec (2.12.2) is giving me a hard time. If I want to reference a

  • 0

RSpec (2.12.2) is giving me a hard time. If I want to reference a class in one of my specs and that class is not in the root of my /lib directory, it throws an error:

no such file to load -- test (LoadError)

It seems that my specs can be nested in a folder structure, but the moment I try and require a class that is in a nested folder (for example lib/workers/conversion_worker.rb), I get this error.

I am using require ‘spec_helper’ in all my specs, but even hard-coding the path the classes results in the same error.

With this structure:

-lib/
  - class_found.rb
  - workers/
     - class_not_found.rb

The spec looks like this:

# spec/workers/class_not_found_spec.rb
require "spec_helper"
require "class_not_found"

describe ClassNotFound do    
  it "Does something"
end

The following runs the spec successfully (the -I flag adds a path to the $LOAD_PATH):

$ rspec spec/workers/class_not_found_spec.rb -I /Path/to/project/*

So it seems that RSpec isn’t adding anything below lib to its path.

I can successfully require class_not_found.rb using require_relative:

require_relative "../../lib/workers/class_not_found.rb" #Succeeds

But not using require:

require "lib/workers/class_not_found.rb" # Fails
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:10:43+00:00Added an answer on June 17, 2026 at 10:10 pm

    I don’t know if you have an answer you like yet, but it seems like you aren’t requiring your files correctly.

    Your 'lib/class_found.rb' file should require all your library files, so it should look something like:

    require 'workers/class_not_found'
    

    and your spec_helper.rb will require the main file in your lib folder, so it should look something like:

    require 'class_found'
    

    rspec automatically loads 'spec/spec_helper.rb' when it runs, it also automatically adds the 'lib' folder to its LOAD_PATH, so that your requires in 'lib/class_found.rb' are seen and required properly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using RSpec, I want to test that certain methods are called within a method.
I get this RSpec error when I try to embed one document in another.
In some Rspec model specs, we have several tests like this: it { should
Running rspec for the first time with the Rails tutorial, p. 95. Getting this
I am new to rspec and wanted to ask how one would go about
Im trying to implement rspec for a http call... But I have not succeeded
In rspec (1.2.9), what is the correct way to specify that an object will
I have an rspec scenario that looks like: scenario some description of the scenario,
I try to learn Rspec , but I don't understand what is that. Let
Rspec book says to run cucumber features -n command. But it is giving following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.