Class: RSpec::RubyContentMatchers::HaveCall

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

Direct Known Subclasses

HaveCalls

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

#alt_end, #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, #is_match?, #main_expr, #opt

Constructor Details

#initialize(method, options = {}) ⇒ HaveCall

Returns a new instance of HaveCall.



12
13
14
15
16
17
18
19
20
21
# File 'lib/code_spec/matchers/have_call.rb', line 12

def initialize(method, options = {})
  @method = method.to_s
  @args = case options
  when Hash 
    options[:args] 
  else 
    options
  end
  @dot = options[:dot]
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



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

def args
  @args
end

#contentObject (readonly)

Returns the value of attribute content.



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

def content
  @content
end

#dotObject (readonly)

Returns the value of attribute dot.



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

def dot
  @dot
end

#methodObject (readonly)

Returns the value of attribute method.



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

def method
  @method
end

Instance Method Details

#failure_messageObject



37
38
39
40
# File 'lib/code_spec/matchers/have_call.rb', line 37

def failure_message
  super
  "Expected there to be a call to #{method}#{args_msg}, but there wasn't"
end

#matches?(content) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/code_spec/matchers/have_call.rb', line 23

def matches?(content)
  @content = content 
  has_def = (content =~ /def(.*)#{method}/)
  expr = if has_def || dot == :form
    /#{dot_expr}#{method}#{args_expr}/m        
  else
    /#{dot_expr}?#{method}#{args_expr}/m
  end   
  debug "expr = #{expr}"
  debug "content = %{#{content}}"
  debug "content =~ #{expr}"      
  (content =~ expr)
end

#negative_failure_messageObject



42
43
44
45
# File 'lib/code_spec/matchers/have_call.rb', line 42

def negative_failure_message
  super
  "Did not expect there to be a call to #{method}#{args_msg}, but there was"
end