Class: Berl::BehatRunner
- Inherits:
-
Object
- Object
- Berl::BehatRunner
- Defined in:
- lib/berl/behat_runner.rb
Overview
Service to run Behat tests
Instance Attribute Summary collapse
-
#num_of_failed ⇒ Object
readonly
Returns the value of attribute num_of_failed.
-
#num_of_succeed ⇒ Object
readonly
Returns the value of attribute num_of_succeed.
Instance Method Summary collapse
- #handle_finish(_, _, result) ⇒ Object
-
#initialize(num_of_workers, suites, databases, debug) ⇒ BehatRunner
constructor
A new instance of BehatRunner.
- #print_errors ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(num_of_workers, suites, databases, debug) ⇒ BehatRunner
Returns a new instance of BehatRunner.
8 9 10 11 12 13 14 15 16 |
# File 'lib/berl/behat_runner.rb', line 8 def initialize(num_of_workers, suites, databases, debug) @num_of_succeed = 0 @num_of_failed = 0 @num_of_workers = num_of_workers @suites = suites @databases = databases @debug = debug @output = {} end |
Instance Attribute Details
#num_of_failed ⇒ Object (readonly)
Returns the value of attribute num_of_failed.
6 7 8 |
# File 'lib/berl/behat_runner.rb', line 6 def num_of_failed @num_of_failed end |
#num_of_succeed ⇒ Object (readonly)
Returns the value of attribute num_of_succeed.
6 7 8 |
# File 'lib/berl/behat_runner.rb', line 6 def num_of_succeed @num_of_succeed end |
Instance Method Details
#handle_finish(_, _, result) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/berl/behat_runner.rb', line 60 def handle_finish(_, _, result) puts "Handling finished job for #{result['suite_name']}" if @debug if result['status'] == 'success' @num_of_succeed += 1 puts "ā #{result['suite_name']} (#{num_of_executed}/#{@suites.count})" return end @num_of_failed += 1 @output[result['suite_name']] = result['output'] puts "ā #{result['suite_name']} (#{num_of_executed}/#{@suites.count})" end |
#print_errors ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/berl/behat_runner.rb', line 81 def print_errors puts "\n\n šØ Errors for failed suites:" @output.each do |suite_name, output| puts "\nā #{suite_name}" puts output end end |
#start ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/berl/behat_runner.rb', line 18 def start Parallel.each( @suites, in_threads: @num_of_workers, finish: method(:handle_finish) ) do |suite| database = @databases[Parallel.worker_number] cache = "cache_#{Parallel.worker_number}" behat_cmd = build_behat_cmd(database, cache, suite) puts "[DEBUG] command: #{behat_cmd}" if @debug Open3.popen3(behat_cmd) do |_, stdout, _, wait_thr| result = {} result['output'] = [] result['output'].push(*stdout.readlines) if wait_thr.value != 0 result['suite_name'] = suite result['status'] = wait_thr.value == 0 ? 'success' : 'fail' puts "[DEBUG] result: #{result}" if @debug result end end end |