2 # Creates and registers an instance of a Spec::DSL::Behaviour (or a subclass).
3 # The instantiated behaviour class depends on the directory of the file
4 # calling this method. For example, Spec::Rails will use different
5 # classes for specs living in <tt>spec/models</tt>, <tt>spec/helpers</tt>,
6 # <tt>spec/views</tt> and <tt>spec/controllers</tt>.
8 # It is also possible to override autodiscovery of the behaviour class
9 # with an options Hash as the last argument:
11 # describe "name", :behaviour_type => :something_special do ...
13 # The reason for using different behaviour classes is to have
14 # different matcher methods available from within the <tt>describe</tt>
17 # See Spec::DSL::BehaviourFactory#add_behaviour_class for details about
18 # how to register special Spec::DSL::Behaviour implementations.
20 def describe(*args, &block)
21 raise ArgumentError if args.empty?
22 args << {} unless Hash === args.last
23 args.last[:spec_path] = caller(0)[1]
24 register_behaviour(Spec::DSL::BehaviourFactory.create(*args, &block))
26 alias :context :describe
28 def respond_to(*names)
29 Spec::Matchers::RespondTo.new(*names)
34 def register_behaviour(behaviour)
36 Spec::DSL::Behaviour.add_shared_behaviour(behaviour)
38 behaviour_runner.add_behaviour(behaviour)
43 # TODO: Figure out a better way to get this considered "covered" and keep this statement on multiple lines
44 unless $behaviour_runner; \
45 $behaviour_runner = ::Spec::Runner::OptionParser.new.create_behaviour_runner(ARGV.dup, STDERR, STDOUT, false); \
46 at_exit { $behaviour_runner.run(nil, false) }; \