Sha256: 08ddfa4cc1630c68f5097f8b214578b5d0e665b80d17bae1ffab976747097a04
Contents?: true
Size: 1.93 KB
Versions: 3
Compression:
Stored size: 1.93 KB
Contents
# encoding: utf-8 module InitializerStubs UNWANTED_BEHAVIOR = { Adhearsion::Initializer => [:debugging_log, :require, :load, :init_plugins, :run_plugins] } unless defined? UNWANTED_BEHAVIOR def stub_behavior_for_initializer_with_no_path_changing_behavior stub_unwanted_behavior allow(Adhearsion::Rayo::Initializer).to receive(:init).and_return(true) allow(Adhearsion::Rayo::Initializer).to receive(:run).and_return(true) yield if block_given? ensure unstub_directory_changing_behavior end def with_new_initializer_with_no_path_changing_behavior(&block) stub_behavior_for_initializer_with_no_path_changing_behavior do block.call Adhearsion::Initializer.start end end def stub_unwanted_behavior(unwanted_behavior = UNWANTED_BEHAVIOR) unwanted_behavior.each do |stub_victim_class, undesired_methods| undesired_methods.each do |undesired_method_name_or_key_value_pair| undesired_method_name, method_implementation = case undesired_method_name_or_key_value_pair when Array [undesired_method_name_or_key_value_pair.first, lambda { |*args| undesired_method_name_or_key_value_pair.last } ] else [undesired_method_name_or_key_value_pair, lambda{ |*args| }] end stub_victim_class.send(:alias_method, "pre_stubbed_#{undesired_method_name}", undesired_method_name) stub_victim_class.send(:define_method, undesired_method_name, &method_implementation) end end end def unstub_directory_changing_behavior UNWANTED_BEHAVIOR.each do |stub_victim_class, undesired_methods| undesired_methods.each do |undesired_method_name| undesired_method_name = undesired_method_name.first if undesired_method_name.kind_of? Array stub_victim_class.send(:remove_method, undesired_method_name) stub_victim_class.send(:alias_method, undesired_method_name, "pre_stubbed_#{undesired_method_name}") end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
adhearsion-3.0.0.rc1 | spec/support/initializer_stubs.rb |
adhearsion-3.0.0.beta2 | spec/support/initializer_stubs.rb |
adhearsion-3.0.0.beta1 | spec/support/initializer_stubs.rb |