Skip to content
Browse files

add support for defining examples using def test_xxx

  • Loading branch information...
1 parent fcd564e commit d523321b7b90c1940991f931a13db99b28a64aac @dchelimsky dchelimsky committed May 22, 2011
Showing with 20 additions and 0 deletions.
  1. +6 −0 lib/rspec/core/example_group.rb
  2. +14 −0 spec/rspec/core/example_group_spec.rb
View
6 lib/rspec/core/example_group.rb
@@ -308,6 +308,12 @@ def self.set_ivars(instance, ivars)
ivars.each {|name, value| instance.instance_variable_set(name, value)}
end
+ def self.method_added(m)
+ if m.to_s =~ /test_(.*)/
+ example($1) { method(m).call }
+ end
+ end
+
def described_class
self.class.described_class
end
View
14 spec/rspec/core/example_group_spec.rb
@@ -906,5 +906,19 @@ def foo; 'foo'; end
end
end
+ describe "a method starting with test_" do
+ it "is generates an an example" do
+ group = ExampleGroup.describe do
+ def test_something_that_fails
+ 1.should eq(2)
+ end
+ end
+
+ group.examples.length.should eq(1)
+ group.examples.first.description.should eq('something_that_fails')
+ group.run.should be_false, "expected a failure"
+ end
+ end
+
end
end

0 comments on commit d523321

Please sign in to comment.
Something went wrong with that request. Please try again.