Class: QUnited::Runner
- Inherits:
-
Object
- Object
- QUnited::Runner
- Defined in:
- lib/qunited/runner.rb
Constant Summary collapse
- DRIVERS_PRIORITY =
The drivers in order of which to use first when not otherwise specified
[:PhantomJs, :Rhino].freeze
Instance Attribute Summary collapse
-
#js_source_files ⇒ Object
Returns the value of attribute js_source_files.
-
#js_test_files ⇒ Object
Returns the value of attribute js_test_files.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #best_available_driver ⇒ Object
- #confirm_existence_of_files(files_array) ⇒ Object
- #get_driver(klass) ⇒ Object
- #get_formatter(klass) ⇒ Object
-
#initialize(js_source_files, js_test_files, options = {}) ⇒ Runner
constructor
A new instance of Runner.
- #resolve_driver_class ⇒ Object
- #resolve_formatter_class ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(js_source_files, js_test_files, options = {}) ⇒ Runner
Returns a new instance of Runner.
9 10 11 |
# File 'lib/qunited/runner.rb', line 9 def initialize(js_source_files, js_test_files, ={}) @js_source_files, @js_test_files, @options = js_source_files, js_test_files, end |
Instance Attribute Details
#js_source_files ⇒ Object
Returns the value of attribute js_source_files.
7 8 9 |
# File 'lib/qunited/runner.rb', line 7 def js_source_files @js_source_files end |
#js_test_files ⇒ Object
Returns the value of attribute js_test_files.
7 8 9 |
# File 'lib/qunited/runner.rb', line 7 def js_test_files @js_test_files end |
#options ⇒ Object
Returns the value of attribute options.
7 8 9 |
# File 'lib/qunited/runner.rb', line 7 def @options end |
Instance Method Details
#best_available_driver ⇒ Object
75 76 77 |
# File 'lib/qunited/runner.rb', line 75 def best_available_driver DRIVERS_PRIORITY.map { |driver| get_driver(driver) }.find { |driver| driver.available? } end |
#confirm_existence_of_files(files_array) ⇒ Object
79 80 81 |
# File 'lib/qunited/runner.rb', line 79 def confirm_existence_of_files(files_array) files_array.each { |f| raise UsageError, "File not found: #{f}" unless File.exist? f } end |
#get_driver(klass) ⇒ Object
63 64 65 66 67 |
# File 'lib/qunited/runner.rb', line 63 def get_driver(klass) if known_driver_classes.include?(klass.to_sym) ::QUnited::Driver.const_get(klass.to_s) end end |
#get_formatter(klass) ⇒ Object
69 70 71 72 73 |
# File 'lib/qunited/runner.rb', line 69 def get_formatter(klass) if known_formatter_classes.include?(klass.to_sym) ::QUnited::Formatter.const_get(klass.to_s) end end |
#resolve_driver_class ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/qunited/runner.rb', line 29 def resolve_driver_class if [:driver] begin driver_class = get_driver([:driver]) rescue NameError raise UsageError, "#{[:driver].to_s} does not exist" end if !driver_class raise UsageError, "#{driver_class} driver not found" elsif !driver_class.available? raise UsageError, "#{driver_class} driver specified, but not available" end end driver_class ||= best_available_driver raise(UsageError, 'No driver available') unless driver_class driver_class end |
#resolve_formatter_class ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/qunited/runner.rb', line 49 def resolve_formatter_class if [:formatter] begin formatter_class = get_formatter([:formatter]) rescue NameError raise UsageError, "#{[:formatter].to_s} does not exist" end raise UsageError, "#{formatter_class} formatter not found" unless formatter_class end formatter_class || ::QUnited::Formatter::Dots end |
#run ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/qunited/runner.rb', line 13 def run [js_source_files, js_test_files].each { |files| confirm_existence_of_files files } driver_class, formatter_class = resolve_driver_class, resolve_formatter_class driver = driver_class.new(js_source_files, js_test_files) driver.formatter = formatter_class.new({:driver_name => driver.name}) if [:fixture_files] driver.fixture_files = [:fixture_files] end results = driver.run results.all? { |r| r.passed? } end |