Class: RSpec::RubyContentMatchers::HaveModules

Inherits:
RSpec::RubyContentMatcher show all
Defined in:
lib/code_spec/matchers/multi/have_classes_modules.rb

Direct Known Subclasses

HaveClasses, HaveSubClasses

Constant Summary

Constants inherited from RSpec::RubyContentMatcher

RSpec::RubyContentMatcher::ANY_GROUP, RSpec::RubyContentMatcher::LPAR, RSpec::RubyContentMatcher::OPT_ARGS, RSpec::RubyContentMatcher::OPT_SPACES, RSpec::RubyContentMatcher::Q_ANY_GROUP, RSpec::RubyContentMatcher::RPAR, RSpec::RubyContentMatcher::SPACES

Instance Attribute Summary collapse

Attributes inherited from RSpec::RubyContentMatcher

#content, #content_matches, #end_option

Instance Method Summary collapse

Methods inherited from RSpec::RubyContentMatcher

#any_args_expr, #args_expr, #args_msg, #comment_end, #debug, #debug?, #debug_content, #end_expr, #get_expr, #handle_result, #index, #indexes, #opt

Constructor Details

#initialize(*names) ⇒ HaveModules

Returns a new instance of HaveModules.



5
6
7
8
9
10
# File 'lib/code_spec/matchers/multi/have_classes_modules.rb', line 5

def initialize(*names)
  postfix = last_arg_value({:postfix => ''}, names)
  @names = names.to_strings  
  @postfix = postfix ? postfix.to_s.camelize : nil
  @type = :module
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/code_spec/matchers/multi/have_classes_modules.rb', line 3

def name
  @name
end

#namesObject (readonly)

Returns the value of attribute names.



3
4
5
# File 'lib/code_spec/matchers/multi/have_classes_modules.rb', line 3

def names
  @names
end

#postfixObject (readonly)

Returns the value of attribute postfix.



3
4
5
# File 'lib/code_spec/matchers/multi/have_classes_modules.rb', line 3

def postfix
  @postfix
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/code_spec/matchers/multi/have_classes_modules.rb', line 3

def type
  @type
end

Instance Method Details

#failure_messageObject



39
40
41
42
# File 'lib/code_spec/matchers/multi/have_classes_modules.rb', line 39

def failure_message
  super
  "Expected there to be the #{type} #{name}"
end

#is_match?(content) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
# File 'lib/code_spec/matchers/multi/have_classes_modules.rb', line 31

def is_match? content
  expr = get_expr(content) 
  debug "match expression: #{expr}"
  match = (content =~ expr)
  @content_matches = [$1, $2, $3]
  match
end

#matches?(content, &block) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/code_spec/matchers/multi/have_classes_modules.rb', line 12

def matches? content, &block
  return false if names.empty?

  @content = content

  return false if names.empty?

  names.each do |name|       
    @name = name.camelize     
    @klass = name.camelize
    @full_class = "#{@klass}#{@postfix}" 
    
    @end_option = name        
    match = is_match? content
    return false if !match
  end
  true
end

#negative_failure_messageObject



44
45
46
47
# File 'lib/code_spec/matchers/multi/have_classes_modules.rb', line 44

def negative_failure_message
  super
  "Did not expected there to be the #{type} #{name}"
end