How do I get my Rails app\'s root directory path?
In some cases you may want the Rails root without having to load Rails.
For example, you get a quicker feedback cycle when TDD'ing models that do not depend on Rails by requiring spec_helper instead of rails_helper.
# spec/spec_helper.rb
require 'pathname'
rails_root = Pathname.new('..').expand_path(File.dirname(__FILE__))
[
rails_root.join('app', 'models'),
# Add your decorators, services, etc.
].each do |path|
$LOAD_PATH.unshift path.to_s
end
Which allows you to easily load Plain Old Ruby Objects from their spec files.
# spec/models/poro_spec.rb
require 'spec_helper'
require 'poro'
RSpec.describe ...