Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add support for docstrings method

  • Loading branch information...
commit 48e8fe59c6f5b56e997e7fac86cac730450ac168 1 parent fad075c
Tom Stuart authored
Showing with 12 additions and 3 deletions.
  1. +12 −3 lib/rspec/matchers/generated_descriptions.rb
15 lib/rspec/matchers/generated_descriptions.rb
View
@@ -11,13 +11,21 @@ def self.clear_generated_description
def self.generated_description
return nil if last_should.nil?
- "#{last_should.to_s.gsub('_',' ')} #{last_description}"
+ negative = last_should.to_s =~ /not/
+ last_description(negative)
end
private
- def self.last_description
- last_matcher.respond_to?(:description) ? last_matcher.description : <<-MESSAGE
+ def self.last_description(negative=false)
+ 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:
specify { object.should matcher }
@@ -30,6 +38,7 @@ def self.last_description
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
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.