Module: RSpec::Mocks::TestDouble

Defined in:
opal/opal/rspec/fixes/rspec/mocks/test_double.rb

Instance Method Summary collapse

Instance Method Details

#call_method_missing(message, *args, &block) ⇒ Object

With multiple modules included in a class, Opal doesn't let module 2 (VerifyingDouble) invoke super from module 1 (TestDouble)

Raises:

  • (NoMethodError)


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'opal/opal/rspec/fixes/rspec/mocks/test_double.rb', line 4

def call_method_missing(message, *args, &block)
  proxy = __mock_proxy
  proxy.record_message_received(message, *args, &block)

  if proxy.null_object?
    case message
      when :to_int then
        return 0
      when :to_a, :to_ary then
        return nil
      when :to_str then
        return to_s
      else
        return self
    end
  end

  # Defined private and protected methods will still trigger `method_missing`
  # when called publicly. We want ruby's method visibility error to get raised,
  # so we simply delegate to `super` in that case.
  # ...well, we would delegate to `super`, but there's a JRuby
  # bug, so we raise our own visibility error instead:
  # https://github.com/jruby/jruby/issues/1398
  visibility = proxy.visibility_for(message)
  if visibility == :private || visibility == :protected
    ErrorGenerator.new(self, @name).raise_non_public_error(
        message, visibility
    )
  end

  # Required wrapping doubles in an Array on Ruby 1.9.2
  raise NoMethodError if [:to_a, :to_ary].include? message
  proxy.raise_unexpected_message_error(message, *args)
end