Helps require files and manage the
$LOAD_PATH of unit tests which do not boot
For example in Rails if you want fast unit tests you do not boot Rails.
However this means that "app/models" etc. are not added to the
This typically means you need to either add the paths or use
- Explicit requiring of files
- Additional meta-information about the required files
- Adds paths to the
Require only what you need, keep it light and explicit.
gem 'spec_requirer', group: :test, github: 'HouseTrip/spec_requirer', tag: 'v0.0.2'
This is not released to Rubygems yet.
require 'pathname' require 'spec_requirer' SpecRequirer.setup(app_root: File.join(File.dirname(__FILE__), ".."), components: ['models', 'services', 'presenters']) include SpecRequirer
In a Rails app the
app_root would be the
For each component a require helper is added which lets you do:
require_models 'user', 'reward', 'prize' require_presenters 'user_presenter' require_services 'create_user'
Similarly a "utilizes" method is available for each component which adds a
directory to the
$LOAD_PATH. You can then
require the file as usual:
utilizes_models utilizes_presenters utilizes_services require 'user' require 'user_presenter' require 'create_user'
Or you can use the one-line version as such:
utilizes :models, :presenters, :services
Commented out options are not yet implemented.
require 'pathname' require 'spec_requirer' SpecRequirer.configure do |config| config.app_root = Pathname(__FILE__).join('..') # config.add_components(in: ‘app’, except: %’w(views, assets)) # config.add_component('config/initializers', as: 'initializer') # config.patch_kernel = true end SpecRequirer.setup include SpecRequirer
You can also pass some configuration directly to
setup as such:
SpecRequirer.setup(app_root: app_root, components: ['models', 'presenters'])