Sha256: 8fe568c935a2203510c85209e73c590439b73011113ca0002b10eed24224f122
Contents?: true
Size: 1.05 KB
Versions: 3
Compression:
Stored size: 1.05 KB
Contents
# frozen_string_literal: true # must require active_support's alias_method_chain first, to ensure that our module monkey patches it require 'active_support/core_ext/module/aliasing' require_relative '../../lib/invoca/utils/module.rb' require_relative '../spec_helper' describe Module do class NumberFun def self.around_filter(around_method, method_names) method_names.each do |meth| define_method("#{meth}_with_around_filter") do |*args| send(around_method, *args) do |*ar_args| send("#{meth}_without_around_filter", *ar_args) end end alias_method_chain meth, :around_filter end end def increment_filter(num) yield(num + 1) end def number_printer(num) num end around_filter :increment_filter, [:number_printer] around_filter :increment_filter, [:number_printer] end context 'alias_method_chain' do it 'not cause infinite recursion when double aliasing the same method' do expect(NumberFun.new.number_printer(3)).to eq(4) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
invoca-utils-0.6.0 | spec/unit/module_spec.rb |
invoca-utils-0.5.1 | spec/unit/module_spec.rb |
invoca-utils-0.5.0 | spec/unit/module_spec.rb |