1 require File.dirname(__FILE__) + '/../../spec_helper'
5 describe ExampleGroupFactory, "with :foobar registered as custom type" do
8 @example_group = Class.new(ExampleGroup)
9 ExampleGroupFactory.register(:foobar, @example_group)
13 ExampleGroupFactory.reset
16 it "should #get the default ExampleGroup type when passed nil" do
17 ExampleGroupFactory.get(nil).should == ExampleGroup
20 it "should #get the default ExampleGroup for unregistered non-nil values" do
21 ExampleGroupFactory.get(:does_not_exist).should == ExampleGroup
24 it "should #get custom type for :foobar" do
25 ExampleGroupFactory.get(:foobar).should == @example_group
28 it "should #get the actual type when that is passed in" do
29 ExampleGroupFactory.get(@example_group).should == @example_group
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+/
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
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
49 example_group.superclass.should == Spec::Example::ExampleGroup
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
56 example_group.superclass.should == Spec::Example::ExampleGroup
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
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
67 example_group.superclass.should == klass
70 it "should create a type indicated by :spec_path" do
71 klass = Class.new(ExampleGroup) do
72 def initialize(*args, &block); 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"
78 example_group.superclass.should == klass
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
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"
89 example_group.superclass.should == klass
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
96 shared_example_group.should be_an_instance_of(Spec::Example::SharedExampleGroup)
97 SharedExampleGroup.shared_example_groups.should include(shared_example_group)
100 it "should favor the :type over the :spec_path" do
101 klass = Class.new(ExampleGroup) do
102 def initialize(*args, &block); 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
108 example_group.superclass.should == klass
111 it "should register ExampleGroup by default" do
112 example_group = Spec::Example::ExampleGroupFactory.create_example_group("The ExampleGroup") do
114 rspec_options.example_groups.should include(example_group)
117 it "should enable unregistering of ExampleGroups" do
118 example_group = Spec::Example::ExampleGroupFactory.create_example_group("The ExampleGroup") do
121 rspec_options.example_groups.should_not include(example_group)
125 Spec::Example::ExampleGroupFactory.reset