Class: RSpec::Rails::AssertionDelegator Private

Inherits:
Module
  • Object
show all
Defined in:
lib/rspec/rails/adapters.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary (collapse)

Constructor Details

- (AssertionDelegator) initialize(*assertion_modules)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of AssertionDelegator

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/rspec/rails/adapters.rb', line 25
def initialize(*assertion_modules)
  assertion_class = Class.new(SimpleDelegator) do
    include ::RSpec::Rails::Assertions
    include ::RSpec::Rails::MinitestCounters
    assertion_modules.each { |mod| include mod }
  end
  super() do
    # @api private
    define_method :build_assertion_instance do
      assertion_class.new(self)
    end
    # @api private
    def assertion_instance
      @assertion_instance ||= build_assertion_instance
    end
    assertion_modules.each do |mod|
      mod.public_instance_methods.each do |method|
        next if method == :method_missing || method == "method_missing"
        class_eval <<-EOM, __FILE__, __LINE__ + 1
          def #{method}(*args, &block)
            assertion_instance.send(:#{method}, *args, &block)
          end
        EOM
      end
    end
  end
end