module Shoulda
def self.autoload_macros(root, *dirs)
- APP_ROOT/test/vendor/*/shoulda_macros
- APP_ROOT/vendor/*/shoulda_macros
will load everything in
Shoulda.autoload_macros(APP_ROOT, 'vendor/*', 'test/vendor/*')
If you prefer to stick testing dependencies away from your production dependencies:
- APP_ROOT/test/shoulda_macros
- APP_ROOT/vendor/gems/*/shoulda_macros
- APP_ROOT/vendor/plugins/*/shoulda_macros
will load everything in
Shoulda.autoload_macros(APP_ROOT, 'vendor/plugins/*', 'vendor/gems/*')
or
Shoulda.autoload_macros(APP_ROOT, 'vendor/{plugins,gems}/*')
To load macros in an app with a vendor directory laid out like Rails':
- APP_ROOT/test/shoulda_macros
- APP_ROOT/vendor/*/shoulda_macros
will load everything in
Shoulda.autoload_macros(APP_ROOT, 'vendor/*')
To load vendored macros as well:
- your_app/test/shoulda_macros
will load everything in
Shoulda.autoload_macros(File.dirname(__FILE__) + '/..')
Basic usage (from a test_helper):
Dir class.
shoulda_macros subdirectories. These directories support the same kinds of globs as the
All following arguments are directories relative to your root, which contain
The first argument is the path to you application's root directory.
are loaded automatically when you call autoload_macros.
You don't need to specify ROOT/test/shoulda_macros explicitly. Your custom macros
project (it's done automatically for Rails projects).
Call autoload_macros when you want to load test macros automatically in a non-Rails
:nodoc:
def self.autoload_macros(root, *dirs) dirs << File.join('test') complete_dirs = dirs.map{|d| File.join(root, d, 'shoulda_macros')} all_files = complete_dirs.inject([]){ |files, dir| files + Dir[File.join(dir, '*.rb')] } all_files.each do |file| require file end end
def add_context(context) # :nodoc:
def add_context(context) # :nodoc: self.contexts.push(context) end
def contexts # :nodoc:
def contexts # :nodoc: @contexts ||= [] end
def current_context # :nodoc:
def current_context # :nodoc: self.contexts.last end
def remove_context # :nodoc:
def remove_context # :nodoc: self.contexts.pop end