~ubuntu-branches/ubuntu/oneiric/puppet/oneiric-security

« back to all changes in this revision

Viewing changes to vendor/gems/rspec/lib/spec/example/example_group_factory.rb

  • Committer: Bazaar Package Importer
  • Author(s): Micah Anderson
  • Date: 2008-07-26 15:43:45 UTC
  • mfrom: (1.1.8 upstream) (3.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080726154345-c03m49twzxewdwjn
Tags: 0.24.5-2
* Fix puppetlast to work with 0.24.5
* Adjust logcheck to match against new log messages in 0.24.5
* Update standards version to 3.8.0 (no changes)
* Update changelog to reduce length of line to make lintian happy

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
module Spec
 
2
  module Example
 
3
    class ExampleGroupFactory
 
4
      class << self
 
5
        def reset
 
6
          @example_group_types = nil
 
7
          default(ExampleGroup)
 
8
        end
 
9
 
 
10
        # Registers an example group class +klass+ with the symbol
 
11
        # +type+. For example:
 
12
        #
 
13
        #   Spec::Example::ExampleGroupFactory.register(:farm, Spec::Farm::Example::FarmExampleGroup)
 
14
        #
 
15
        # This will cause Main#describe from a file living in 
 
16
        # <tt>spec/farm</tt> to create example group instances of type
 
17
        # Spec::Farm::Example::FarmExampleGroup.
 
18
        def register(id, example_group_class)
 
19
          @example_group_types[id] = example_group_class
 
20
        end
 
21
        
 
22
        # Sets the default ExampleGroup class
 
23
        def default(example_group_class)
 
24
          old = @example_group_types
 
25
          @example_group_types = Hash.new(example_group_class)
 
26
          @example_group_types.merge(old) if old
 
27
        end
 
28
 
 
29
        def get(id=nil)
 
30
          if @example_group_types.values.include?(id)
 
31
            id
 
32
          else
 
33
            @example_group_types[id]
 
34
          end
 
35
        end
 
36
        
 
37
        def create_example_group(*args, &block)
 
38
          opts = Hash === args.last ? args.last : {}
 
39
          if opts[:shared]
 
40
            SharedExampleGroup.new(*args, &block)
 
41
          else
 
42
            superclass = determine_superclass(opts)
 
43
            superclass.describe(*args, &block)
 
44
          end
 
45
        end
 
46
 
 
47
        protected
 
48
 
 
49
        def determine_superclass(opts)
 
50
          id = if opts[:type]
 
51
            opts[:type]
 
52
          elsif opts[:spec_path] =~ /spec(\\|\/)(#{@example_group_types.keys.join('|')})/
 
53
            $2 == '' ? nil : $2.to_sym
 
54
          end
 
55
          get(id)
 
56
        end
 
57
 
 
58
      end
 
59
      self.reset
 
60
    end
 
61
  end
 
62
end