4 # Creates and returns a class that includes the ExampleGroupMethods
5 # module. Which ExampleGroup type is created 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>.
11 # It is also possible to override autodiscovery of the example group
12 # type with an options Hash as the last argument:
14 # describe "name", :type => :something_special do ...
16 # The reason for using different behaviour classes is to have different
17 # matcher methods available from within the <tt>describe</tt> block.
19 # See Spec::Example::ExampleFactory#register for details about how to
20 # register special implementations.
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)
29 alias :context :describe
31 # Creates an example group that can be shared by other example groups
35 # share_examples_for "All Editions" do
36 # it "all editions behaviour" ...
39 # describe SmallEdition do
40 # it_should_behave_like "All Editions"
42 # it "should do small edition stuff" do
46 def share_examples_for(name, &block)
47 describe(name, :shared => true, &block)
50 alias :shared_examples_for :share_examples_for
52 # Creates a Shared Example Group and assigns it to a constant
54 # share_as :AllEditions do
55 # it "should do all editions stuff" ...
58 # describe SmallEdition do
59 # it_should_behave_like AllEditions
61 # it "should do small edition stuff" do
66 # And, for those of you who prefer to use something more like Ruby, you
67 # can just include the module directly
69 # describe SmallEdition do
72 # it "should do small edition stuff" do
76 def share_as(name, &block)
78 Object.const_set(name, share_examples_for(name, &block))
80 raise NameError.new(e.message + "\nThe first argument to share_as must be a legal name for a constant\n")
87 $rspec_options ||= begin; \
88 parser = ::Spec::Runner::OptionParser.new(STDERR, STDOUT); \
89 parser.order!(ARGV); \
90 $rspec_options = parser.options; \
95 def init_rspec_options(options)
96 $rspec_options = options if $rspec_options.nil?
102 include Spec::Extensions::Main