Class: RSpec::Rails::AssertionDelegator

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

Instance Method Summary collapse

Constructor Details

#initialize(*assertion_modules) ⇒ AssertionDelegator

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.



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
38
# File 'lib/rspec/rails/adapters.rb', line 9

def initialize(*assertion_modules)
  assertion_class = Class.new(SimpleDelegator) do
    include Test::Unit::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