Module: Museo::TestIntegration

Included in:
MinitestIntegration, RSpecIntegration
Defined in:
lib/museo/test_integration.rb

Instance Method Summary collapse

Instance Method Details

#_add_snapshot_helper_methodsObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/museo/test_integration.rb', line 12

def _add_snapshot_helper_methods
  @controller.class.helper do
    Museo.configuration.stubbed_methods.each do |method_name, callable|
      alias_method("_original_#{method_name}", method_name) if method_defined?(method_name)

      define_method(method_name) do |*args, &block|
        output = callable.respond_to?(:call) ? instance_exec(*args, block, &callable) : callable

        [
          "<!--",
          "Stubbed method call: #{method_name}",
          Museo.configuration.formatter.format(output),
          "-->",
          "",
        ].join("\n").html_safe
      end
    end
  end
end

#_museo_setupObject



3
4
5
6
# File 'lib/museo/test_integration.rb', line 3

def _museo_setup
  _add_snapshot_helper_methods
  _redefine_render_with_snapshot_layout
end

#_museo_teardownObject



8
9
10
# File 'lib/museo/test_integration.rb', line 8

def _museo_teardown
  _remove_snapshot_helper_methods
end

#_redefine_render_with_snapshot_layoutObject



44
45
46
47
48
49
# File 'lib/museo/test_integration.rb', line 44

def _redefine_render_with_snapshot_layout
  @controller.define_singleton_method(:render) do |*args|
    options = args.length > 1 ? args.last : {}
    super(*args[1..-2], options.merge(layout: "museo/snapshot"))
  end
end

#_remove_snapshot_helper_methodsObject



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/museo/test_integration.rb', line 32

def _remove_snapshot_helper_methods
  @controller.class.helper do
    Museo.configuration.stubbed_methods.each do |method_name, _callable|
      remove_method method_name

      if method_defined?("_original_#{method_name}")
        alias_method method_name, "_original_#{method_name}"
      end
    end
  end
end