Class: QUnited::Driver::Base
- Inherits:
-
Object
- Object
- QUnited::Driver::Base
- Defined in:
- lib/qunited/driver/base.rb
Constant Summary collapse
- SUPPORT_DIR =
Path of the common (to all drivers) supporting files directory
File.('../support', __FILE__)
- TEST_RESULT_START_TOKEN =
'QUNITED_TEST_RESULT_START_TOKEN'
- TEST_RESULT_END_TOKEN =
'QUNITED_TEST_RESULT_END_TOKEN'
- TEST_RESULT_REGEX =
/#{TEST_RESULT_START_TOKEN}(.*?)#{TEST_RESULT_END_TOKEN}/m
- COFFEESCRIPT_EXTENSIONS =
['coffee', 'cs']
Instance Attribute Summary collapse
-
#fixture_files ⇒ Object
Returns the value of attribute fixture_files.
-
#formatter ⇒ Object
Returns the value of attribute formatter.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
-
#source_files ⇒ Object
readonly
Returns the value of attribute source_files.
-
#test_files ⇒ Object
readonly
Returns the value of attribute test_files.
Class Method Summary collapse
-
.available? ⇒ Boolean
Overridden in subclasses to return true if the underlying library is installed.
-
.which(cmd) ⇒ Object
Finds an executable on the PATH.
Instance Method Summary collapse
- #command ⇒ Object
-
#initialize(source_files, test_files) ⇒ Base
constructor
Initialize the driver with source and test files.
- #name ⇒ Object
- #run ⇒ Object
- #support_file_contents(filename) ⇒ Object
- #support_file_path(filename) ⇒ Object
Constructor Details
#initialize(source_files, test_files) ⇒ Base
Initialize the driver with source and test files. The files can be described either with glob patterns or arrays of file names.
38 39 40 41 42 |
# File 'lib/qunited/driver/base.rb', line 38 def initialize(source_files, test_files) @source_files = normalize_files source_files @test_files = normalize_files test_files @fixture_files = [] end |
Instance Attribute Details
#fixture_files ⇒ Object
Returns the value of attribute fixture_files.
16 17 18 |
# File 'lib/qunited/driver/base.rb', line 16 def fixture_files @fixture_files end |
#formatter ⇒ Object
Returns the value of attribute formatter.
16 17 18 |
# File 'lib/qunited/driver/base.rb', line 16 def formatter @formatter end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
15 16 17 |
# File 'lib/qunited/driver/base.rb', line 15 def results @results end |
#source_files ⇒ Object (readonly)
Returns the value of attribute source_files.
15 16 17 |
# File 'lib/qunited/driver/base.rb', line 15 def source_files @source_files end |
#test_files ⇒ Object (readonly)
Returns the value of attribute test_files.
15 16 17 |
# File 'lib/qunited/driver/base.rb', line 15 def test_files @test_files end |
Class Method Details
.available? ⇒ Boolean
Overridden in subclasses to return true if the underlying library is installed
32 33 34 |
# File 'lib/qunited/driver/base.rb', line 32 def self.available? false end |
.which(cmd) ⇒ Object
Finds an executable on the PATH. Returns the absolute path of the executable if found, otherwise nil.
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/qunited/driver/base.rb', line 20 def self.which(cmd) exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : [''] ENV['PATH'].split(File::PATH_SEPARATOR).each do |path| exts.each do |ext| exe = "#{path}/#{cmd}#{ext}" return exe if File.executable? exe end end return nil end |
Instance Method Details
#command ⇒ Object
44 45 46 |
# File 'lib/qunited/driver/base.rb', line 44 def command raise 'not implemented' end |
#name ⇒ Object
92 93 94 |
# File 'lib/qunited/driver/base.rb', line 92 def name self.class.name.split('::')[-1] end |
#run ⇒ Object
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 82 |
# File 'lib/qunited/driver/base.rb', line 48 def run @tests_file = Tempfile.new(['tests_page', '.html']) @tests_file.write(tests_page_content) @tests_file.close send_to_formatter(:start) @results = [] Open3.popen3(command) do |stdin, stdout, stderr| results_collector = ResultsCollector.new(stdout) results_collector.on_test_result do |result| @results << result method = result.passed? ? :test_passed : :test_failed send_to_formatter(method, result) end results_collector.on_non_test_result_line do |line| # Drivers sometimes print error messages to stdout. If we are not reading # a test result then redirect any output to stderr $stderr.puts(line) end results_collector.collect_results err = stderr.read $stderr.puts(err) if err && !err.empty? end send_to_formatter(:stop) send_to_formatter(:summarize) @results end |
#support_file_contents(filename) ⇒ Object
88 89 90 |
# File 'lib/qunited/driver/base.rb', line 88 def support_file_contents(filename) IO.read(support_file_path(filename)) end |
#support_file_path(filename) ⇒ Object
84 85 86 |
# File 'lib/qunited/driver/base.rb', line 84 def support_file_path(filename) File.join(SUPPORT_DIR, filename) end |