Class: RSpec::RubyContentMatchers::HaveCalls

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec_for_generators/matchers/content/have_calls.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(calls) ⇒ HaveCalls

Returns a new instance of HaveCalls.



6
7
8
# File 'lib/rspec_for_generators/matchers/content/have_calls.rb', line 6

def initialize(calls)
  @calls = calls
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



4
5
6
# File 'lib/rspec_for_generators/matchers/content/have_calls.rb', line 4

def args
  @args
end

#callsObject (readonly)

Returns the value of attribute calls.



3
4
5
# File 'lib/rspec_for_generators/matchers/content/have_calls.rb', line 3

def calls
  @calls
end

#methodObject

Returns the value of attribute method.



4
5
6
# File 'lib/rspec_for_generators/matchers/content/have_calls.rb', line 4

def method
  @method
end

Instance Method Details

#failure_messageObject



19
20
21
22
# File 'lib/rspec_for_generators/matchers/content/have_calls.rb', line 19

def failure_message
  return "Expected there to be a call to #{method} with args #{args}, but there wasn't" if args
  "Expected there to be a call to #{method}, but there wasn't"
end

#matches?(content) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
15
16
17
# File 'lib/rspec_for_generators/matchers/content/have_calls.rb', line 10

def matches?(content)
  calls.each_pair do |method, args|
    @method = method
    @args = args
    return false if (content =~ /#{method}\s+#{args_expr}/m) == nil
  end
  true
end

#negative_failure_messageObject



24
25
26
27
# File 'lib/rspec_for_generators/matchers/content/have_calls.rb', line 24

def negative_failure_message                                      
  return "Did not expect there to be a call to #{method} with args #{args}, but there was" if args
  "Did not expect there to be a call to #{method}, but there was"
end