You are viewing a plain text version of this content. The canonical link for it is here.
Posted to olio-commits@incubator.apache.org by ws...@apache.org on 2008/12/11 01:34:30 UTC
svn commit: r725524 [10/14] - in /incubator/olio/webapp/rails/trunk:
app/controllers/ app/models/ app/views/events/ config/ config/environments/
spec/controllers/ spec/models/ vendor/plugins/attachment_fu/
vendor/plugins/attachment_fu/lib/ vendor/plugi...
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/example_group_factory_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/example_group_factory_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/example_group_factory_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/example_group_factory_spec.rb Wed Dec 10 17:34:18 2008
@@ -5,35 +5,35 @@
describe ExampleGroupFactory do
describe "#get" do
attr_reader :example_group
- before do
- @example_group = Class.new(ExampleGroup)
- ExampleGroupFactory.register(:registered_type, @example_group)
+ before(:each) do
+ @example_group_class = Class.new(ExampleGroup)
+ ExampleGroupFactory.register(:registered_type, @example_group_class)
end
- after do
+ after(:each) do
ExampleGroupFactory.reset
end
- it "should #get the default ExampleGroup type when passed nil" do
+ it "should return the default ExampleGroup type for nil" do
ExampleGroupFactory.get(nil).should == ExampleGroup
end
- it "should #get the default ExampleGroup for unregistered non-nil values" do
+ it "should return the default ExampleGroup for an unregistered non-nil value" do
ExampleGroupFactory.get(:does_not_exist).should == ExampleGroup
end
- it "should #get custom type for :registered_type" do
- ExampleGroupFactory.get(:registered_type).should == @example_group
+ it "should return custom type if registered" do
+ ExampleGroupFactory.get(:registered_type).should == @example_group_class
end
- it "should #get the actual type when that is passed in" do
- ExampleGroupFactory.get(@example_group).should == @example_group
+ it "should return the actual type when that is what is submitted" do
+ ExampleGroupFactory.get(@example_group_class).should == @example_group_class
end
it "should get the custom type after setting the default" do
- @example_group2 = Class.new(ExampleGroup)
- ExampleGroupFactory.default(@example_group2)
- ExampleGroupFactory.get(:registered_type).should == @example_group
+ @alternate_example_group_class = Class.new(ExampleGroup)
+ ExampleGroupFactory.default(@alternate_example_group_class)
+ ExampleGroupFactory.get(:registered_type).should == @example_group_class
end
end
@@ -57,15 +57,28 @@
example_group.superclass.should == Spec::Example::ExampleGroup
end
- describe "when :type => :default" do
- it "should create a Spec::Example::Example" do
- example_group = Spec::Example::ExampleGroupFactory.create_example_group(
- "example_group", :type => :default
- ) {}
- example_group.superclass.should == Spec::Example::ExampleGroup
- end
+ it "should raise when no description is given" do
+ lambda {
+ Spec::Example::ExampleGroupFactory.create_example_group do; end
+ }.should raise_error(ArgumentError)
+ end
+
+ it "should raise when no block is given" do
+ lambda { Spec::Example::ExampleGroupFactory.create_example_group "foo" }.should raise_error(ArgumentError)
+ end
+
+ it "should run registered ExampleGroups" do
+ example_group = Spec::Example::ExampleGroupFactory.create_example_group "The ExampleGroup" do end
+ Spec::Runner.options.example_groups.should include(example_group)
+ end
+
+ it "should not run unregistered ExampleGroups" do
+ example_group = Spec::Example::ExampleGroupFactory.create_example_group "The ExampleGroup" do unregister; end
+ Spec::Runner.options.example_groups.should_not include(example_group)
+ end
- it "should create a Spec::Example::Example" do
+ describe "with :type => :default" do
+ it "should create a Spec::Example::ExampleGroup" do
example_group = Spec::Example::ExampleGroupFactory.create_example_group(
"example_group", :type => :default
) {}
@@ -73,8 +86,8 @@
end
end
- describe "when :type => :something_other_than_default" do
- it "should create specified type" do
+ describe "with :type => :something_other_than_default" do
+ it "should create the specified type" do
Spec::Example::ExampleGroupFactory.register(:something_other_than_default, parent_example_group)
non_default_example_group = Spec::Example::ExampleGroupFactory.create_example_group(
"example_group", :type => :something_other_than_default
@@ -100,17 +113,16 @@
custom_example_group.superclass.should == parent_example_group
end
- describe "when :shared => true" do
- attr_reader :shared_example_group
- before do
- @shared_example_group = Spec::Example::ExampleGroupFactory.create_example_group(
+ describe "with :shared => true" do
+ def shared_example_group
+ @shared_example_group ||= Spec::Example::ExampleGroupFactory.create_example_group(
"name", :spec_path => '/blah/spec/models/blah.rb', :type => :controller, :shared => true
) {}
end
- it "should create and register a Spec::Example::Example" do
+ it "should create and register a Spec::Example::SharedExampleGroup" do
shared_example_group.should be_an_instance_of(Spec::Example::SharedExampleGroup)
- SharedExampleGroup.shared_example_groups.should include(shared_example_group)
+ SharedExampleGroup.should include(shared_example_group)
end
end
@@ -125,14 +137,44 @@
it "should register ExampleGroup by default" do
example_group = Spec::Example::ExampleGroupFactory.create_example_group("The ExampleGroup") do
end
- rspec_options.example_groups.should include(example_group)
+ Spec::Runner.options.example_groups.should include(example_group)
end
it "should enable unregistering of ExampleGroups" do
example_group = Spec::Example::ExampleGroupFactory.create_example_group("The ExampleGroup") do
unregister
end
- rspec_options.example_groups.should_not include(example_group)
+ Spec::Runner.options.example_groups.should_not include(example_group)
+ end
+
+
+ after(:each) do
+ Spec::Example::ExampleGroupFactory.reset
+ end
+ end
+
+ describe "#registered_or_ancestor_of_registered?" do
+ before(:each) do
+ @unregistered_parent = Class.new(ExampleGroup)
+ @registered_child = Class.new(@unregistered_parent)
+ @unregistered_grandchild = Class.new(@registered_child)
+ Spec::Example::ExampleGroupFactory.register :registered_child, @registered_child
+ end
+
+ it "should return true for empty list" do
+ Spec::Example::ExampleGroupFactory.registered_or_ancestor_of_registered?([]).should be_true
+ end
+
+ it "should return true for a registered example group class" do
+ Spec::Example::ExampleGroupFactory.registered_or_ancestor_of_registered?([@registered_child]).should be_true
+ end
+
+ it "should return true for an ancestor of a registered example_group_classes" do
+ Spec::Example::ExampleGroupFactory.registered_or_ancestor_of_registered?([@unregistered_parent]).should be_true
+ end
+
+ it "should return false for a subclass of a registered example_group_class" do
+ Spec::Example::ExampleGroupFactory.registered_or_ancestor_of_registered?([@unregistered_grandchild]).should be_false
end
after(:each) do
Modified: incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/example_group_methods_spec.rb
URL: http://svn.apache.org/viewvc/incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/example_group_methods_spec.rb?rev=725524&r1=725523&r2=725524&view=diff
==============================================================================
--- incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/example_group_methods_spec.rb (original)
+++ incubator/olio/webapp/rails/trunk/vendor/plugins/rspec/spec/spec/example/example_group_methods_spec.rb Wed Dec 10 17:34:18 2008
@@ -3,570 +3,577 @@
module Spec
module Example
describe 'ExampleGroupMethods' do
- it_should_behave_like "sandboxed rspec_options"
- attr_reader :example_group, :result, :reporter
- before(:each) do
- options.formatters << mock("formatter", :null_object => true)
- options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
- @reporter = FakeReporter.new(@options)
- options.reporter = reporter
- @example_group = Class.new(ExampleGroup) do
- describe("ExampleGroup")
- it "does nothing"
+ with_sandboxed_options do
+ attr_reader :example_group, :result, :reporter
+ before(:each) do
+ # See http://rspec.lighthouseapp.com/projects/5645-rspec/tickets/525-arity-changed-on-partial-mocks#ticket-525-2
+ method_with_three_args = lambda { |arg1, arg2, arg3| }
+ options.formatters << mock("formatter", :null_object => true, :example_pending => method_with_three_args)
+ options.backtrace_tweaker = mock("backtrace_tweaker", :null_object => true)
+ @reporter = FakeReporter.new(@options)
+ options.reporter = reporter
+ @example_group = Class.new(ExampleGroup) do
+ describe("ExampleGroup")
+ it "does nothing"
+ end
end
- class << example_group
- public :include
+
+ after(:each) do
+ ExampleGroup.reset
end
- @result = nil
- end
- after(:each) do
- ExampleGroup.reset
- end
-
- ["describe","context"].each do |method|
- describe "#{method}" do
- describe "when creating an ExampleGroup" do
- attr_reader :child_example_group
- before do
- @child_example_group = @example_group.send method, "Another ExampleGroup" do
- it "should pass" do
- true.should be_true
+ ["describe","context"].each do |method|
+ describe "##{method}" do
+ describe "when creating an ExampleGroup" do
+ before(:each) do
+ @parent_example_group = Class.new(ExampleGroup) do
+ example "first example" do; end
+ end
+ @child_example_group = @parent_example_group.__send__ method, "Child" do
+ example "second example" do; end
end
end
- end
- it "should create a subclass of the ExampleGroup when passed a block" do
- child_example_group.superclass.should == @example_group
- @options.example_groups.should include(child_example_group)
- end
+ it "should create a subclass of the ExampleGroup when passed a block" do
+ @child_example_group.superclass.should == @parent_example_group
+ options.example_groups.should include(@child_example_group)
+ end
- it "should not inherit examples" do
- child_example_group.examples.length.should == 1
+ it "should not inherit examples" do
+ @child_example_group.should have(1).examples
+ end
end
- end
- describe "when creating a SharedExampleGroup" do
- attr_reader :name, :shared_example_group
- before do
- @name = "A Shared ExampleGroup"
- @shared_example_group = @example_group.send method, name, :shared => true do
- it "should pass" do
- true.should be_true
- end
+ describe "when creating a SharedExampleGroup" do
+ before(:each) do
+ @shared_example_group = @example_group.__send__ method, "A Shared ExampleGroup", :shared => true do; end
end
- end
- after do
- SharedExampleGroup.shared_example_groups.delete_if do |registered_shared_example_group|
- registered_shared_example_group == shared_example_group
+ after(:each) do
+ SharedExampleGroup.instance_eval{@shared_example_groups}.delete @shared_example_group
end
- end
- it "should create a SharedExampleGroup" do
- SharedExampleGroup.find_shared_example_group(name).should == shared_example_group
+ it "should create a SharedExampleGroup" do
+ @shared_example_group.should_not be_nil
+ SharedExampleGroup.find("A Shared ExampleGroup").should == @shared_example_group
+ end
end
- end
+ end
end
- end
-
- describe "#it" do
- it "should should create an example instance" do
- lambda {
- @example_group.it("")
- }.should change { @example_group.examples.length }.by(1)
- end
- end
-
- describe "#xit and #xspecify" do
- before(:each) do
- Kernel.stub!(:warn)
+
+ [:specify, :it].each do |method|
+ describe "##{method.to_s}" do
+ it "should should create an example" do
+ lambda {
+ @example_group.__send__(method, "")
+ }.should change { @example_group.examples.length }.by(1)
+ end
+ end
end
+
+ [:xit, :xspecify].each do |method|
+ describe "##{method.to_s}" do
+ before(:each) do
+ Kernel.stub!(:warn)
+ end
- it "should NOT create an example instance" do
- lambda {
- @example_group.xit("")
- }.should_not change(@example_group.examples, :length)
+ it "should NOT create an example" do
+ lambda {
+ @example_group.__send__(method,"")
+ }.should_not change(@example_group.examples, :length)
+ end
- lambda {
- @example_group.xspecify("")
- }.should_not change(@example_group.examples, :length)
+ it "should warn that the example is disabled" do
+ Kernel.should_receive(:warn).with("Example disabled: foo")
+ @example_group.__send__(method,"foo")
+ end
+ end
end
+
- it "should warn that it is disabled" do
- Kernel.should_receive(:warn).with("Example disabled: foo").twice
- @example_group.xit("foo")
- @example_group.xspecify("foo")
- end
- end
+ describe "#examples" do
+ it "should have Examples" do
+ example_group = Class.new(ExampleGroup) do
+ it "should exist" do; end
+ end
+ example_group.examples.length.should == 1
+ example_group.examples.first.description.should == "should exist"
+ end
- describe "#examples" do
- it "should have Examples" do
- example_group = Class.new(ExampleGroup) do
- describe('example')
- it "should pass" do
- 1.should == 1
+ it "should not include methods that begin with test (only when TU interop is loaded)" do
+ example_group = Class.new(ExampleGroup) do
+ def test_any_args(*args)
+ true.should be_true
+ end
+ def test_something
+ 1.should == 1
+ end
+ def test
+ raise "This is not a real test"
+ end
+ def testify
+ raise "This is not a real test"
+ end
+ def should_something
+ # forces the run
+ end
end
+ example_group.examples.length.should == 1
+ example_group.run.should be_true
end
- example_group.examples.length.should == 1
- example_group.examples.first.description.should == "should pass"
- end
- it "should not include methods that begin with test (only when TU interop is loaded)" do
- example_group = Class.new(ExampleGroup) do
- describe('example')
- def test_any_args(*args)
- true.should be_true
- end
- def test_something
- 1.should == 1
+ it "should include methods that begin with should and has an arity of 0 in suite" do
+ example_group = Class.new(ExampleGroup) do
+ def shouldCamelCase
+ true.should be_true
+ end
+ def should_any_args(*args)
+ true.should be_true
+ end
+ def should_something
+ 1.should == 1
+ end
+ def should_not_something
+ 1.should_not == 2
+ end
+ def should
+ raise "This is not a real example"
+ end
+ def should_not
+ raise "This is not a real example"
+ end
end
- def test
- raise "This is not a real test"
+ example_group.should have(4).examples
+ descriptions = example_group.examples.collect {|example| example.description.to_s}
+ descriptions.should include(
+ "shouldCamelCase",
+ "should_any_args",
+ "should_something",
+ "should_not_something")
+ descriptions.should_not include(
+ "should",
+ "should_not"
+ )
+ end
+
+ it "should not include methods that begin with test_ and has an arity > 0 in suite" do
+ example_group = Class.new(ExampleGroup) do
+ def test_invalid(foo)
+ 1.should == 1
+ end
+ def testInvalidCamelCase(foo)
+ 1.should == 1
+ end
end
- def testify
- raise "This is not a real test"
+ example_group.should have(:no).examples
+ end
+
+ it "should not include methods that begin with should_ and has an arity > 0 in suite" do
+ example_group = Class.new(ExampleGroup) do
+ def should_invalid(foo)
+ 1.should == 2
+ end
+ def shouldInvalidCamelCase(foo)
+ 1.should == 3
+ end
+ def should_not_invalid(foo)
+ 1.should == 4
+ end
+ def should_valid
+ 1.should == 1
+ end
end
- def should_something
- # forces the run
+ example_group.should have(1).examples
+ example_group.run.should be_true
+ end
+
+ it "should run should_methods" do
+ example_group = Class.new(ExampleGroup) do
+ def should_valid
+ 1.should == 2
+ end
end
+ example_group.should have(1).examples
+ example_group.run.should be_false
end
- example_group.examples.length.should == 1
- example_group.run.should be_true
end
- it "should include methods that begin with should and has an arity of 0 in suite" do
- example_group = Class.new(ExampleGroup) do
- describe('example')
- def shouldCamelCase
- true.should be_true
+ describe "#set_description" do
+ attr_reader :example_group
+ before do
+ class << example_group
+ public :set_description
end
- def should_any_args(*args)
- true.should be_true
+ end
+
+ describe "given a String" do
+ before(:each) do
+ example_group.set_description("abc")
end
- def should_something
- 1.should == 1
+
+ specify ".description should return the String passed into .set_description" do
+ example_group.description.should == "abc"
end
- def should_not_something
- 1.should_not == 2
+
+ specify ".described_type should provide nil as its type" do
+ example_group.described_type.should be_nil
end
- def should
- raise "This is not a real example"
+ end
+
+ describe "given a Class" do
+ before(:each) do
+ example_group.set_description(ExampleGroup)
+ end
+
+ specify ".description should return a String representation of that type (fully qualified) as its name" do
+ example_group.description.should == "Spec::Example::ExampleGroup"
end
- def should_not
- raise "This is not a real example"
+
+ specify ".described_type should return the passed in type" do
+ example_group.described_type.should == Spec::Example::ExampleGroup
end
end
- example_group = example_group.dup
- example_group.examples.length.should == 4
- descriptions = example_group.examples.collect {|example| example.description}.sort
- descriptions.should include("shouldCamelCase")
- descriptions.should include("should_any_args")
- descriptions.should include("should_something")
- descriptions.should include("should_not_something")
- end
- it "should not include methods that begin with test_ and has an arity > 0 in suite" do
- example_group = Class.new(ExampleGroup) do
- describe('example')
- def test_invalid(foo)
- 1.should == 1
+ describe "given a String and a Class" do
+ before(:each) do
+ example_group.set_description("behaving", ExampleGroup)
+ end
+
+ specify ".description should return String then space then Type" do
+ example_group.description.should == "behaving Spec::Example::ExampleGroup"
end
- def testInvalidCamelCase(foo)
- 1.should == 1
+
+ specify ".described_type should return the passed in type" do
+ example_group.described_type.should == Spec::Example::ExampleGroup
end
end
- example_group.examples.length.should == 0
- end
- it "should not include methods that begin with should_ and has an arity > 0 in suite" do
- example_group = Class.new(ExampleGroup) do
- describe('example')
- def should_invalid(foo)
- 1.should == 2
+ describe "given a Class and a String (starting with an alpha char)" do
+ before(:each) do
+ example_group.set_description(ExampleGroup, "behaving")
end
- def shouldInvalidCamelCase(foo)
- 1.should == 3
+
+ specify ".description should return the Type then space then String" do
+ example_group.description.should == "Spec::Example::ExampleGroup behaving"
end
- def should_not_invalid(foo)
- 1.should == 4
+ end
+
+ describe "given a Class and a String (starting with a '.')" do
+ before(:each) do
+ example_group.set_description(ExampleGroup, ".behaving")
end
- def should_valid
- 1.should == 1
+
+ specify ".description should return the Type then String" do
+ example_group.description.should == "Spec::Example::ExampleGroup.behaving"
end
end
- example_group.examples.length.should == 1
- example_group.run.should be_true
- end
- it "should run should_methods" do
- example_group = Class.new(ExampleGroup) do
- def should_valid
- 1.should == 2
+ describe "#set_description(Type, String containing .)" do
+ before(:each) do
+ example_group.set_description(ExampleGroup, "calling a.b")
end
- end
- example_group.examples.length.should == 1
- example_group.run.should be_false
- end
- end
- describe "#set_description" do
- attr_reader :example_group
- before do
- class << example_group
- public :set_description
+ specify ".description should return the Type then space then String" do
+ example_group.description.should == "Spec::Example::ExampleGroup calling a.b"
+ end
end
- end
- describe "#set_description(String)" do
- before(:each) do
- example_group.set_description("abc")
- end
+ describe "#set_description(Type, String starting with .)" do
+ before(:each) do
+ example_group.set_description(ExampleGroup, ".behaving")
+ end
- specify ".description should return the String passed into .set_description" do
- example_group.description.should == "abc"
+ specify "should return the Type then String" do
+ example_group.description.should == "Spec::Example::ExampleGroup.behaving"
+ end
end
- specify ".described_type should provide nil as its type" do
- example_group.described_type.should be_nil
- end
- end
+ describe "#set_description(Type, String containing .)" do
+ before(:each) do
+ example_group.set_description(ExampleGroup, "is #1")
+ end
- describe "#set_description(Type)" do
- before(:each) do
- example_group.set_description(ExampleGroup)
+ specify ".description should return the Type then space then String" do
+ example_group.description.should == "Spec::Example::ExampleGroup is #1"
+ end
end
- specify ".description should return a String representation of that type (fully qualified) as its name" do
- example_group.description.should == "Spec::Example::ExampleGroup"
- end
+ describe "#set_description(String, Type, String)" do
+ before(:each) do
+ example_group.set_description("A", Hash, "with one entry")
+ end
- specify ".described_type should return the passed in type" do
- example_group.described_type.should == Spec::Example::ExampleGroup
+ specify ".description should return the first String then space then Type then second String" do
+ example_group.description.should == "A Hash with one entry"
+ end
end
- end
- describe "#set_description(String, Type)" do
- before(:each) do
- example_group.set_description("behaving", ExampleGroup)
- end
+ describe "#set_description(Hash representing options)" do
+ before(:each) do
+ example_group.set_description(:a => "b", :spec_path => "blah")
+ end
- specify ".description should return String then space then Type" do
- example_group.description.should == "behaving Spec::Example::ExampleGroup"
- end
+ it ".spec_path should expand the passed in :spec_path option passed into the constructor" do
+ example_group.spec_path.should == File.expand_path("blah")
+ end
+
+ it ".description_options should return all the options passed in" do
+ example_group.description_options.should == {:a => "b", :spec_path => "blah"}
+ end
- specify ".described_type should return the passed in type" do
- example_group.described_type.should == Spec::Example::ExampleGroup
end
end
- describe "#set_description(Type, String not starting with a space)" do
- before(:each) do
- example_group.set_description(ExampleGroup, "behaving")
+ describe "#description" do
+ it "should return the same description instance for each call" do
+ example_group.description.should eql(example_group.description)
end
- specify ".description should return the Type then space then String" do
- example_group.description.should == "Spec::Example::ExampleGroup behaving"
+ it "should not add a space when description_text begins with #" do
+ child_example_group = Class.new(example_group) do
+ describe("#foobar", "Does something")
+ end
+ child_example_group.description.should == "ExampleGroup#foobar Does something"
end
- end
- describe "#set_description(Type, String starting with .)" do
- before(:each) do
- example_group.set_description(ExampleGroup, ".behaving")
+ it "should not add a space when description_text begins with ." do
+ child_example_group = Class.new(example_group) do
+ describe(".foobar", "Does something")
+ end
+ child_example_group.description.should == "ExampleGroup.foobar Does something"
end
-
- specify ".description should return the Type then String" do
- example_group.description.should == "Spec::Example::ExampleGroup.behaving"
+
+ it "should return the class name if nil" do
+ example_group.set_description(nil)
+ example_group.description.should =~ /Class:/
+ end
+
+ it "should return the class name if nil" do
+ example_group.set_description("")
+ example_group.description.should =~ /Class:/
end
end
- describe "#set_description(Type, String containing .)" do
- before(:each) do
- example_group.set_description(ExampleGroup, "calling a.b")
+ describe "#description_parts" do
+ it "should return an Array of the current class description args" do
+ example_group.description_parts.should == [example_group.description]
end
- specify ".description should return the Type then space then String" do
- example_group.description.should == "Spec::Example::ExampleGroup calling a.b"
- end
- end
+ it "should return an Array of the description args from each class in the hierarchy" do
+ parent_example_group = Class.new(ExampleGroup) do
+ describe("Parent")
+ end
+
+ child_example_group = Class.new(parent_example_group)
+ child_example_group.describe("Child", ExampleGroup)
+ child_example_group.description.should_not be_empty
- describe "#set_description(Type, String starting with .)" do
- before(:each) do
- example_group.set_description(ExampleGroup, ".behaving")
- end
+ grand_child_example_group = Class.new(child_example_group)
+ grand_child_example_group.describe("GrandChild", ExampleGroup)
+ grand_child_example_group.description.should_not be_empty
- specify "should return the Type then String" do
- example_group.description.should == "Spec::Example::ExampleGroup.behaving"
+ grand_child_example_group.description_parts.should == [
+ "Parent",
+ "Child",
+ Spec::Example::ExampleGroup,
+ "GrandChild",
+ Spec::Example::ExampleGroup
+ ]
end
end
- describe "#set_description(Type, String containing .)" do
- before(:each) do
- example_group.set_description(ExampleGroup, "is #1")
+ describe "#described_type" do
+ it "should return passed in type" do
+ child_example_group = Class.new(example_group) do
+ describe Object
+ end
+ child_example_group.described_type.should == Object
end
- specify ".description should return the Type then space then String" do
- example_group.description.should == "Spec::Example::ExampleGroup is #1"
+ it "should return #described_type of superclass when no passed in type" do
+ parent_example_group = Class.new(ExampleGroup) do
+ describe Object, "#foobar"
+ end
+ child_example_group = Class.new(parent_example_group) do
+ describe "not a type"
+ end
+ child_example_group.described_type.should == Object
end
end
- describe "#set_description(String, Type, String)" do
- before(:each) do
- example_group.set_description("A", Hash, "with one entry")
- end
+ describe "#remove_after" do
+ it "should unregister a given after(:each) block" do
+ after_all_ran = false
+ proc = Proc.new { after_all_ran = true }
- specify ".description should return the first String then space then Type then second String" do
- example_group.description.should == "A Hash with one entry"
- end
- end
+ example_group = Class.new(ExampleGroup) do
+ specify("example") {}
+ after(:each, &proc)
+ end
- describe "#set_description(Hash representing options)" do
- before(:each) do
- example_group.set_description(:a => "b", :spec_path => "blah")
- end
+ example_group.run
+ after_all_ran.should be_true
- it ".spec_path should expand the passed in :spec_path option passed into the constructor" do
- example_group.spec_path.should == File.expand_path("blah")
+ after_all_ran = false
+ example_group.remove_after(:each, &proc)
+ example_group.run
+ after_all_ran.should be_false
end
+ end
- it ".description_options should return all the options passed in" do
- example_group.description_options.should == {:a => "b", :spec_path => "blah"}
- end
+ describe "#include" do
+ it "should have accessible class methods from included module" do
+ mod_method_called = false
+ mod = Module.new do
+ class_methods = Module.new do
+ define_method :mod_method do
+ mod_method_called = true
+ end
+ end
- end
- end
+ self.class.class_eval do
+ define_method(:included) do |receiver|
+ receiver.extend class_methods
+ end
+ end
+ end
- describe "#description" do
- it "should return the same description instance for each call" do
- example_group.description.should eql(example_group.description)
- end
+ @example_group.__send__ :include, mod
- it "should not add a space when description_text begins with #" do
- child_example_group = Class.new(example_group) do
- describe("#foobar", "Does something")
+ @example_group.mod_method
+ mod_method_called.should be_true
end
- child_example_group.description.should == "ExampleGroup#foobar Does something"
end
- it "should not add a space when description_text begins with ." do
- child_example_group = Class.new(example_group) do
- describe(".foobar", "Does something")
+ describe "#number_of_examples" do
+ it "should count number of examples" do
+ proc do
+ @example_group.it("one") {}
+ @example_group.it("two") {}
+ @example_group.it("three") {}
+ @example_group.it("four") {}
+ end.should change {@example_group.number_of_examples}.by(4)
end
- child_example_group.description.should == "ExampleGroup.foobar Does something"
- end
-
- it "should return the class name if nil" do
- example_group.set_description(nil)
- example_group.description.should =~ /Class:/
- end
-
- it "should return the class name if nil" do
- example_group.set_description("")
- example_group.description.should =~ /Class:/
- end
- end
-
- describe "#description_parts" do
- it "should return an Array of the current class description args" do
- example_group.description_parts.should == [example_group.description]
- end
-
- it "should return an Array of the description args from each class in the hierarchy" do
- child_example_group = Class.new(example_group)
- child_example_group.describe("Child", ExampleGroup)
- child_example_group.description.should_not be_empty
-
- grand_child_example_group = Class.new(child_example_group)
- grand_child_example_group.describe("GrandChild", ExampleGroup)
- grand_child_example_group.description.should_not be_empty
-
- grand_child_example_group.description_parts.should == [
- "ExampleGroup",
- "Child",
- Spec::Example::ExampleGroup,
- "GrandChild",
- Spec::Example::ExampleGroup
- ]
end
- end
- describe "#described_type" do
- it "should return passed in type" do
- child_example_group = Class.new(example_group) do
- describe Object
+ describe "#class_eval" do
+ it "should allow constants to be defined" do
+ example_group = Class.new(ExampleGroup) do
+ FOO = 1
+ it "should reference FOO" do
+ FOO.should == 1
+ end
+ end
+ success = example_group.run
+ success.should be_true
+ Object.const_defined?(:FOO).should == false
end
- child_example_group.described_type.should == Object
end
- it "should return #described_type of superclass when no passed in type" do
- parent_example_group = Class.new(ExampleGroup) do
- describe Object, "#foobar"
+ describe '#register' do
+ after(:each) do
+ example_group.unregister
end
- child_example_group = Class.new(parent_example_group) do
- describe "not a type"
+ it "should add ExampleGroup to set of ExampleGroups to be run" do
+ example_group.register
+ options.example_groups.should include(example_group)
end
- child_example_group.described_type.should == Object
end
- end
- describe "#remove_after" do
- it "should unregister a given after(:each) block" do
- after_all_ran = false
- @example_group.it("example") {}
- proc = Proc.new { after_all_ran = true }
- ExampleGroup.after(:each, &proc)
- @example_group.run
- after_all_ran.should be_true
-
- after_all_ran = false
- ExampleGroup.remove_after(:each, &proc)
- @example_group.run
- after_all_ran.should be_false
+ describe '#unregister' do
+ before(:each) do
+ example_group.register
+ end
+ it "should remove ExampleGroup from set of ExampleGroups to be run" do
+ example_group.unregister
+ options.example_groups.should_not include(example_group)
+ end
end
- end
-
- describe "#include" do
- it "should have accessible class methods from included module" do
- mod1_method_called = false
- mod1 = Module.new do
- extend Spec::MetaClass
- class_methods = Module.new do
- define_method :mod1_method do
- mod1_method_called = true
+
+ describe "#run" do
+ describe "given an example group with at least one example" do
+ it "should call add_example_group" do
+ example_group = Class.new(ExampleGroup) do
+ example("anything") {}
end
+ reporter.should_receive(:add_example_group)
+ example_group.run
end
+ end
- metaclass.class_eval do
- define_method(:included) do |receiver|
- receiver.extend class_methods
- end
+ describe "given an example group with no examples" do
+ it "should NOT call add_example_group" do
+ example_group = Class.new(ExampleGroup) do end
+ reporter.should_not_receive(:add_example_group)
+ example_group.run
end
end
+ end
- mod2_method_called = false
- mod2 = Module.new do
- extend Spec::MetaClass
- class_methods = Module.new do
- define_method :mod2_method do
- mod2_method_called = true
+ describe "#matcher_class=" do
+ it "should call new and matches? on the class used for matching examples" do
+ example_group = Class.new(ExampleGroup) do
+ it "should do something" do end
+ def self.specified_examples
+ ["something"]
end
- end
-
- metaclass.class_eval do
- define_method(:included) do |receiver|
- receiver.extend class_methods
+ def self.to_s
+ "TestMatcher"
end
end
- end
-
- @example_group.include mod1, mod2
- @example_group.mod1_method
- @example_group.mod2_method
- mod1_method_called.should be_true
- mod2_method_called.should be_true
- end
- end
+ matcher = mock("matcher")
+ matcher.should_receive(:matches?).with(["something"]).any_number_of_times
+
+ matcher_class = Class.new
+ matcher_class.should_receive(:new).with("TestMatcher", "should do something").twice.and_return(matcher)
- describe "#number_of_examples" do
- it "should count number of specs" do
- proc do
- @example_group.it("one") {}
- @example_group.it("two") {}
- @example_group.it("three") {}
- @example_group.it("four") {}
- end.should change {@example_group.number_of_examples}.by(4)
- end
- end
+ begin
+ ExampleGroupMethods.matcher_class = matcher_class
- describe "#class_eval" do
- it "should allow constants to be defined" do
- example_group = Class.new(ExampleGroup) do
- describe('example')
- FOO = 1
- it "should reference FOO" do
- FOO.should == 1
+ example_group.run
+ ensure
+ ExampleGroupMethods.matcher_class = ExampleMatcher
end
end
- example_group.run
- Object.const_defined?(:FOO).should == false
- end
- end
-
- describe '#register' do
- it "should add ExampleGroup to set of ExampleGroups to be run" do
- options.example_groups.delete(example_group)
- options.example_groups.should_not include(example_group)
-
- example_group.register {}
- options.example_groups.should include(example_group)
- end
- end
-
- describe '#unregister' do
- before do
- options.example_groups.should include(example_group)
end
- it "should remove ExampleGroup from set of ExampleGroups to be run" do
- example_group.unregister
- options.example_groups.should_not include(example_group)
- end
- end
-
- describe "#registration_backtrace" do
- it "returns the backtrace of where the ExampleGroup was registered" do
- example_group = Class.new(ExampleGroup)
- example_group.registration_backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-1}")
- end
- end
-
- describe "#run" do
- it "should add_example_group if there are any examples to run" do
- example_group = Class.new(ExampleGroup) do
- it "should do something" do end
- end
- reporter.should_receive(:add_example_group)
- example_group.run
- end
-
- it "should NOT add_example_group if there are no examples to run" do
- example_group = Class.new(ExampleGroup) do end
- reporter.should_not_receive(:add_example_group)
- example_group.run
+ describe "#options" do
+ it "should expose the options hash" do
+ group = describe("group", :this => 'hash') {}
+ group.options[:this].should == 'hash'
+ end
end
- end
- describe "#matcher_class=" do
- it "should call new and matches? on the class used for matching examples" do
- example_group = Class.new(ExampleGroup) do
- it "should do something" do end
- class << self
- def specified_examples
- ["something"]
- end
- def to_s
- "TestMatcher"
- end
+ describe "#backtrace" do
+ it "returns the backtrace from where the example group was defined" do
+ example_group = Class.new(ExampleGroup).describe("foo") do
+ example "bar" do; end
end
+ example_group.backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-3}")
end
+ end
- matcher = mock("matcher")
- matcher.should_receive(:matches?).with(["something"]).any_number_of_times
-
- matcher_class = Class.new
- matcher_class.should_receive(:new).with("TestMatcher", "should do something").twice.and_return(matcher)
-
- begin
- ExampleGroupMethods.matcher_class = matcher_class
+ describe "#example_group_backtrace (deprecated)" do
+ before(:each) do
+ Kernel.stub!(:warn)
+ end
+ it "sends a deprecation warning" do
+ example_group = Class.new(ExampleGroup) {}
+ Kernel.should_receive(:warn).with(/#example_group_backtrace.*deprecated.*#backtrace instead/m)
+ example_group.example_group_backtrace
+ end
- example_group.run
- ensure
- ExampleGroupMethods.matcher_class = ExampleMatcher
+ it "returns the backtrace from where the example group was defined" do
+ example_group = Class.new(ExampleGroup).describe("foo") do
+ example "bar" do; end
+ end
+ example_group.example_group_backtrace.join("\n").should include("#{__FILE__}:#{__LINE__-3}")
end
end
+
end
end
end
-end
+end
\ No newline at end of file