File: any_instance_of.rb

package info (click to toggle)
ruby-rr 3.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,424 kB
  • sloc: ruby: 11,405; makefile: 7
file content (29 lines) | stat: -rw-r--r-- 994 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
module RR
  module DoubleDefinitions
    module DoubleInjections
      class AnyInstanceOf
        extend(Module.new do
          include RR::DSL

          def call(subject_class, stubbed_methods=nil, &block)
            strategy_lambda = lambda do |double_definition_create|
              ::RR::DoubleDefinitions::Strategies::DoubleInjection::AnyInstanceOf.new(double_definition_create)
            end
            ::RR::DoubleDefinitions::DoubleDefinitionCreate.set_default_double_injection_strategy(strategy_lambda) do
              if stubbed_methods
                subject_class.class_eval do
                  stubbed_methods.each do |name, value|
                    value_proc = value.is_a?(Proc) ? value : lambda {value}
                    RR.stub(subject_class, name).returns(&value_proc)
                  end
                end
              else
                block.call(subject_class)
              end
            end
          end
        end)
      end
    end
  end
end