Module: Shoulda
- Defined in:
- lib/shoulda/macros.rb,
lib/shoulda/context.rb,
lib/shoulda/helpers.rb,
lib/shoulda/version.rb,
lib/shoulda/assertions.rb,
lib/shoulda/autoload_macros.rb,
lib/shoulda/private_helpers.rb,
lib/shoulda/active_record/macros.rb,
lib/shoulda/active_record/helpers.rb,
lib/shoulda/action_mailer/matchers.rb,
lib/shoulda/active_record/matchers.rb,
lib/shoulda/action_controller/macros.rb,
lib/shoulda/action_mailer/assertions.rb,
lib/shoulda/active_record/assertions.rb,
lib/shoulda/action_controller/matchers.rb,
lib/shoulda/action_mailer/matchers/have_sent_email.rb,
lib/shoulda/action_controller/matchers/route_matcher.rb,
lib/shoulda/active_record/matchers/validation_matcher.rb,
lib/shoulda/active_record/matchers/allow_value_matcher.rb,
lib/shoulda/active_record/matchers/association_matcher.rb,
lib/shoulda/action_controller/matchers/assign_to_matcher.rb,
lib/shoulda/active_record/matchers/have_db_index_matcher.rb,
lib/shoulda/active_record/matchers/have_db_column_matcher.rb,
lib/shoulda/action_controller/matchers/redirect_to_matcher.rb,
lib/shoulda/action_controller/matchers/set_session_matcher.rb,
lib/shoulda/action_controller/matchers/filter_param_matcher.rb,
lib/shoulda/action_controller/matchers/respond_with_matcher.rb,
lib/shoulda/active_record/matchers/ensure_length_of_matcher.rb,
lib/shoulda/action_controller/matchers/set_the_flash_matcher.rb,
lib/shoulda/active_record/matchers/validate_format_of_matcher.rb,
lib/shoulda/action_controller/matchers/render_template_matcher.rb,
lib/shoulda/active_record/matchers/ensure_inclusion_of_matcher.rb,
lib/shoulda/active_record/matchers/validate_presence_of_matcher.rb,
lib/shoulda/action_controller/matchers/render_with_layout_matcher.rb,
lib/shoulda/active_record/matchers/validate_acceptance_of_matcher.rb,
lib/shoulda/active_record/matchers/validate_uniqueness_of_matcher.rb,
lib/shoulda/active_record/matchers/have_readonly_attribute_matcher.rb,
lib/shoulda/active_record/matchers/allow_mass_assignment_of_matcher.rb,
lib/shoulda/active_record/matchers/validate_numericality_of_matcher.rb,
lib/shoulda/action_controller/matchers/respond_with_content_type_matcher.rb
Overview
:nodoc:
Defined Under Namespace
Modules: ActionController, ActionMailer, ActiveRecord, Assertions, ClassMethods, Helpers, InstanceMethods, Macros, Private Classes: Context
Constant Summary collapse
- VERSION =
"2.11.1"
Class Attribute Summary collapse
-
.contexts ⇒ Object
:nodoc:.
Class Method Summary collapse
-
.add_context(context) ⇒ Object
:nodoc:.
-
.autoload_macros(root, *dirs) ⇒ Object
Call autoload_macros when you want to load test macros automatically in a non-Rails project (it’s done automatically for Rails projects).
-
.current_context ⇒ Object
:nodoc:.
-
.remove_context ⇒ Object
:nodoc:.
Class Attribute Details
.contexts ⇒ Object
:nodoc:
4 5 6 |
# File 'lib/shoulda/context.rb', line 4 def contexts @contexts end |
Class Method Details
.add_context(context) ⇒ Object
:nodoc:
12 13 14 |
# File 'lib/shoulda/context.rb', line 12 def add_context(context) # :nodoc: self.contexts.push(context) end |
.autoload_macros(root, *dirs) ⇒ Object
Call autoload_macros when you want to load test macros automatically in a non-Rails project (it’s done automatically for Rails projects). You don’t need to specify ROOT/test/shoulda_macros explicitly. Your custom macros are loaded automatically when you call autoload_macros.
The first argument is the path to you application’s root directory. All following arguments are directories relative to your root, which contain shoulda_macros subdirectories. These directories support the same kinds of globs as the Dir class.
Basic usage (from a test_helper): Shoulda.autoload_macros(File.dirname(__FILE__) + ‘/..’) will load everything in
-
your_app/test/shoulda_macros
To load vendored macros as well: Shoulda.autoload_macros(APP_ROOT, ‘vendor/*’) will load everything in
-
APP_ROOT/vendor/*/shoulda_macros
-
APP_ROOT/test/shoulda_macros
To load macros in an app with a vendor directory laid out like Rails’: Shoulda.autoload_macros(APP_ROOT, ‘vendor/plugins,gems/*’) or Shoulda.autoload_macros(APP_ROOT, ‘vendor/plugins/*’, ‘vendor/gems/*’) will load everything in
-
APP_ROOT/vendor/plugins/*/shoulda_macros
-
APP_ROOT/vendor/gems/*/shoulda_macros
-
APP_ROOT/test/shoulda_macros
If you prefer to stick testing dependencies away from your production dependencies: Shoulda.autoload_macros(APP_ROOT, ‘vendor/*’, ‘test/vendor/*’) will load everything in
-
APP_ROOT/vendor/*/shoulda_macros
-
APP_ROOT/test/vendor/*/shoulda_macros
-
APP_ROOT/test/shoulda_macros
38 39 40 41 42 43 44 45 |
# File 'lib/shoulda/autoload_macros.rb', line 38 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 |
.current_context ⇒ Object
:nodoc:
8 9 10 |
# File 'lib/shoulda/context.rb', line 8 def current_context # :nodoc: self.contexts.last end |
.remove_context ⇒ Object
:nodoc:
16 17 18 |
# File 'lib/shoulda/context.rb', line 16 def remove_context # :nodoc: self.contexts.pop end |