Class: RSpec::RubyContentMatchers::HaveMethod
- Inherits:
-
Object
- Object
- RSpec::RubyContentMatchers::HaveMethod
- Defined in:
- lib/rspec_for_generators/matchers/content/have_method.rb
Instance Attribute Summary collapse
-
#method ⇒ Object
readonly
Returns the value of attribute method.
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(method, type) ⇒ HaveMethod
constructor
A new instance of HaveMethod.
- #matches?(content) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(method, type) ⇒ HaveMethod
Returns a new instance of HaveMethod.
14 15 16 17 |
# File 'lib/rspec_for_generators/matchers/content/have_method.rb', line 14 def initialize(method, type) @type = type @method = method.to_s end |
Instance Attribute Details
#method ⇒ Object (readonly)
Returns the value of attribute method.
12 13 14 |
# File 'lib/rspec_for_generators/matchers/content/have_method.rb', line 12 def method @method end |
Instance Method Details
#failure_message ⇒ Object
29 30 31 32 |
# File 'lib/rspec_for_generators/matchers/content/have_method.rb', line 29 def return "Expected there to be the class method #{method}, but there wasn't" if @type == :class "Expected there to be the method #{method}, but there wasn't" end |
#matches?(content) ⇒ Boolean
19 20 21 22 23 24 25 26 27 |
# File 'lib/rspec_for_generators/matchers/content/have_method.rb', line 19 def matches?(content) @content = content case @type when :class @content =~ /def\s+self.#{method}\s*(\(.+\))?(.*?)/m else @content =~ /def\s+#{method}\s*(\(.+\))?(.*?)/m end end |
#negative_failure_message ⇒ Object
34 35 36 37 |
# File 'lib/rspec_for_generators/matchers/content/have_method.rb', line 34 def return "Did not expect there to be the method #{method}, but there was" if @type == :class "Did not expect there to be the method #{method}, but there was" end |