class Spec::Example::Configuration
def append_after(*args, &proc)
Appends a global after block to all example groups.
def append_after(*args, &proc) scope, options = scope_and_options(*args) example_group = ExampleGroupFactory.get( get_type_from_options(options) ) example_group.append_after(scope, &proc) end
def append_before(*args, &proc)
config.prepend_before(:type => :farm)
or
config.prepend_before(:all, :type => :farm)
groups then specify this in a Hash as the last argument:
If you want to restrict the block to a subset of all the example
Appends a global before block to all example groups.
def append_before(*args, &proc) scope, options = scope_and_options(*args) example_group = ExampleGroupFactory.get( get_type_from_options(options) ) example_group.append_before(scope, &proc) end
def get_type_from_options(options)
def get_type_from_options(options) options[:type] || options[:behaviour_type] end
def include(*args)
end
# *Will* get My::Pony and My::Horse included
describe "Old Mac Donald", :type => :farm do
end
# Will *not* get My::Pony and My::Horse included
describe "Downtown", :type => :city do
Only example groups that have that type will get the modules included:
config.include(My::Pony, My::Horse, :type => :farm)
and includes Spec::Example::ExampleMethods
Spec::Example::ExampleGroup or extends Spec::Example::ExampleGroupMethods
key that maps to a class that is either a subclass of
a subset of example groups. The value assigned to :type should be a
included in all example groups. Use :type to restrict the inclusion to
(describe blocks). With no :type, the modules listed will be
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(*args) args << {} unless Hash === args.last modules, options = args_and_options(*args) required_example_group = get_type_from_options(options) required_example_group = required_example_group.to_sym if required_example_group modules.each do |mod| ExampleGroupFactory.get(required_example_group).send(:include, mod) 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__), "..", "..", "..", "plugins", "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:
def predicate_matchers @predicate_matchers ||= {} end
def prepend_after(*args, &proc)
Prepends a global after block to all example groups.
def prepend_after(*args, &proc) scope, options = scope_and_options(*args) example_group = ExampleGroupFactory.get( get_type_from_options(options) ) example_group.prepend_after(scope, &proc) end
def prepend_before(*args, &proc)
Prepends a global before block to all example groups.
def prepend_before(*args, &proc) scope, options = scope_and_options(*args) example_group = ExampleGroupFactory.get( get_type_from_options(options) ) example_group.prepend_before(scope, &proc) end
def scope_and_options(*args)
def scope_and_options(*args) args, options = args_and_options(*args) scope = (args[0] || :each), options end