4 # Chooses what mock framework to use. Example:
6 # Spec::Runner.configure do |config|
7 # config.mock_with :rspec, :mocha, :flexmock, or :rr
10 # To use any other mock framework, you'll have to provide
11 # your own adapter. This is simply a module that responds to
12 # setup_mocks_for_rspec, verify_mocks_for_rspec and teardown_mocks_for_rspec.
13 # These are your hooks into the lifecycle of a given example. RSpec will
14 # call setup_mocks_for_rspec before running anything else in each Example.
15 # After executing the #after methods, RSpec will then call verify_mocks_for_rspec
16 # and teardown_mocks_for_rspec (this is guaranteed to run even if there are
17 # failures in verify_mocks_for_rspec).
19 # Once you've defined this module, you can pass that to mock_with:
21 # Spec::Runner.configure do |config|
22 # config.mock_with MyMockFrameworkAdapter
25 def mock_with(mock_framework)
26 @mock_framework = case mock_framework
28 mock_framework_path(mock_framework.to_s)
34 def mock_framework # :nodoc:
35 @mock_framework ||= mock_framework_path("rspec")
38 # Declares modules to be included in all example groups (<tt>describe</tt> blocks).
40 # config.include(My::Bottle, My::Cup)
42 # If you want to restrict the inclusion to a subset of all the example groups then
43 # specify this in a Hash as the last argument:
45 # config.include(My::Pony, My::Horse, :type => :farm)
47 # Only example groups that have that type will get the modules included:
49 # describe "Downtown", :type => :city do
50 # # Will *not* get My::Pony and My::Horse included
53 # describe "Old Mac Donald", :type => :farm do
54 # # *Will* get My::Pony and My::Horse included
58 args << {} unless Hash === args.last
59 modules, options = args_and_options(*args)
60 required_example_group = get_type_from_options(options)
61 required_example_group = required_example_group.to_sym if required_example_group
63 ExampleGroupFactory.get(required_example_group).send(:include, mod)
67 # Defines global predicate matchers. Example:
69 # config.predicate_matchers[:swim] = :can_swim?
71 # This makes it possible to say:
73 # person.should swim # passes if person.should_swim? returns true
75 def predicate_matchers
76 @predicate_matchers ||= {}
79 # Prepends a global <tt>before</tt> block to all example groups.
80 # See #append_before for filtering semantics.
81 def prepend_before(*args, &proc)
82 scope, options = scope_and_options(*args)
83 example_group = ExampleGroupFactory.get(
84 get_type_from_options(options)
86 example_group.prepend_before(scope, &proc)
88 # Appends a global <tt>before</tt> block to all example groups.
90 # If you want to restrict the block to a subset of all the example groups then
91 # specify this in a Hash as the last argument:
93 # config.prepend_before(:all, :type => :farm)
97 # config.prepend_before(:type => :farm)
99 def append_before(*args, &proc)
100 scope, options = scope_and_options(*args)
101 example_group = ExampleGroupFactory.get(
102 get_type_from_options(options)
104 example_group.append_before(scope, &proc)
106 alias_method :before, :append_before
108 # Prepends a global <tt>after</tt> block to all example groups.
109 # See #append_before for filtering semantics.
110 def prepend_after(*args, &proc)
111 scope, options = scope_and_options(*args)
112 example_group = ExampleGroupFactory.get(
113 get_type_from_options(options)
115 example_group.prepend_after(scope, &proc)
117 alias_method :after, :prepend_after
118 # Appends a global <tt>after</tt> block to all example groups.
119 # See #append_before for filtering semantics.
120 def append_after(*args, &proc)
121 scope, options = scope_and_options(*args)
122 example_group = ExampleGroupFactory.get(
123 get_type_from_options(options)
125 example_group.append_after(scope, &proc)
130 def scope_and_options(*args)
131 args, options = args_and_options(*args)
132 scope = (args[0] || :each), options
135 def get_type_from_options(options)
136 options[:type] || options[:behaviour_type]
139 def mock_framework_path(framework_name)
140 File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "plugins", "mock_frameworks", framework_name))