Class: RSpec::Mocks::TargetBase

Inherits:
Object
  • Object
show all
Defined in:
lib/rspec/mocks/targets.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target) ⇒ TargetBase

Returns a new instance of TargetBase.



7
8
9
# File 'lib/rspec/mocks/targets.rb', line 7

def initialize(target)
  @target = target
end

Class Method Details

.delegate_to(matcher_method, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rspec/mocks/targets.rb', line 11

def self.delegate_to(matcher_method, options = {})
  method_name = options.fetch(:from) { :to }
  class_eval("  def \#{method_name}(matcher, &block)\n    unless Matchers::Receive === matcher\n      raise UnsupportedMatcherError, \"only the `receive` matcher is supported \" +\n        \"with `\\\#{expression}(...).\\\#{\#{method_name.inspect}}`, but you have provided: \\\#{matcher}\"\n    end\n\n    matcher.__send__(\#{matcher_method.inspect}, @target, &block)\n  end\n  RUBY\nend\n", __FILE__, __LINE__ + 1)

.disallow_negation(method) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/rspec/mocks/targets.rb', line 25

def self.disallow_negation(method)
  define_method method do |*args|
    raise NegationUnsupportedError,
      "`#{expression}(...).#{method} receive` is not supported since it " +
      "doesn't really make sense. What would it even mean?"
  end
end