Skip to content

Commit

Permalink
Refactoring docstring methods
Browse files Browse the repository at this point in the history
  - extract modal docstring method
  - rename docstring -> indicative_docstring
  - remove unnecessary nil
  • Loading branch information
Tom Stuart committed May 17, 2011
1 parent 7072199 commit 6cf66a8
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/rspec/matchers/generated_descriptions.rb
Expand Up @@ -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 }
Expand All @@ -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.