Sha256: f34236e258886a458745c5d613c5ae1e53a70cb526e66b8f448726598c89ccb0
Contents?: true
Size: 1.78 KB
Versions: 2
Compression:
Stored size: 1.78 KB
Contents
require 'json' require_relative 'basic_event' require_relative 'test_event' require_relative 'pass_or_fail_event' require_relative 'status_change_event' require_relative 'echo_event' module Torkify::Event # Parse raw strings passed by tork into event objects. class Parser # Parse a raw string and return an object based on the event type. # # E.g. a raw string like: # > '["test","spec/reader_spec.rb",[],"spec/reader_spec.rb.log",3]' def parse(line) raw = JSON.load line event_from_data raw end protected # Create an event object from the array of data. def event_from_data(data) case data.first when 'test' [ TestEvent.new(*data) ] when 'pass', 'fail' [ PassOrFailEvent.new(*data) ] when 'pass_now_fail', 'fail_now_pass' [ StatusChangeEvent.new(data[0], data[1], event_from_data(data[2]).first) ] when 'echo' parse_echo_event data else [ BasicEvent.new(data.first) ] end end def parse_echo_event(data) events = [ EchoEvent.new(*data) ] event = event_from_echo(*data[1]) events << event if event events end def event_from_echo(action, *action_args) if echo_commands_requiring_args.include? action return if action_args.empty? || action_args.first.empty? end if known_echo_commands.include? action BasicEvent.new action end end def known_echo_commands [ 'run_all_test_files', 'run_test_files', 'run_test_file', 'stop_running_test_files', 'stop_running_test_files', 'rerun_passed_test_files', 'rerun_failed_test_files' ] end def echo_commands_requiring_args [ 'run_test_files', 'run_test_file' ] end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
torkify-0.0.3 | lib/torkify/event/parser.rb |
torkify-0.0.2 | lib/torkify/event/parser.rb |