Class Index [+]

Quicksearch

Spec::DSL::Main

Public Instance Methods

context(*args, &block) click to toggle source
Alias for: describe
describe(*args, &block) click to toggle source

Creates and returns a class that includes the ExampleGroupMethods module. Which ExampleGroup type is created depends on the directory of the file calling this method. For example, Spec::Rails will use different classes for specs living in spec/models, spec/helpers, spec/views and spec/controllers.

It is also possible to override autodiscovery of the example group type with an options Hash as the last argument:

  describe "name", :type => :something_special do ...

The reason for using different example group classes is to have different matcher methods available from within the describe block.

See Spec::Example::ExampleGroupFactory#register for details about how to register special implementations.

    # File lib/spec/dsl/main.rb, line 24
24:       def describe(*args, &block)
25:         raise Spec::Example::NoDescriptionError.new("example group", caller(0)[1]) if args.empty?
26:         add_options(args, :scope => self)
27:         set_location(args.options, caller(0)[1])
28:         Spec::Example::ExampleGroupFactory.create_example_group(*args, &block)
29:       end
Also aliased as: context
share_as(name, &block) click to toggle source

Creates a Shared Example Group and assigns it to a constant

 share_as :AllEditions do
   it "should do all editions stuff" ...
 end

 describe SmallEdition do
   it_should_behave_like AllEditions

   it "should do small edition stuff" do
     ...
   end
 end

And, for those of you who prefer to use something more like Ruby, you can just include the module directly

 describe SmallEdition do
   include AllEditions

   it "should do small edition stuff" do
     ...
   end
 end
    # File lib/spec/dsl/main.rb, line 78
78:       def share_as(name, &block)
79:         begin
80:           args = [name]
81:           add_options(args)
82:           set_location(args.options, caller(0)[1])
83:           Object.const_set(name, Spec::Example::ExampleGroupFactory.create_shared_example_group(*args, &block))
84:         rescue NameError => e
85:           raise NameError.new(e.message + "\nThe first argument to share_as must be a legal name for a constant\n")
86:         end
87:       end
share_examples_for(*args, &block) click to toggle source

Creates an example group that can be shared by other example groups

Examples

 share_examples_for "All Editions" do
   it "all editions behaviour" ...
 end

 describe SmallEdition do
   it_should_behave_like "All Editions"

   it "should do small edition stuff" do
     ...
   end
 end
    # File lib/spec/dsl/main.rb, line 47
47:       def share_examples_for(*args, &block)
48:         add_options(args)
49:         set_location(args.options, caller(0)[1])
50:         Spec::Example::ExampleGroupFactory.create_shared_example_group(*args, &block)
51:       end
Also aliased as: shared_examples_for
shared_examples_for(*args, &block) click to toggle source
Alias for: share_examples_for

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.