Class: RSpec::RubyContentMatchers::HaveMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_for_generators/matchers/content/have_method.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#methodObject (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_messageObject



29
30
31
32
# File 'lib/rspec_for_generators/matchers/content/have_method.rb', line 29

def failure_message
  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

Returns:

  • (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_messageObject



34
35
36
37
# File 'lib/rspec_for_generators/matchers/content/have_method.rb', line 34

def negative_failure_message                                      
  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