Module: Scarpe::Test

Defined in:
lib/scarpe/shoes_spec.rb,
scarpe-components/lib/scarpe/components/unit_test_helpers.rb

Overview

Test framework code to allow Scarpe to execute Shoes-Spec test code. This will run inside the exe/scarpe child process, then send results back to the parent Minitest process.

Defined Under Namespace

Modules: HTMLAssertions, Helpers, LoggedTest

Class Method Summary collapse

Class Method Details

.run_shoes_spec_test_code(code, class_name: nil, test_name: nil) ⇒ Object

Is it at all reasonable to define more than one test to run in the same Shoes run? Probably not. They'll leave in-memory residue.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/scarpe/shoes_spec.rb', line 16

def self.run_shoes_spec_test_code(code, class_name: nil, test_name: nil)
  if @shoes_spec_init
    raise Shoes::Errors::MultipleShoesSpecRunsError, "Scarpe-Webview can only run a single Shoes spec per process!"
  end

  @shoes_spec_init = true

  require "scarpe/components/minitest_export_reporter"
  Minitest::Reporters::ShoesExportReporter.activate!

  class_name ||= ENV["SHOES_MINITEST_CLASS_NAME"] || "TestShoesSpecCode"
  test_name ||= ENV["SHOES_MINITEST_METHOD_NAME"] || "test_shoes_spec"

  Scarpe::CCInstance.include Scarpe::ShoesSpecTest

  Scarpe::CCInstance.instance.instance_eval do
    event_init

    t_timeout = ENV["SCARPE_SSPEC_TIMEOUT"] || "30"
    timeout(t_timeout.to_f) unless t_timeout.downcase == "none"

    on_event(:next_heartbeat) do
      Minitest.run ARGV

      wait_after = ENV["SCARPE_SSPEC_TIMEOUT_WAIT_AFTER_TEST"]
      if !(wait_after && wait_after.downcase != "n" && wait_after.downcase != "no")
        shut_down_shoes_code
      end
    end
  end

  test_class = Class.new(Minitest::Test)
  test_class.include Scarpe::ShoesSpecTest
  Object.const_set(Scarpe::Components::StringHelpers.camelize(class_name), test_class)
  test_name = "test_" + test_name unless test_name.start_with?("test_")
  test_class.define_method(test_name) do
    eval(code)
  end
end