Class: Talkshow
- Inherits:
-
Object
- Object
- Talkshow
- Defined in:
- lib/talkshow.rb,
lib/talkshow/server.rb,
lib/talkshow/timeout.rb,
lib/talkshow/web_control.rb,
lib/talkshow/javascript_error.rb
Overview
Sinatra server that is launched by your test code to talk to the instrumented javascript application
Defined Under Namespace
Classes: Daemon, JavascriptError, Queue, Server, Timeout, WebControl
Instance Attribute Summary collapse
-
#thread ⇒ Object
Returns the value of attribute thread.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#execute(command, timeout = 6) ⇒ Object
Send a javascript instruction to the client.
-
#execute_file(filename) ⇒ Object
Load in a javascript file and execute remotely.
-
#initialize ⇒ Talkshow
constructor
Create a new Talkshow object to get going:.
-
#invoke(function, args, timeout = 6) ⇒ Object
Invoke a function in the javascript application invoke requires a function name (including the namespace).
-
#start_server(options = {}) ⇒ Object
Start up the Talkshow webserver This will be triggered if you don’t do it – but it takes a few seconds to start up the thin server, so you are better off issuing this yourself.
-
#stop_server ⇒ Object
Stop the webserver.
Constructor Details
#initialize ⇒ Talkshow
Create a new Talkshow object to get going:
26 27 |
# File 'lib/talkshow.rb', line 26 def initialize end |
Instance Attribute Details
#thread ⇒ Object
Returns the value of attribute thread.
23 24 25 |
# File 'lib/talkshow.rb', line 23 def thread @thread end |
#type ⇒ Object
Returns the value of attribute type.
22 23 24 |
# File 'lib/talkshow.rb', line 22 def type @type end |
Instance Method Details
#execute(command, timeout = 6) ⇒ Object
Send a javascript instruction to the client
92 93 94 |
# File 'lib/talkshow.rb', line 92 def execute( command, timeout=6 ) send_question( { type: 'code', message: command }, timeout) end |
#execute_file(filename) ⇒ Object
Load in a javascript file and execute remotely
97 98 99 100 |
# File 'lib/talkshow.rb', line 97 def execute_file( filename ) text = File.read(filename) execute(text) end |
#invoke(function, args, timeout = 6) ⇒ Object
Invoke a function in the javascript application invoke requires a function name (including the namespace). Arguments are specified as an array reference.
Some examples:
ts.invoke( 'alert' )
ts.invoke( 'alert', ['Hello world'])
ts.invoke( 'window.alert', ['Hello world'] )
83 84 85 86 87 88 89 |
# File 'lib/talkshow.rb', line 83 def invoke( function, args, timeout=6 ) send_question( { type: 'invocation', function: function, args: args }, timeout) end |
#start_server(options = {}) ⇒ Object
Start up the Talkshow webserver This will be triggered if you don’t do it – but it takes a few seconds to start up the thin server, so you are better off issuing this yourself
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/talkshow.rb', line 33 def start_server( = {}) # Backward compatibility if .is_a? String url = port = nil logfile = nil else url = [:url] port = [:port] logfile = [:logfile] end url = ENV['TALKSHOW_REMOTE_URL'] if ENV['TALKSHOW_REMOTE_URL'] port = ENV['TALKSHOW_PORT'] if ENV['TALKSHOW_PORT'] logfile = ENV['TALKSHOW_LOG'] if ENV['TALKSHOW_LOG'] Talkshow::Server.set_port port if port Talkshow::Server.set_logfile logfile if logfile if !url @type = :thread @question_queue = ::Queue.new @answer_queue = ::Queue.new @thread = Thread.new do Talkshow::Server.question_queue(@question_queue) Talkshow::Server.answer_queue(@answer_queue) Talkshow::Server.run! end else @type = :remote @question_queue = Talkshow::Queue.new(url) @answer_queue = Talkshow::Queue.new(url) end end |
#stop_server ⇒ Object
Stop the webserver
71 72 73 |
# File 'lib/talkshow.rb', line 71 def stop_server @thread.exit end |