Skip to content

Commit

Permalink
add support for defining examples using def test_xxx
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed May 23, 2011
1 parent fcd564e commit d523321
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/rspec/core/example_group.rb
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions spec/rspec/core/example_group_spec.rb
Expand Up @@ -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.