Class: RSpec::RubyContentMatchers::HaveClass

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

Returns a new instance of HaveClass.



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

def initialize(klass, type=nil)
  @klass = klass.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_class.rb', line 3

def klass
  @klass
end

#typeObject (readonly)

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#end_exprObject



30
31
32
# File 'lib/generator_spec/matchers/content/have_class.rb', line 30

def end_expr
  "(end|# #{klass})"
end

#failure_messageObject



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

def failure_message 
  super
  "Expected there to be the class #{klass}"
end

#matches?(content) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#negative_failure_messageObject



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

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