Class: JsTestDriver::Runner
- Inherits:
-
Object
- Object
- JsTestDriver::Runner
- Defined in:
- lib/js_test_driver/runner.rb
Overview
The Runner class is used
Defined Under Namespace
Classes: Command
Instance Attribute Summary collapse
- #config ⇒ Object
- #config_path ⇒ Object
-
#generated_files_dir ⇒ Object
this is where the generated files will be saved, by default this is ‘pwd`/.js_test_driver.
- #jar_path ⇒ Object
-
#tmp_path ⇒ Object
writeonly
this is where the config yml file will be saved, by default its saved in the generated files directory under the name jsTestDriver.conf.
Instance Method Summary collapse
- #add_capture_browsers(command, browsers) ⇒ Object
- #add_capture_console(command) ⇒ Object
- #add_output_directory(command, path) ⇒ Object
- #add_run_tests(command, tests) ⇒ Object
- #add_runner_mode(command) ⇒ Object
- #add_start_server(command) ⇒ Object
- #add_with_config(command) ⇒ Object
-
#capture_browsers(browsers = nil) ⇒ Object
captures the browsers.
- #config_yml_path ⇒ Object
- #execute_jar ⇒ Object
- #generate_html_coverage_report(output_path) ⇒ Object
-
#initialize(attributes = {}) ⇒ Runner
constructor
A new instance of Runner.
-
#run_tests(tests = nil) ⇒ Object
runs the tests specified by the argument.
-
#start_server ⇒ Object
starts the server on the default port specified in the config file.
- #start_server_capture_and_run(tests = nil, browsers = nil, output_xml_path = nil, console = nil) ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Runner
Returns a new instance of Runner.
5 6 7 |
# File 'lib/js_test_driver/runner.rb', line 5 def initialize(attributes = {}) self.attributes = attributes end |
Instance Attribute Details
#config ⇒ Object
12 13 14 |
# File 'lib/js_test_driver/runner.rb', line 12 def config @config ||= parse_config end |
#config_path ⇒ Object
28 29 30 |
# File 'lib/js_test_driver/runner.rb', line 28 def config_path @config_path ||= default_config_path end |
#generated_files_dir ⇒ Object
this is where the generated files will be saved, by default this is ‘pwd`/.js_test_driver
the generated files are the config yml file and the fixture files
21 22 23 |
# File 'lib/js_test_driver/runner.rb', line 21 def generated_files_dir @generated_files_dir || default_generated_files_dir end |
#jar_path ⇒ Object
35 36 37 |
# File 'lib/js_test_driver/runner.rb', line 35 def jar_path @jar_path ||= default_jar_path end |
#tmp_path=(value) ⇒ Object (writeonly)
this is where the config yml file will be saved, by default its saved in the generated files directory under the name jsTestDriver.conf
41 42 43 |
# File 'lib/js_test_driver/runner.rb', line 41 def tmp_path=(value) @tmp_path = value end |
Instance Method Details
#add_capture_browsers(command, browsers) ⇒ Object
118 119 120 121 122 |
# File 'lib/js_test_driver/runner.rb', line 118 def add_capture_browsers(command, browsers) browsers ||= config.browsers.join(',') raise ArgumentError.new("No browsers defined!") if browsers == "" command.option('--browser', browsers) end |
#add_capture_console(command) ⇒ Object
130 131 132 |
# File 'lib/js_test_driver/runner.rb', line 130 def add_capture_console(command) command.option('--captureConsole') end |
#add_output_directory(command, path) ⇒ Object
124 125 126 127 128 |
# File 'lib/js_test_driver/runner.rb', line 124 def add_output_directory(command, path) path = File.(path) FileUtils.mkdir_p(path) unless File.exists?(path) command.option('--testOutput', path) end |
#add_run_tests(command, tests) ⇒ Object
114 115 116 |
# File 'lib/js_test_driver/runner.rb', line 114 def add_run_tests(command, tests) command.option('--tests', tests || "all") end |
#add_runner_mode(command) ⇒ Object
110 111 112 |
# File 'lib/js_test_driver/runner.rb', line 110 def add_runner_mode(command) command.option('--runnerMode', ENV['RUNNER_MODE']) unless ENV['RUNNER_MODE'].nil? || ENV['RUNNER_MODE'].empty? end |
#add_start_server(command) ⇒ Object
106 107 108 |
# File 'lib/js_test_driver/runner.rb', line 106 def add_start_server(command) command.option('--port', config.port) end |
#add_with_config(command) ⇒ Object
134 135 136 137 |
# File 'lib/js_test_driver/runner.rb', line 134 def add_with_config(command) save_config_file(config_yml_path) command.option('--config', config_yml_path) end |
#capture_browsers(browsers = nil) ⇒ Object
captures the browsers
by default it will capture the browsers specified in the config, but you can pass an argument like ‘opera,chrome,firefox’ to capture opera, chrome and firefox
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/js_test_driver/runner.rb', line 60 def capture_browsers(browsers = nil) browsers ||= '' browsers = browsers.split(',') browsers = config.browsers if browsers.empty? url = config.server + "/capture" browsers.each do |browser| spawn("#{browser} \'#{url}\'") end end |
#config_yml_path ⇒ Object
43 44 45 |
# File 'lib/js_test_driver/runner.rb', line 43 def config_yml_path @tmp_path ||= default_config_yml_path end |
#execute_jar ⇒ Object
139 140 141 |
# File 'lib/js_test_driver/runner.rb', line 139 def execute_jar Command.new('java').option('-jar', jar_path) end |
#generate_html_coverage_report(output_path) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/js_test_driver/runner.rb', line 143 def generate_html_coverage_report(output_path) unless genhtml_installed? puts "Could not find genhtml. You must install lcov (sudo apt-get install lcov)" return end output_path = File.(output_path) config_file_name = File.basename(config_yml_path) coverage_file_name = config_file_name + '-coverage.dat' coverage_file_path = File.join(output_path, coverage_file_name) coverage_out_dir = File.join(output_path, 'coverage') system("genhtml -o #{coverage_out_dir} #{coverage_file_path}") end |
#run_tests(tests = nil) ⇒ Object
runs the tests specified by the argument
by default it will run all the tests, but you can pass a string like: ‘TestCase’ or ‘TestCase.test’ to run either a single test case or a single test
77 78 79 80 81 82 83 84 |
# File 'lib/js_test_driver/runner.rb', line 77 def run_tests(tests = nil) command = execute_jar add_with_config(command) add_run_tests(command, tests) command.run end |
#start_server ⇒ Object
starts the server on the default port specified in the config file
48 49 50 51 52 53 54 |
# File 'lib/js_test_driver/runner.rb', line 48 def start_server command = execute_jar add_start_server(command) command.run end |
#start_server_capture_and_run(tests = nil, browsers = nil, output_xml_path = nil, console = nil) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/js_test_driver/runner.rb', line 86 def start_server_capture_and_run(tests = nil, browsers = nil, output_xml_path = nil, console = nil) command = execute_jar add_start_server(command) add_runner_mode(command) add_with_config(command) add_capture_browsers(command, browsers) add_run_tests(command, tests) add_output_directory(command, output_xml_path) if output_xml_path add_capture_console(command) if console result = command.run if config.measure_coverage? && output_xml_path generate_html_coverage_report(output_xml_path) end return result end |