Class: RSpec::RubyContentMatchers::HaveClass

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ HaveClass

Returns a new instance of HaveClass.



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

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

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



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

def klass
  @klass
end

Instance Method Details

#failure_messageObject



22
23
24
# File 'lib/rspec_for_generators/matchers/content/have_class.rb', line 22

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

#matches?(content) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#negative_failure_messageObject



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

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