Class: Shoegaze::Mock

Inherits:
Object
  • Object
show all
Includes:
Proxy::Interface
Defined in:
lib/shoegaze/mock.rb

Overview

Provides the top-level mocking interface from which our mocks will inherit.

Class Method Summary collapse

Methods included from Proxy::Interface

included

Class Method Details

.mock(class_name) ⇒ Class.new(Shoegaze::Proxy)

Creates a Shoegaze mock proxy for the provided class name

example:

class RealClass
end

class FakeClass < Shoegaze::Mock
  mock RealClass
end

Parameters:

  • class_name (String)

    String name of the constant to mock

Returns:

  • (Class.new(Shoegaze::Proxy))

    The created Shoegaze proxy. Use this as the replacement for your real implementation.


21
22
23
24
25
26
27
28
29
30
31
# File 'lib/shoegaze/mock.rb', line 21

def mock(class_name)
  @mock_class_double = class_double(class_name)
  @mock_instance_double = instance_double(class_name)

  extend_double_with_extra_methods(@mock_instance_double)
  extend_double_with_extra_methods(@mock_class_double)

  @implementations = {class: {}, instance: {}}

  proxy
end