Class: RSpec::RubyContentMatchers::HaveMethod
- Inherits:
-
RSpec::RubyContentMatcher
- Object
- RSpec::RubyContentMatcher
- RSpec::RubyContentMatchers::HaveMethod
- Defined in:
- lib/generator_spec/matchers/content/have_method.rb
Instance Attribute Summary collapse
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes inherited from RSpec::RubyContentMatcher
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(method, type = nil) ⇒ HaveMethod
constructor
A new instance of HaveMethod.
- #matches?(content) ⇒ Boolean
- #negative_failure_message ⇒ Object
Methods inherited from RSpec::RubyContentMatcher
Constructor Details
#initialize(method, type = nil) ⇒ HaveMethod
Returns a new instance of HaveMethod.
12 13 14 15 |
# File 'lib/generator_spec/matchers/content/have_method.rb', line 12 def initialize(method, type=nil) @method = method.to_s @type = type end |
Instance Attribute Details
#method ⇒ Object (readonly)
Returns the value of attribute method.
10 11 12 |
# File 'lib/generator_spec/matchers/content/have_method.rb', line 10 def method @method end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
10 11 12 |
# File 'lib/generator_spec/matchers/content/have_method.rb', line 10 def type @type end |
Instance Method Details
#failure_message ⇒ Object
33 34 35 36 37 |
# File 'lib/generator_spec/matchers/content/have_method.rb', line 33 def super 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
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/generator_spec/matchers/content/have_method.rb', line 17 def matches?(content) super match_res = case type when :class content =~ /def\s+self.#{method}#{args_expr}(.*?)#{end_expr}/m else content =~ /def\s+#{method}#{args_expr}(.*?)#{end_expr}/m end if block_given? && $2 ruby_content = $2.strip.extend(RSpec::RubyContent::Helpers) ruby_content << "\nend" if !(ruby_content =~ /\nend$/) yield ruby_content end match_res end |
#negative_failure_message ⇒ Object
39 40 41 42 43 |
# File 'lib/generator_spec/matchers/content/have_method.rb', line 39 def super return "Did not expect there to be the class method #{method}, but there was" if type == :class "Did not expect there to be the method #{method}, but there was" end |