class Saharspec::Matchers::SendMessage
@private
Public Class Methods
new(target, method)
click to toggle source
# File lib/saharspec/matchers/send_message.rb, line 10 def initialize(target, method) @target = target @method = method end
Public Instance Methods
calling_original()
click to toggle source
# File lib/saharspec/matchers/send_message.rb, line 26 def calling_original @call_original = true self end
description()
click to toggle source
# File lib/saharspec/matchers/send_message.rb, line 73 def description format('send %p.%s', @target, @method) end
does_not_match?(subject)
click to toggle source
# File lib/saharspec/matchers/send_message.rb, line 62 def does_not_match?(subject) run(subject) expect(@target).not_to expectation true end
exactly(n)
click to toggle source
# File lib/saharspec/matchers/send_message.rb, line 31 def exactly(n) @times = n self end
failure_message()
click to toggle source
# File lib/saharspec/matchers/send_message.rb, line 77 def failure_message "expected #{description}, but sent nothing" end
failure_message_when_negated()
click to toggle source
# File lib/saharspec/matchers/send_message.rb, line 81 def failure_message_when_negated "expected not #{description}, but sent it" end
matches?(subject)
click to toggle source
Matching
# File lib/saharspec/matchers/send_message.rb, line 56 def matches?(subject) run(subject) expect(@target).to expectation true end
once()
click to toggle source
# File lib/saharspec/matchers/send_message.rb, line 42 def once exactly(1) end
ordered()
click to toggle source
# File lib/saharspec/matchers/send_message.rb, line 50 def ordered @ordered = true self end
returning(*res)
click to toggle source
# File lib/saharspec/matchers/send_message.rb, line 21 def returning(*res) @res = [*res] self end
supports_block_expectations?()
click to toggle source
Static properties
# File lib/saharspec/matchers/send_message.rb, line 69 def supports_block_expectations? true end
times()
click to toggle source
# File lib/saharspec/matchers/send_message.rb, line 36 def times fail NoMethodError unless @times self end
twice()
click to toggle source
# File lib/saharspec/matchers/send_message.rb, line 46 def twice exactly(2) end
with(*arguments)
click to toggle source
DSL
# File lib/saharspec/matchers/send_message.rb, line 16 def with(*arguments) @arguments = arguments self end
Private Instance Methods
allower()
click to toggle source
# File lib/saharspec/matchers/send_message.rb, line 95 def allower receive(@method).tap do |a| a.and_return(*@res) if @res a.and_call_original if @call_original end end
expectation()
click to toggle source
# File lib/saharspec/matchers/send_message.rb, line 102 def expectation have_received(@method).tap do |e| e.with(*@arguments) if @arguments e.exactly(@times).times if @times e.ordered if @ordered end end
run(subject)
click to toggle source
# File lib/saharspec/matchers/send_message.rb, line 87 def run(subject) @target.respond_to?(@method, true) or fail NoMethodError, "undefined method `#{@method}' for#{@target.inspect}:#{@target.class}" allow(@target).to allower subject.call end