Class: RSpec::RubyContentMatchers::HaveMethods

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

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_msg, #comment_end, #debug, #debug?, #debug_content, #end_expr, #get_expr, #handle_result, #indexes, #opt

Constructor Details

#initialize(*methods) ⇒ HaveMethods

Returns a new instance of HaveMethods.



12
13
14
15
16
17
# File 'lib/code_spec/matchers/multi/have_methods.rb', line 12

def initialize *methods
  options = last_option methods
  @names = methods.to_strings
  @type = options[:type]
  @args = options[:args]
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



10
11
12
# File 'lib/code_spec/matchers/multi/have_methods.rb', line 10

def args
  @args
end

#methodObject (readonly)

Returns the value of attribute method.



10
11
12
# File 'lib/code_spec/matchers/multi/have_methods.rb', line 10

def method
  @method
end

#namesObject (readonly)

Returns the value of attribute names.



10
11
12
# File 'lib/code_spec/matchers/multi/have_methods.rb', line 10

def names
  @names
end

#typeObject (readonly)

Returns the value of attribute type.



10
11
12
# File 'lib/code_spec/matchers/multi/have_methods.rb', line 10

def type
  @type
end

Instance Method Details

#failure_messageObject



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

def failure_message
  super
  "Expected there to be the #{class_msg} method #{method}, but there wasn't"
end

#indexObject



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

def index
  1
end

#is_match?(content) ⇒ Boolean

Returns:

  • (Boolean)


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

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)


19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/code_spec/matchers/multi/have_methods.rb', line 19

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

  @content = content
  names.each do |name|       
    @method = name     
    @end_option = name        
    match = is_match? content
    return false if !match
  end
  true
end

#negative_failure_messageObject



49
50
51
52
# File 'lib/code_spec/matchers/multi/have_methods.rb', line 49

def negative_failure_message                                      
  super
  "Did not expect there to be the #{class_msg} method #{method}, but there was"
end