Module: Repla::Test::Helper
- Defined in:
- lib/repla/test/lib/helper.rb
Overview
Test helper
Constant Summary collapse
- APPLESCRIPT_DIRECTORY =
File.join(__dir__, '..', 'applescript')
- CONFIRMDIALOGAPPLESCRIPT_FILE =
File.join(APPLESCRIPT_DIRECTORY, 'confirm_dialog.scpt')
- WINDOWIDAPPLESCRIPT_FILE =
File.join(APPLESCRIPT_DIRECTORY, 'window_id.scpt')
- CANCELDIALOGAPPLESCRIPT_FILE =
File.join(APPLESCRIPT_DIRECTORY, 'cancel_dialog.scpt')
- QUITAPPLESCRIPT_FILE =
File.join(APPLESCRIPT_DIRECTORY, 'quit.scpt')
- ISRUNNINGAPPLESCRIPT_FILE =
File.join(APPLESCRIPT_DIRECTORY, 'is_running.scpt')
- SWITCHWINDOWSAPPLESCRIPT_FILE =
File.join(APPLESCRIPT_DIRECTORY, 'switch_windows.scpt')
- WINDOWBOUNDSAPPLESCRIPT_FILE =
File.join(APPLESCRIPT_DIRECTORY, 'window_bounds.scpt')
- SETWINDOWBOUNDSAPPLESCRIPT_FILE =
File.join(APPLESCRIPT_DIRECTORY, 'set_window_bounds'\ '.scpt')
Class Method Summary collapse
- .app_running? ⇒ Boolean
- .cancel_dialog ⇒ Object
- .confirm_dialog ⇒ Object
- .quit ⇒ Object
-
.run_applescript(script, arguments = nil) ⇒ Object
TODO: ‘self.run_applescript` should be private but now all of a sudden instances method can’t call private class methods?.
- .run_javascript(javascript) ⇒ Object
- .set_window_bounds(bounds, window_id = nil) ⇒ Object
- .switch_windows ⇒ Object
- .window_bounds(window_id = nil) ⇒ Object
- .window_id ⇒ Object
Class Method Details
.app_running? ⇒ Boolean
49 50 51 52 |
# File 'lib/repla/test/lib/helper.rb', line 49 def self.app_running? result = run_applescript(ISRUNNINGAPPLESCRIPT_FILE) result == 'true' end |
.cancel_dialog ⇒ Object
36 37 38 39 |
# File 'lib/repla/test/lib/helper.rb', line 36 def self.cancel_dialog run_applescript(CANCELDIALOGAPPLESCRIPT_FILE) sleep TEST_PAUSE_TIME # Give dialog time end |
.confirm_dialog ⇒ Object
23 24 25 26 |
# File 'lib/repla/test/lib/helper.rb', line 23 def self.confirm_dialog run_applescript(CONFIRMDIALOGAPPLESCRIPT_FILE) sleep TEST_PAUSE_TIME # Give dialog time end |
.quit ⇒ Object
43 44 45 |
# File 'lib/repla/test/lib/helper.rb', line 43 def self.quit run_applescript(QUITAPPLESCRIPT_FILE) end |
.run_applescript(script, arguments = nil) ⇒ Object
TODO: ‘self.run_applescript` should be private but now all of a sudden instances method can’t call private class methods?
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/repla/test/lib/helper.rb', line 77 def self.run_applescript(script, arguments = nil) command = "/usr/bin/osascript #{Shellwords.escape(script)}" if arguments arguments.each do |argument| if argument argument = argument.to_s command = command + ' ' + Shellwords.escape(argument) end end end result = `#{command}` result.chomp! return nil if result.empty? return result.to_i if result.integer? return result.to_f if result.float? result end |
.run_javascript(javascript) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/repla/test/lib/helper.rb', line 13 def self.run_javascript(javascript) # `/usr/bin/osascript` requires redirecting stderr to stdout for some # reason `/usr/bin/osascript -l JavaScript -e \ #{Shellwords.escape(javascript)} 2>&1`.chomp! # return `node -e #{Shellwords.escape(javascript)}` end |
.set_window_bounds(bounds, window_id = nil) ⇒ Object
69 70 71 72 73 |
# File 'lib/repla/test/lib/helper.rb', line 69 def self.set_window_bounds(bounds, window_id = nil) arguments = [bounds] arguments = arguments.push(window_id) if window_id run_applescript(SETWINDOWBOUNDSAPPLESCRIPT_FILE, arguments) end |
.switch_windows ⇒ Object
56 57 58 |
# File 'lib/repla/test/lib/helper.rb', line 56 def self.switch_windows run_applescript(SWITCHWINDOWSAPPLESCRIPT_FILE) end |
.window_bounds(window_id = nil) ⇒ Object
62 63 64 |
# File 'lib/repla/test/lib/helper.rb', line 62 def self.window_bounds(window_id = nil) run_applescript(WINDOWBOUNDSAPPLESCRIPT_FILE, [window_id]) end |
.window_id ⇒ Object
30 31 32 |
# File 'lib/repla/test/lib/helper.rb', line 30 def self.window_id run_applescript(WINDOWIDAPPLESCRIPT_FILE) end |