Class: RSpec::RubyContentMatchers::HaveCall
- Inherits:
-
RSpec::RubyContentMatcher
- Object
- RSpec::RubyContentMatcher
- RSpec::RubyContentMatchers::HaveCall
- Defined in:
- lib/code_spec/matchers/have_call.rb
Direct Known Subclasses
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
-
#args ⇒ Object
Returns the value of attribute args.
-
#content ⇒ Object
Returns the value of attribute content.
-
#dot ⇒ Object
Returns the value of attribute dot.
-
#method_name ⇒ Object
Returns the value of attribute method_name.
Attributes inherited from RSpec::RubyContentMatcher
#alt_end, #content_matches, #end_option
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(method_name, options = {}) ⇒ HaveCall
constructor
A new instance of HaveCall.
- #matches?(content) ⇒ Boolean
- #negative_failure_message ⇒ Object
Methods inherited from RSpec::RubyContentMatcher
#any_args_expr, #args_expr, #args_msg, #comment_end, #debug, #debug?, #debug_content, #display, #display_content, #end_expr, #get_expr, #handle_result, #index, #indexes, #is_match?, #main_expr, #opt
Constructor Details
#initialize(method_name, options = {}) ⇒ HaveCall
Returns a new instance of HaveCall.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/code_spec/matchers/have_call.rb', line 12 def initialize(method_name, = {}) @method_name = method_name.to_s @args = case when Hash @dot = [:dot] [:args] else ( == {}) ? nil : end @args = ":#{args}" if args.kind_of? Symbol end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
10 11 12 |
# File 'lib/code_spec/matchers/have_call.rb', line 10 def args @args end |
#content ⇒ Object
Returns the value of attribute content.
10 11 12 |
# File 'lib/code_spec/matchers/have_call.rb', line 10 def content @content end |
#dot ⇒ Object
Returns the value of attribute dot.
10 11 12 |
# File 'lib/code_spec/matchers/have_call.rb', line 10 def dot @dot end |
#method_name ⇒ Object
Returns the value of attribute method_name.
10 11 12 |
# File 'lib/code_spec/matchers/have_call.rb', line 10 def method_name @method_name end |
Instance Method Details
#failure_message ⇒ Object
57 58 59 60 |
# File 'lib/code_spec/matchers/have_call.rb', line 57 def super display "Expected there to be a call to #{method_name}#{args_msg}, but there wasn't." end |
#matches?(content) ⇒ Boolean
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/code_spec/matchers/have_call.rb', line 25 def matches?(content) @content = content def_pos = (content =~ /def(.*)#{method_name}/) || 999 call_pos = (content =~ /[^def]?#{method_name}/) || 999 arguments_expr = case @args when String args_expr when Array args.flatten.inject("") do |res, arg| arg_val = (arg.kind_of?(String) && arg[0] == '#') ? arg[1..-1] : arg.inspect res << '(\s|,|\w|:)*' + arg_val end when NilClass "" else @special_error = "Unknown arguments: #{args.inspect}" return nil end expr = if (def_pos < call_pos) || dot == :form /#{dot_expr}#{method_name}#{arguments_expr}/m else /#{dot_expr}?#{method_name}#{arguments_expr}/m end @expr = expr debug "expr = #{expr}" debug "content = %{#{content}}" debug "content =~ #{expr}" (content =~ expr) end |
#negative_failure_message ⇒ Object
62 63 64 65 |
# File 'lib/code_spec/matchers/have_call.rb', line 62 def super display "Did not expect there to be a call to #{method_name}#{args_msg}, but there was" end |