class Spec::Runner::Configuration
def add_callback(sym, *args, &proc)
def add_callback(sym, *args, &proc) scope, options = scope_and_options(*args) example_group = Spec::Example::ExampleGroupFactory[get_type_from_options(options)] example_group.__send__(sym, scope, &proc) end
def append_after(scope = :each, options={}, &proc)
Appends a global after block to all example groups.
def append_after(scope = :each, options={}, &proc) add_callback(:append_after, scope, options, &proc) end
def append_before(scope = :each, options={}, &proc)
group, before any of its examples are run. When :suite the
example. When :all, the block is executed once per example
:suite. When :each, the block is executed before each
scope can be any of :each (default), :all, or
Appends a global before block to all example groups.
def append_before(scope = :each, options={}, &proc) add_callback(:append_before, scope, options, &proc) end
def extend(*modules_and_options)
Works just like #include, but extends the example groups
extend(My::Helpers, :type => :key)
extend(Some::Helpers, More::Helpers)
extend(Some::Helpers)
:call-seq:
def extend(*modules_and_options) include_or_extend(:extend, *modules_and_options) end
def get_type_from_options(options)
def get_type_from_options(options) options[:type] || options[:behaviour_type] end
def include(*modules_and_options)
end
# *Will* include ControllerExampleHelpers
describe AccountsController, :type => :controller do
end
# Will *not* include ControllerExampleHelpers
describe Account, :type => :model do
Only example groups that have that type will get the modules included:
config.include(ControllerExampleHelpers, :type => :controller)
methods for controller examples, you could do this:
Spec::Example::ExampleMethods in it. So if you have a module of helper
with Spec::Example::ExampleGroupMethods and includes
For example, the rspec-rails gem/plugin extends Test::Unit::TestCase
Spec::Example::ExampleMethods.
Spec::Example::ExampleGroupMethods and includes
subclass of Spec::Example::ExampleGroup or extends
:type should be a key that maps to a class that is either a
the inclusion to a subset of example groups. The value assigned to
Use :type to restrict
will be included in all example groups.
(describe blocks). With no :type, the modules listed
Declares modules to be included in multiple example groups
include(My::Helpers, :type => :key)
include(Some::Helpers, More::Helpers)
include(Some::Helpers)
:call-seq:
def include(*modules_and_options) include_or_extend(:include, *modules_and_options) end
def include_or_extend(action, *args)
def include_or_extend(action, *args) modules, options = args_and_options(*args) [get_type_from_options(options)].flatten.each do |required_example_group| required_example_group = required_example_group.to_sym if required_example_group modules.each do |mod| Spec::Example::ExampleGroupFactory[required_example_group].__send__(action, mod) end end end
def mock_framework # :nodoc:
def mock_framework # :nodoc: @mock_framework ||= mock_framework_path("rspec") end
def mock_framework_path(framework_name)
def mock_framework_path(framework_name) File.expand_path(File.join(File.dirname(__FILE__), "/../adapters/mock_frameworks/#{framework_name}")) end
def mock_with(mock_framework)
end
config.mock_with MyMockFrameworkAdapter
Spec::Runner.configure do |config|
Once you've defined this module, you can pass that to mock_with:
verify_mocks_for_rspec).
guaranteed to run even if there are failures in
verify_mocks_for_rspec and teardown_mocks_for_rspec (this is
Example. After executing the #after methods, RSpec will then call
call setup_mocks_for_rspec before running anything else in each
These are your hooks into the lifecycle of a given example. RSpec will
teardown_mocks_for_rspec.
verify_mocks_for_rspec
setup_mocks_for_rspec
methods:
adapter. This is simply a module that responds to the following
To use any other mock framework, you'll have to provide your own
end
config.mock_with :rspec, :mocha, :flexmock, or :rr
Spec::Runner.configure do |config|
Chooses what mock framework to use. Example:
def mock_with(mock_framework) @mock_framework = case mock_framework when Symbol mock_framework_path(mock_framework.to_s) else mock_framework end end
def predicate_matchers
person.should swim # passes if person.can_swim? returns true
This makes it possible to say:
config.predicate_matchers[:swim] = :can_swim?
Defines global predicate matchers. Example:
DEPRECATED - use Spec::Matchers::DSL instead
def predicate_matchers @predicate_matchers ||= Spec::HashWithDeprecationNotice.new("predicate_matchers", "the new Matcher DSL") end
def prepend_after(scope = :each, options={}, &proc)
Prepends a global after block to all example groups.
def prepend_after(scope = :each, options={}, &proc) add_callback(:prepend_after, scope, options, &proc) end
def prepend_before(scope = :each, options={}, &proc)
Prepends a global before block to all example groups.
def prepend_before(scope = :each, options={}, &proc) add_callback(:prepend_before, scope, options, &proc) end
def scope_and_options(*args) # :nodoc:
def scope_and_options(*args) # :nodoc: args, options = args_and_options(*args) return scope_from(*args), options end
def scope_from(*args) # :nodoc:
def scope_from(*args) # :nodoc: args[0] || :each end