Permalink
Browse files

Refactoring docstring methods

  - extract modal docstring method
  - rename docstring -> indicative_docstring
  - remove unnecessary nil
  • Loading branch information...
1 parent 7072199 commit 6cf66a8f48f78a66b70b41986d00cabe86e47ca0 @rentalcustard committed May 17, 2011
Showing with 10 additions and 9 deletions.
  1. +10 −9 lib/rspec/matchers/generated_descriptions.rb
@@ -17,21 +17,16 @@ def self.generated_description
private
- def self.docstring(negative=false)
+ def self.indicative_docstring(negative=false)
if negative && last_matcher.respond_to?(:docstring_for_should_not)
last_matcher.docstring_for_should_not
elsif last_matcher.respond_to?(:docstring_for_should)
last_matcher.docstring_for_should
- else
- nil
end
end
- def self.last_description(negative=false)
- if RSpec.configuration.generated_docstring_format == :indicative && doc = docstring(negative)
- doc
- else
- last_matcher.respond_to?(:description) ? "#{last_should.to_s.sub("_", " ")} #{last_matcher.description}" : <<-MESSAGE
+ def self.modal_docstring
+ last_matcher.respond_to?(:description) ? "#{last_should.to_s.sub("_", " ")} #{last_matcher.description}" : <<-MESSAGE
When you call a matcher in an example without a String, like this:
specify { object.should matcher }
@@ -44,8 +39,14 @@ def self.last_description(negative=false)
add a String to the example this matcher is being used in, or give it a
description method. Then you won't have to suffer this lengthy warning again.
MESSAGE
+ end
+
+ def self.last_description(negative=false)
+ if RSpec.configuration.generated_docstring_format == :indicative
+ self.indicative_docstring(negative)
+ else
+ self.modal_docstring
end
end
end
end
-

0 comments on commit 6cf66a8

Please sign in to comment.