Class: RSpec::RubyContentMatchers::HaveCalls

Inherits:
RSpec::RubyContentMatcher show all
Defined in:
lib/generator_spec/matchers/content/have_calls.rb

Instance Attribute Summary collapse

Attributes inherited from RSpec::RubyContentMatcher

#content

Instance Method Summary collapse

Methods inherited from RSpec::RubyContentMatcher

#debug_content

Constructor Details

#initialize(calls) ⇒ HaveCalls

Returns a new instance of HaveCalls.



5
6
7
# File 'lib/generator_spec/matchers/content/have_calls.rb', line 5

def initialize(calls)
  @calls = calls
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



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

def args
  @args
end

#callsObject (readonly)

Returns the value of attribute calls.



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

def calls
  @calls
end

#methodObject (readonly)

Returns the value of attribute method.



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

def method
  @method
end

Instance Method Details

#failure_messageObject



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

def failure_message
  super
  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)


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

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

#negative_failure_messageObject



25
26
27
28
29
# File 'lib/generator_spec/matchers/content/have_calls.rb', line 25

def negative_failure_message 
  super
  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