RSpec (2.12.2) gives me a hard time. If I want to refer to a class in one of my specifications, and this class is not in the root directory of my /lib , it throws an error:
no such file to load
It looks like my specifications can be nested in a folder structure, but the moment I try and require a class that is in a subfolder (e.g. lib/workers/conversion_worker.rb ), I get this error.
I use require 'spec_helper' in all my specifications, but even hard-coded the path in which the classes lead to the same error.
With this structure:
-lib/ - class_found.rb - workers/ - class_not_found.rb
The spectrum is as follows:
# spec/workers/class_not_found_spec.rb require "spec_helper" require "class_not_found" describe ClassNotFound do it "Does something" end
As a result, the specification starts successfully (the -I flag adds the path to $ LOAD_PATH):
$ rspec spec/workers/class_not_found_spec.rb -I /Path/to/project/*
So it looks like RSpec is not adding anything below lib to its path.
I can successfully execute class_not_found.rb using require_relative:
require_relative "../../lib/workers/class_not_found.rb"
But do not use require:
require "lib/workers/class_not_found.rb"
source share