Class: QUnited::Application
- Inherits:
-
Object
- Object
- QUnited::Application
- Defined in:
- lib/qunited/application.rb
Instance Method Summary collapse
-
#handle_options ⇒ Object
Parse and handle command line options.
-
#options ⇒ Object
Client options generally parsed from the command line.
- #run ⇒ Object
- #run_tests ⇒ Object
Instance Method Details
#handle_options ⇒ Object
Parse and handle command line options
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/qunited/application.rb', line 24 def drivers = ::QUnited::Driver.constants.reject { |d| d == :Base } valid_drivers_string = "Valid drivers include: #{drivers.map { |d| d.to_s }.join(', ')}" args_empty = ARGV.empty? # This is a bit of a hack, but OptionParser removes the -- that separates the source # and test files and we need to put it back in the right place. Save the distance from # the end to do this later. double_dash_neg_index = ARGV.find_index('--') && (ARGV.find_index('--') - ARGV.size) optparse = OptionParser.new do |opts| opts. = "Usage: qunited [OPTIONS] [JS_SOURCE_FILES...] -- [JS_TEST_FILES..]\n\nRuns JavaScript unit tests with QUnit.\n\nJS_SOURCE_FILES are the JavaScript files that you want to test. They will all be\nloaded for running each test.\n\nJS_TEST_FILES are files that contain the QUnit tests to run.\n\nOptions:\n HELP_TEXT\n\n opts.on('-d', '--driver [NAME]', 'Specify the driver to use in running the tests',\n valid_drivers_string) do |name|\n raise UsageError, 'Must specify a driver name with -d or --driver option' unless name\n names_and_drivers = Hash[drivers.map { |d| d.to_s.downcase }.zip(drivers)]\n driver = names_and_drivers[name.downcase]\n raise UsageError, \"Invalid driver specified: \#{name}\\n\#{valid_drivers_string}\" unless driver\n options[:driver] = driver\n end\n\n opts.on('--fixtures [FILES]', 'Specify some files to include as html before running the tests') do |files|\n options[:fixture_files] = files.split(',')\n end\n\n opts.on_tail('-h', '--help', 'Show this message') do\n puts opts\n exit\n end\n opts.on_tail('--version', 'Print the QUnited version') do\n puts ::QUnited::VERSION\n exit\n end\n\n if args_empty\n puts opts\n exit 1\n end\n end.parse!\n\n # Put the -- back in if we had one initially and it was removed\n if double_dash_neg_index && !ARGV.include?('--')\n ARGV.insert(double_dash_neg_index, '--')\n end\nend\n" |
#options ⇒ Object
Client options generally parsed from the command line
19 20 21 |
# File 'lib/qunited/application.rb', line 19 def ||= {} end |
#run ⇒ Object
5 6 7 8 9 10 |
# File 'lib/qunited/application.rb', line 5 def run handle_exceptions do run_tests end end |
#run_tests ⇒ Object
12 13 14 15 16 |
# File 'lib/qunited/application.rb', line 12 def run_tests js_source_files, js_test_files = ARGV.join(' ').split('--').map { |file_list| file_list.split(' ') } passed = QUnited::Runner.new(js_source_files, js_test_files, ).run exit (passed ? 0 : 10) end |