Class: TestLauncher::CLI::MultiFrameworkQuery

Inherits:
Struct
  • Object
show all
Defined in:
lib/test_launcher/cli.rb

Constant Summary collapse

@@mutex =
Mutex.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cli_optionsObject

Returns the value of attribute cli_options

Returns:

  • (Object)

    the current value of cli_options



9
10
11
# File 'lib/test_launcher/cli.rb', line 9

def cli_options
  @cli_options
end

Instance Method Details

#commandObject



12
13
14
15
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
55
56
# File 'lib/test_launcher/cli.rb', line 12

def command
  # do them all at the same time!
  @count = cli_options.frameworks.count
  @finished = 0
  @value = nil
  @now = Time.now.to_f
  @generic_default = nil

  cli_options.frameworks.each do |framework|
    Thread.new do
      finder = Queries::CommandFinder.new(request_for(framework))
      ex = nil

      begin
        val = finder.generic_search
      rescue => e
        ex = e
      end

      @@mutex.synchronize do
        @finished += 1

        if framework == Frameworks::Generic
          @generic_default = val
        else
          if ex && !@exception
            @exception = ex
          elsif val && !@value
            @value = val
          end
        end
      end
    end
  end

  while (@finished < @count && !@value && !@exception) do
    sleep(0.05)
  end

  if @exception
    raise @exception
  else
    @value || @generic_default
  end
end

#request_for(framework) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/test_launcher/cli.rb', line 58

def request_for(framework)
  Request.new(
    framework: framework,
    search_string: cli_options.search_string,
    rerun: cli_options.rerun,
    run_all: cli_options.run_all,
    disable_spring: cli_options.disable_spring,
    force_spring: cli_options.force_spring,
    example_name: cli_options.example_name,
    shell: cli_options.shell,
    searcher: cli_options.searcher,
  )
end