]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/spec/spec/example/example_group_factory_spec.rb
3b50011f708b9b3d064a678b75d49cf141df8931
[rails.git] / vendor / gems / rspec-1.1.2 / spec / spec / example / example_group_factory_spec.rb
1 require File.dirname(__FILE__) + '/../../spec_helper'
2
3 module Spec
4   module Example
5     describe ExampleGroupFactory, "with :foobar registered as custom type" do
6
7       before do
8         @example_group = Class.new(ExampleGroup)
9         ExampleGroupFactory.register(:foobar, @example_group)
10       end
11
12       after do
13         ExampleGroupFactory.reset
14       end
15
16       it "should #get the default ExampleGroup type when passed nil" do
17         ExampleGroupFactory.get(nil).should == ExampleGroup
18       end
19
20       it "should #get the default ExampleGroup for unregistered non-nil values" do
21         ExampleGroupFactory.get(:does_not_exist).should == ExampleGroup
22       end
23
24       it "should #get custom type for :foobar" do
25         ExampleGroupFactory.get(:foobar).should == @example_group
26       end
27
28       it "should #get the actual type when that is passed in" do
29         ExampleGroupFactory.get(@example_group).should == @example_group
30       end
31
32     end    
33
34     describe ExampleGroupFactory, "#create_example_group" do
35       it "should create a uniquely named class" do
36         example_group = Spec::Example::ExampleGroupFactory.create_example_group("example_group") {}
37         example_group.name.should =~ /Spec::Example::ExampleGroup::Subclass_\d+/
38       end
39
40       it "should create a Spec::Example::Example subclass by default" do
41         example_group = Spec::Example::ExampleGroupFactory.create_example_group("example_group") {}
42         example_group.superclass.should == Spec::Example::ExampleGroup
43       end
44
45       it "should create a Spec::Example::Example when :type => :default" do
46         example_group = Spec::Example::ExampleGroupFactory.create_example_group(
47           "example_group", :type => :default
48         ) {}
49         example_group.superclass.should == Spec::Example::ExampleGroup
50       end
51
52       it "should create a Spec::Example::Example when :type => :default" do
53         example_group = Spec::Example::ExampleGroupFactory.create_example_group(
54           "example_group", :type => :default
55         ) {}
56         example_group.superclass.should == Spec::Example::ExampleGroup
57       end
58
59       it "should create specified type when :type => :something_other_than_default" do
60         klass = Class.new(ExampleGroup) do
61           def initialize(*args, &block); end
62         end
63         Spec::Example::ExampleGroupFactory.register(:something_other_than_default, klass)
64         example_group = Spec::Example::ExampleGroupFactory.create_example_group(
65           "example_group", :type => :something_other_than_default
66         ) {}
67         example_group.superclass.should == klass
68       end
69       
70       it "should create a type indicated by :spec_path" do
71         klass = Class.new(ExampleGroup) do
72           def initialize(*args, &block); end
73         end
74         Spec::Example::ExampleGroupFactory.register(:something_other_than_default, klass)
75         example_group = Spec::Example::ExampleGroupFactory.create_example_group(
76           "example_group", :spec_path => "./spec/something_other_than_default/some_spec.rb"
77         ) {}
78         example_group.superclass.should == klass
79       end
80       
81       it "should create a type indicated by :spec_path (with spec_path generated by caller on windows)" do
82         klass = Class.new(ExampleGroup) do
83           def initialize(*args, &block); end
84         end
85         Spec::Example::ExampleGroupFactory.register(:something_other_than_default, klass)
86         example_group = Spec::Example::ExampleGroupFactory.create_example_group(
87           "example_group", :spec_path => "./spec\\something_other_than_default\\some_spec.rb"
88         ) {}
89         example_group.superclass.should == klass
90       end
91       
92       it "should create and register a Spec::Example::Example if :shared => true" do
93         shared_example_group = Spec::Example::ExampleGroupFactory.create_example_group(
94           "name", :spec_path => '/blah/spec/models/blah.rb', :type => :controller, :shared => true
95         ) {}
96         shared_example_group.should be_an_instance_of(Spec::Example::SharedExampleGroup)
97         SharedExampleGroup.shared_example_groups.should include(shared_example_group)
98       end
99
100       it "should favor the :type over the :spec_path" do
101         klass = Class.new(ExampleGroup) do
102           def initialize(*args, &block); end
103         end
104         Spec::Example::ExampleGroupFactory.register(:something_other_than_default, klass)
105         example_group = Spec::Example::ExampleGroupFactory.create_example_group(
106           "name", :spec_path => '/blah/spec/models/blah.rb', :type => :something_other_than_default
107         ) {}
108         example_group.superclass.should == klass
109       end
110
111       it "should register ExampleGroup by default" do
112         example_group = Spec::Example::ExampleGroupFactory.create_example_group("The ExampleGroup") do
113         end
114         rspec_options.example_groups.should include(example_group)
115       end
116
117       it "should enable unregistering of ExampleGroups" do
118         example_group = Spec::Example::ExampleGroupFactory.create_example_group("The ExampleGroup") do
119           unregister
120         end
121         rspec_options.example_groups.should_not include(example_group)
122       end
123       
124       after(:each) do
125         Spec::Example::ExampleGroupFactory.reset
126       end
127     end
128   end
129 end