Upgraded Rails and RSpec
[monkeycharger.git] / vendor / plugins / rspec / rspec / lib / spec / extensions / main.rb
blob19d1df8c45ba3685da026c9ad190292ae9c2063b
1 module Spec
2   module Extensions
3     module Main
4       # Creates and returns a class that includes the ExampleGroupMethods
5       # module. The ExampleGroup sub-class depends on the directory of the file
6       # calling this method. For example, Spec::Rails will use different
7       # classes for specs living in <tt>spec/models</tt>,
8       # <tt>spec/helpers</tt>, <tt>spec/views</tt> and
9       # <tt>spec/controllers</tt>.
10       #
11       # It is also possible to override autodiscovery of the behaviour class
12       # with an options Hash as the last argument:
13       #
14       #   describe "name", :behaviour_type => :something_special do ...
15       #
16       # The reason for using different behaviour classes is to have different
17       # matcher methods available from within the <tt>describe</tt> block.
18       #
19       # See Spec::Example::ExampleFactory#register for details about how to
20       # register special implementations.
21       #
22       def describe(*args, &block)
23         raise ArgumentError if args.empty?
24         raise ArgumentError unless block
25         args << {} unless Hash === args.last
26         args.last[:spec_path] = caller(0)[1]
27         Spec::Example::ExampleGroupFactory.create_example_group(*args, &block)
28       end
29       alias :context :describe
31     private
32     
33       def rspec_options
34         $rspec_options ||= begin; \
35           parser = ::Spec::Runner::OptionParser.new(STDERR, STDOUT); \
36           parser.order!(ARGV); \
37           $rspec_options = parser.options; \
38         end
39         $rspec_options
40       end
41       
42       def init_rspec_options(options)
43         $rspec_options = options if $rspec_options.nil?
44       end
45     end
46   end
47 end
49 include Spec::Extensions::Main