Class: RSpec::RubyContentMatchers::InheritFrom

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ InheritFrom

Returns a new instance of InheritFrom.



7
8
9
# File 'lib/rspec_for_generators/matchers/content/inherit_from.rb', line 7

def initialize(content)
  @klass = klass
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



5
6
7
# File 'lib/rspec_for_generators/matchers/content/inherit_from.rb', line 5

def klass
  @klass
end

Instance Method Details

#failure_messageObject



20
21
22
# File 'lib/rspec_for_generators/matchers/content/inherit_from.rb', line 20

def failure_message
  "Expected the class to inherit from #{klass}"
end

#matches?(content) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
# File 'lib/rspec_for_generators/matchers/content/inherit_from.rb', line 11

def matches?(content)      
  @content = content
  @content =~ /class\s+(.*?)<\s+#{klass}(.*)end/
  if block_given?
    ruby_content = $2.strip.extend(RSpec::RubyContent::Helpers)
    yield ruby_content
  end
end

#negative_failure_messageObject



24
25
26
# File 'lib/rspec_for_generators/matchers/content/inherit_from.rb', line 24

def negative_failure_message
  "Did not expect the class to inherit from #{klass}"
end