Permalink
Browse files

Improved test case descriptions and cleaned up spec docs

  • Loading branch information...
1 parent 7e07fc5 commit c3c208daa26cd285de11e6c4676bc3eed50975dd @glv committed Sep 13, 2010
Showing with 20 additions and 18 deletions.
  1. +2 −3 lib/rspec/unit/test_case.rb
  2. +18 −15 spec/test_case_spec.rb
@@ -62,7 +62,7 @@ def self.to_s
def self.test_case_name(klass)
class_name = klass.name
- (class_name.nil? || class_name.empty?) ? 'Anonymous TestCase' : "TestCase #{class_name}"
+ (class_name.nil? || class_name.empty?) ? '<Anonymous TestCase>' : class_name
end
def self.caller_lines
@@ -100,9 +100,8 @@ def self.number_of_tests
def self.tests
@tests ||= test_methods.sort.map do |m|
- name = "#{display_name}##{m}"
meta = (test_method_metadata[m] || {}).merge({:caller => caller_lines[m],
- :full_description => name,
+ :full_description => "#{display_name}##{m}",
:test_unit => true})
Core::Example.new(self, m, meta, proc{execute(m)})
end
View
@@ -48,13 +48,21 @@ def test_bar; end
@foo.examples.should be_empty
end
- it "ignores methods with good names but positive arity" do
+ it "ignores methods with good names but requiring parameters" do
@foo.class_eval do
def test_foo(a); end
def test_bar(a, *b); end
end
@foo.examples.should be_empty
end
+
+ it "notices methods that have only optional parameters" do
+ @foo.class_eval do
+ def test_foo(*a); end
+ end
+ @foo.examples.size.should == 1
+ @foo.examples.first.metadata[:description].should == 'test_foo'
+ end
it "creates an example to represent a test method" do
@foo.class_eval do
@@ -197,17 +205,12 @@ class SampleTestCaseForName < RSpec::Unit::TestCase
end
end
- it "sets :description to 'TestCase' and the class name if the class has one" do
- SampleTestCaseForName.metadata[:example_group][:description].should == "TestCase SampleTestCaseForName"
- end
-
- it "sets :description to 'Anonymous TestCase' for anonymous test classes" do
- @foo.metadata[:example_group][:description].should == "Anonymous TestCase"
+ it "sets :description to the class name if the class has a name" do
+ SampleTestCaseForName.metadata[:example_group][:description].should == "SampleTestCaseForName"
end
- it "sets :full_description to be the same as :description" do
- @foo.metadata[:example_group][:full_description].should == @foo.metadata[:example_group][:description]
- SampleTestCaseForName.metadata[:example_group][:full_description].should == SampleTestCaseForName.metadata[:example_group][:description]
+ it "sets :description to '<Anonymous TestCase>' for anonymous test classes" do
+ @foo.metadata[:example_group][:description].should == "<Anonymous TestCase>"
end
it "adds :test_unit => true" do
@@ -236,7 +239,7 @@ class SampleTestCaseForName < RSpec::Unit::TestCase
@foo.metadata[:example_group][:describes].should be_nil
end
- it "records test_case_info options" do
+ it "records test_case_info metadata" do
@foo.class_eval do
test_case_info :foo => :bar
end
@@ -260,11 +263,11 @@ def test_baz; end
@foo.examples.first.metadata[:description].should == 'test_baz'
end
- it "uses a test method's name with the class name as its :full_description" do
+ it "sets the test method's :full_description to ClassName#method_name" do
@foo.class_eval do
def test_baz; end
end
- test_baz_metadata[:full_description].should == 'Anonymous TestCase#test_baz'
+ test_baz_metadata[:full_description].should == "#{@foo.metadata[:example_group][:description]}#test_baz"
end
it "adds :test_unit => true" do
@@ -312,15 +315,15 @@ def test_baz; end
test_baz_metadata[:caller].size.should == caller.size + 3
end
- it "records test_info options for next test method" do
+ it "records test_info metadata for next test method" do
@foo.class_eval do
test_info :foo => :bar
def test_baz; end
end
test_baz_metadata[:foo].should == :bar
end
- it "records test_info options *only* for next test method" do
+ it "records test_info metadata *only* for next test method" do
@foo.class_eval do
test_info :foo => :bar
def test_baz; end

0 comments on commit c3c208d

Please sign in to comment.