Upgraded Rails and RSpec
[monkeycharger.git] / vendor / plugins / rspec / lib / spec / dsl / configuration.rb
blobf6bd4724dcbe41b252c79bb5d77d5a2ccc29d967
1 module Spec
2   module DSL
3     class Configuration
4       
5       # Chooses what mock framework to use. Example:
6       #
7       #   Spec::Runner.configure do |config|
8       #     config.mock_with :rspec # or :mocha, or :flexmock
9       #   end
10       #
11       # To use any other mock framework, you'll have to provide
12       # your own adapter. This is simply a module that responds to
13       # setup_mocks_for_rspec, verify_mocks_for_rspec and teardown_mocks_for_rspec.
14       # These are your hooks into the lifecycle of a given example. RSpec will
15       # call setup_mocks_for_rspec before running anything else in each Example.
16       # After executing the #after methods, RSpec will then call verify_mocks_for_rspec
17       # and teardown_mocks_for_rspec (this is guaranteed to run even if there are
18       # failures in verify_mocks_for_rspec).
19       #
20       # Once you've defined this module, you can pass that to mock_with:
21       #
22       #   Spec::Runner.configure do |config|
23       #     config.mock_with MyMockFrameworkAdapter
24       #   end
25       #
26       def mock_with(mock_framework)
27         @mock_framework = case mock_framework
28         when Symbol
29           mock_framework_path(mock_framework.to_s)
30         else
31           mock_framework
32         end
33       end
34       
35       def mock_framework # :nodoc:
36         @mock_framework ||= mock_framework_path("rspec")
37       end
38       
39       # Declares modules to be included in all behaviours (<tt>describe</tt> blocks).
40       #
41       #   config.include(My::Bottle, My::Cup)
42       #
43       # If you want to restrict the inclusion to a subset of all the behaviours then
44       # specify this in a Hash as the last argument:
45       #
46       #   config.include(My::Pony, My::Horse, :behaviour_type => :farm)
47       #
48       # Only behaviours that have that type will get the modules included:
49       #
50       #   describe "Downtown", :behaviour_type => :city do
51       #     # Will *not* get My::Pony and My::Horse included
52       #   end
53       #
54       #   describe "Old Mac Donald", :behaviour_type => :farm do
55       #     # *Will* get My::Pony and My::Horse included
56       #   end
57       #
58       def include(*args)
59         included_modules.push(*args)
60       end
61       
62       def included_modules # :nodoc:
63         @included_modules ||= []
64       end
65       
66       # Defines global predicate matchers. Example:
67       #
68       #   config.predicate_matchers[:swim] = :can_swim?
69       #
70       # This makes it possible to say:
71       #
72       #   person.should swim # passes if person.should_swim? returns true
73       #
74       def predicate_matchers
75         @predicate_matchers ||= {}
76       end
77       
78       # Prepends a global <tt>before</tt> block to all behaviours.
79       # See #append_before for filtering semantics.
80       def prepend_before(*args, &proc)
81         Behaviour.prepend_before(*args, &proc)
82       end
83       # Appends a global <tt>before</tt> block to all behaviours.
84       #
85       # If you want to restrict the block to a subset of all the behaviours then
86       # specify this in a Hash as the last argument:
87       #
88       #   config.prepend_before(:all, :behaviour_type => :farm)
89       #
90       # or
91       #
92       #   config.prepend_before(:behaviour_type => :farm)
93       #
94       def append_before(*args, &proc)
95         Behaviour.append_before(*args, &proc)
96       end
97       alias_method :before, :append_before
99       # Prepends a global <tt>after</tt> block to all behaviours.
100       # See #append_before for filtering semantics.
101       def prepend_after(*args, &proc)
102         Behaviour.prepend_after(*args, &proc)
103       end
104       alias_method :after, :prepend_after
105       # Appends a global <tt>after</tt> block to all behaviours.
106       # See #append_before for filtering semantics.
107       def append_after(*args, &proc)
108         Behaviour.append_after(*args, &proc)
109       end
111     private
112     
113       def mock_framework_path(framework_name)
114         File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "..", "plugins", "mock_frameworks", framework_name))
115       end
116       
117     end
118   end