Class: RSpec::RubyContentMatchers::InheritFrom

Inherits:
RSpec::RubyContentMatcher show all
Defined in:
lib/generator_spec/matchers/content/inherit_from.rb

Instance Attribute Summary collapse

Attributes inherited from RSpec::RubyContentMatcher

#content

Instance Method Summary collapse

Methods inherited from RSpec::RubyContentMatcher

#debug_content

Constructor Details

#initialize(klass) ⇒ InheritFrom

Returns a new instance of InheritFrom.



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

def initialize klass
  @klass = klass.to_s.camelize
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



3
4
5
# File 'lib/generator_spec/matchers/content/inherit_from.rb', line 3

def klass
  @klass
end

Instance Method Details

#failure_messageObject



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

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

#matches?(content) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#negative_failure_messageObject



25
26
27
28
# File 'lib/generator_spec/matchers/content/inherit_from.rb', line 25

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