Skip to content

Commit

Permalink
Add support for docstrings method
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Stuart committed May 13, 2011
1 parent fad075c commit 48e8fe5
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/rspec/matchers/generated_descriptions.rb
Expand Up @@ -11,13 +11,21 @@ def self.clear_generated_description


def self.generated_description def self.generated_description
return nil if last_should.nil? return nil if last_should.nil?
"#{last_should.to_s.gsub('_',' ')} #{last_description}" negative = last_should.to_s =~ /not/
last_description(negative)
end end


private private


def self.last_description def self.last_description(negative=false)
last_matcher.respond_to?(:description) ? last_matcher.description : <<-MESSAGE if last_matcher.respond_to?(:docstrings)
if negative
last_matcher.docstrings[:negative]
else
last_matcher.docstrings[:positive]
end
else
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: When you call a matcher in an example without a String, like this:
specify { object.should matcher } specify { object.should matcher }
Expand All @@ -30,6 +38,7 @@ def self.last_description
add a String to the example this matcher is being used in, or give it a 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. description method. Then you won't have to suffer this lengthy warning again.
MESSAGE MESSAGE
end
end end
end end
end end
Expand Down

0 comments on commit 48e8fe5

Please sign in to comment.