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. - #finalize ⇒ Object
-
#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
- #setup ⇒ Object
- #stop ⇒ Object
-
#tsv_output ⇒ Array<String>
Return the output of the processor on the given records, parsing as TSV first.
Methods included from DriverMethods
#add_serialization, #build_serializer, #construct_dataflow, #driver, #finalize_and_stop_dataflow, #finalize_dataflow, #lookup, #lookup_and_build, #setup_dataflow
Constructor Details
#initialize(label, settings) ⇒ UnitTestDriver
Returns a new instance of UnitTestDriver.
7 8 9 10 11 12 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 7 def initialize label, settings super() @settings = settings @dataflow = construct_dataflow(label, settings) setup_dataflow end |
Instance Attribute Details
#given_records ⇒ Object (readonly)
An array of accumulated records to process come match-time.
41 42 43 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 41 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.
127 128 129 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 127 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.
107 108 109 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 107 def delimited_output(delimiter) output.map { |record| record.split(delimiter) } end |
#finalize ⇒ Object
17 18 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 17 def finalize end |
#given(*records) ⇒ Object
Give a collection of records to the processor.
46 47 48 49 50 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 46 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.
82 83 84 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 82 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.
64 65 66 67 68 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 64 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.
56 57 58 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 56 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.
74 75 76 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 74 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.
136 137 138 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 136 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.
96 97 98 99 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 96 def output run self end |
#process(output) ⇒ Object
23 24 25 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 23 def process output self << output end |
#processor ⇒ Object
36 37 38 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 36 def processor dataflow.first end |
#run ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 27 def run return false unless dataflow given_records.each do |input| driver.send_through_dataflow(input) end finalize_and_stop_dataflow self end |
#setup ⇒ Object
14 15 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 14 def setup end |
#stop ⇒ Object
20 21 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 20 def stop end |
#tsv_output ⇒ Array<String>
Return the output of the processor on the given records, parsing as TSV first.
117 118 119 |
# File 'lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb', line 117 def tsv_output delimited_output("\t") end |