Class: Wukong::SpecHelpers::UnitTestDriver
- Inherits:
-
Array
- Object
- Array
- Wukong::SpecHelpers::UnitTestDriver
- Includes:
- DriverMethods
- Defined in:
- lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb
Instance Attribute Summary collapse
-
#given_records ⇒ Object
readonly
An array of accumulated records to process come match-time.
Attributes included from DriverMethods
Instance Method Summary collapse
-
#csv_output ⇒ Array<String>
Return the output of the processor on the given records, parsing as CSV first.
-
#delimited_output(delimiter) ⇒ Array<String>
Return the output of the processor on the given records, parsing as a string with the given
delimiter
first. -
#given(*records) ⇒ Object
Give a collection of records to the processor.
-
#given_csv(*records) ⇒ Object
Give a collection of records to the processor but join each in CSV format first.
-
#given_delimited(delimiter, *records) ⇒ Object
Give a collection of records to the processor but join each in a delimited format first.
-
#given_json(*records) ⇒ Object
Give a collection of records to the processor but turn each to JSON first.
-
#given_tsv(*records) ⇒ Object
Give a collection of records to the processor but join each in TSV format first.
-
#initialize(label, settings = {}) ⇒ UnitTestDriver
constructor
A new instance of UnitTestDriver.
-
#json_output ⇒ Hash, Array
Return the output of the processor on the given records, parsing as JSONS first.
-
#output ⇒ UnitTestDriver
Return the output of the processor on the given records.
- #process(output) ⇒ Object
- #processor ⇒ Object
- #run ⇒ Object
-
#tsv_output ⇒ Array<String>
Return the output of the processor on the given records, parsing as TSV first.
Methods included from DriverMethods
#construct_dataflow, #finalize, #finalize_and_stop_dataflow, #finalize_dataflow, #send_through_dataflow, #setup, #setup_dataflow, #stop
Constructor Details
#initialize(label, settings = {}) ⇒ UnitTestDriver
Returns a new instance of UnitTestDriver.
7 8 9 10 11 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 7 def initialize label, settings={} super() construct_dataflow(label, settings) setup_dataflow end |
Instance Attribute Details
#given_records ⇒ Object (readonly)
An array of accumulated records to process come match-time.
31 32 33 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 31 def given_records @given_records end |
Instance Method Details
#csv_output ⇒ Array<String>
Return the output of the processor on the given records, parsing as CSV first.
117 118 119 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 117 def csv_output delimited_output(",") end |
#delimited_output(delimiter) ⇒ Array<String>
Return the output of the processor on the given records,
parsing as a string with the given delimiter
first.
97 98 99 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 97 def delimited_output(delimiter) output.map { |record| record.split(delimiter) } end |
#given(*records) ⇒ Object
Give a collection of records to the processor.
36 37 38 39 40 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 36 def given *records @given_records ||= [] @given_records.concat(records) self # for chaining end |
#given_csv(*records) ⇒ Object
Give a collection of records to the processor but join each in CSV format first.
72 73 74 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 72 def given_csv *records self.given_delimited(",", *records) end |
#given_delimited(delimiter, *records) ⇒ Object
Give a collection of records to the processor but join each in a delimited format first.
54 55 56 57 58 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 54 def given_delimited delimiter, *records self.given(*records.map do |record| record.map(&:to_s).join(delimiter) end.join("\n")) end |
#given_json(*records) ⇒ Object
Give a collection of records to the processor but turn each to JSON first.
46 47 48 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 46 def given_json *records self.given(*records.map { |record| MultiJson.dump(record) }) end |
#given_tsv(*records) ⇒ Object
Give a collection of records to the processor but join each in TSV format first.
64 65 66 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 64 def given_tsv *records self.given_delimited("\t", *records) end |
#json_output ⇒ Hash, Array
Return the output of the processor on the given records, parsing as JSONS first.
126 127 128 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 126 def json_output output.map { |record| MultiJson.load(record) } end |
#output ⇒ UnitTestDriver
Return the output of the processor on the given records.
Calling this method, like passing the processor to an emit
matcher, will trigger processing of all the given records.
Returns a UnitTestDriver, which is a subclass of array, so the
usual matchers like include
and so on should work, as well
as explicitly indexing to introspect on particular records.
86 87 88 89 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 86 def output run self end |
#process(output) ⇒ Object
13 14 15 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 13 def process output self << output end |
#processor ⇒ Object
26 27 28 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 26 def processor dataflow.root end |
#run ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 17 def run return false unless dataflow given_records.each do |input| send_through_dataflow(input) end finalize_and_stop_dataflow self end |
#tsv_output ⇒ Array<String>
Return the output of the processor on the given records, parsing as TSV first.
107 108 109 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 107 def tsv_output delimited_output("\t") end |