Permalink
Browse files

strip Test, Spec, or Describe from class name

  • Loading branch information...
dchelimsky committed May 22, 2011
1 parent d523321 commit c1b2b00c94c778e46b8f6c6ba6426030b82e8c1f
Showing with 14 additions and 1 deletion.
  1. +5 −1 lib/rspec/core/example_group.rb
  2. +9 −0 spec/rspec/core/example_group_spec.rb
@@ -128,7 +128,7 @@ def self.describe(*args, &example_group_block)
def self.inherited(child)
child.register if child.top_level?
- child.set_it_up(*$initialization_args)
+ child.set_it_up(*$initialization_args || [subject_for(child.name)])
children << child
end
@@ -314,6 +314,10 @@ def self.method_added(m)
end
end
+ def self.subject_for(name)
+ name.gsub(/(^Describe|Spec|Test)/,'')
+ end
+
def described_class
self.class.described_class
end
@@ -920,5 +920,14 @@ def test_something_that_fails
end
end
+ describe "#subject_for" do
+ it "removes Test or Spec, or Describe from the name" do
+ group = ExampleGroup.describe
+ group.subject_for('FooTest').should eq('Foo')
+ group.subject_for('FooSpec').should eq('Foo')
+ group.subject_for('DescribeFoo').should eq('Foo')
+ end
+ end
+
end
end

0 comments on commit c1b2b00

Please sign in to comment.