Class: NotAMock::Matchers::ResultMatcher

Inherits:
CallMatcher show all
Defined in:
lib/not_a_mock/matchers/result_matcher.rb

Overview

Matcher for

and_returned(...)

Instance Attribute Summary

Attributes inherited from CallMatcher

#calls

Instance Method Summary collapse

Methods inherited from CallMatcher

#and_returned, #exactly, #failure_message, #matched?, #matches?, #negative_failure_message, #once, #twice, #with, #without_args

Constructor Details

#initialize(result, parent = nil) ⇒ ResultMatcher

Returns a new instance of ResultMatcher.



9
10
11
12
# File 'lib/not_a_mock/matchers/result_matcher.rb', line 9

def initialize(result, parent = nil)
  super parent
  @result = result
end

Instance Method Details

#failure_message_without_parentsObject



19
20
21
22
23
24
25
# File 'lib/not_a_mock/matchers/result_matcher.rb', line 19

def failure_message_without_parents
  if matched?
    ", and returned #{@result.inspect}"
  else
    ", but didn't return #{@result.inspect}"
  end
end

#matches_without_parents?Boolean

Returns:

  • (Boolean)


14
15
16
17
# File 'lib/not_a_mock/matchers/result_matcher.rb', line 14

def matches_without_parents?
  @calls = @parent.calls.select {|entry| entry[:result] == @result }
  !@calls.empty?
end