Class: RSpec::RubyContentMatchers::HaveModule

Inherits:
RSpec::RubyContentMatcher show all
Defined in:
lib/generator_spec/matchers/content/have_module.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(module_name) ⇒ HaveModule

Returns a new instance of HaveModule.



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

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

Instance Attribute Details

#module_nameObject (readonly)

Returns the value of attribute module_name.



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

def module_name
  @module_name
end

Instance Method Details

#failure_messageObject



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

def failure_message
  super
  "Expected there to be the module #{module_name}"
end

#matches?(content) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches?(content)            
  super
  match_res =~ /module\s+#{module_name}\s+(.*)end/m
  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/have_module.rb', line 25

def negative_failure_message
  super
  "Did no expected there to be the module #{module_name}"
end