Class: Nobbie::Wx::ApplicationLauncher

Inherits:
Object
  • Object
show all
Defined in:
lib/nobbie/wx/application_launcher.rb

Overview

:nodoc:

Constant Summary collapse

AUT_NOT_WX_APP =
"APPLICATION_UNDER_TEST must be an instance of a Wx::App"

Instance Method Summary collapse

Constructor Details

#initialize(application_under_test) ⇒ ApplicationLauncher

Returns a new instance of ApplicationLauncher.



22
23
24
25
# File 'lib/nobbie/wx/application_launcher.rb', line 22

def initialize(application_under_test)
  @app = application_under_test
  Kernel.raise(AUT_NOT_WX_APP) unless @app.is_a?(Wxruby2::App)
end

Instance Method Details

#startObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/nobbie/wx/application_launcher.rb', line 34

def start
  puts "\n>> Starting application: #{@app.class}"
  start = Time.now

  @app_thread = Thread.new {
    @app.extend(ApplicationUnderTest)
    @app.init_timer
    @app.main_loop
  }

  @app_thread.priority = -1

  sleep 1
  finish = Time.now
  puts "\n>> Took #{finish-start} seconds to start application"
  Thread.pass
end

#stopObject



52
53
54
55
56
57
58
59
# File 'lib/nobbie/wx/application_launcher.rb', line 52

def stop
  puts "\n>> Stopping application: #{@app.class}\n"

  #todo: tbis would seem a polite way to exit .. but causes Bus/Segmentation Errors on OSX.
  #@app.top_window.destroy
  #@app.exit_main_loop
  #@app = nil
end

#with_applicationObject



27
28
29
30
31
32
# File 'lib/nobbie/wx/application_launcher.rb', line 27

def with_application
  start
  result = yield
  stop
  result
end