Class: RSpec::RubyContentMatchers::HaveSubclass

Inherits:
RSpec::RubyContentMatcher show all
Defined in:
lib/generator_spec/matchers/content/have_subclass.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, superclass, type = nil) ⇒ HaveSubclass

Returns a new instance of HaveSubclass.



5
6
7
8
9
# File 'lib/generator_spec/matchers/content/have_subclass.rb', line 5

def initialize(klass, superclass, type=nil)
  @klass      = klass.to_s.camelize
  @superclass = superclass.to_s.camelize
  @type       = type.to_s.camelize if type      
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



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

def klass
  @klass
end

#superclassObject (readonly)

Returns the value of attribute superclass.



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

def superclass
  @superclass
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#failure_messageObject



22
23
24
25
# File 'lib/generator_spec/matchers/content/have_subclass.rb', line 22

def failure_message  
  super
  "Expected there to be the subclass #{klass} of #{superclass}"
end

#matches?(content) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
# File 'lib/generator_spec/matchers/content/have_subclass.rb', line 11

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

#negative_failure_messageObject



27
28
29
30
# File 'lib/generator_spec/matchers/content/have_subclass.rb', line 27

def negative_failure_message
  super
  "Did no expected there to be the subclass #{klass} of #{superclass}"
end