Class: Emendate::Examples::TestableExample
- Inherits:
-
Object
- Object
- Emendate::Examples::TestableExample
- Defined in:
- lib/emendate/examples/testable_example.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#fingerprint ⇒ Object
readonly
Returns the value of attribute fingerprint.
-
#processed ⇒ Object
readonly
Returns the value of attribute processed.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
-
#test_options ⇒ Object
readonly
Returns the value of attribute test_options.
-
#test_pattern ⇒ Object
readonly
Returns the value of attribute test_pattern.
-
#test_string ⇒ Object
readonly
Returns the value of attribute test_string.
Instance Method Summary collapse
- #add_error(testname, err) ⇒ Object
- #add_test_result(testname, result) ⇒ Object
- #all_tags ⇒ Object
- #formatted_error(testname, err) ⇒ Object
-
#initialize(rows) ⇒ TestableExample
constructor
A new instance of TestableExample.
- #report_error(err) ⇒ Object
- #report_failure ⇒ Object
- #run_tests(tests: nil, fail_fast: false, mode: :normal) ⇒ Object
- #runnable_tests ⇒ Object
- #tags(type) ⇒ Object
- #test_status ⇒ Object
- #testable? ⇒ Boolean
- #to_s ⇒ Object (also: #inspect)
- #type_pattern(date_only: false, stage: :tokens) ⇒ Object
Constructor Details
#initialize(rows) ⇒ TestableExample
Returns a new instance of TestableExample.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/emendate/examples/testable_example.rb', line 12 def initialize(rows) @rows = rows fail(EmptyTestSetError.new) if rows.empty? @fingerprint = rows.first.test_fingerprint @test_string = rows.first.test_string @test_options = rows.first. @test_pattern = rows.first.test_pattern @processed = nil @errors = {} @test_results = {} end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
10 11 12 |
# File 'lib/emendate/examples/testable_example.rb', line 10 def errors @errors end |
#fingerprint ⇒ Object (readonly)
Returns the value of attribute fingerprint.
10 11 12 |
# File 'lib/emendate/examples/testable_example.rb', line 10 def fingerprint @fingerprint end |
#processed ⇒ Object (readonly)
Returns the value of attribute processed.
10 11 12 |
# File 'lib/emendate/examples/testable_example.rb', line 10 def processed @processed end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
10 11 12 |
# File 'lib/emendate/examples/testable_example.rb', line 10 def rows @rows end |
#test_options ⇒ Object (readonly)
Returns the value of attribute test_options.
10 11 12 |
# File 'lib/emendate/examples/testable_example.rb', line 10 def @test_options end |
#test_pattern ⇒ Object (readonly)
Returns the value of attribute test_pattern.
10 11 12 |
# File 'lib/emendate/examples/testable_example.rb', line 10 def test_pattern @test_pattern end |
#test_string ⇒ Object (readonly)
Returns the value of attribute test_string.
10 11 12 |
# File 'lib/emendate/examples/testable_example.rb', line 10 def test_string @test_string end |
Instance Method Details
#add_error(testname, err) ⇒ Object
26 27 28 |
# File 'lib/emendate/examples/testable_example.rb', line 26 def add_error(testname, err) @errors[testname] = formatted_error(testname, err) end |
#add_test_result(testname, result) ⇒ Object
36 37 38 |
# File 'lib/emendate/examples/testable_example.rb', line 36 def add_test_result(testname, result) @test_results[testname] = result end |
#all_tags ⇒ Object
40 41 42 |
# File 'lib/emendate/examples/testable_example.rb', line 40 def [("data_set"), ("date_type")].flatten.sort.uniq end |
#formatted_error(testname, err) ⇒ Object
30 31 32 33 34 |
# File 'lib/emendate/examples/testable_example.rb', line 30 def formatted_error(testname, err) return err unless errors.key?(testname) "#{errors[testname]}|#{err}" end |
#report_error(err) ⇒ Object
44 45 46 |
# File 'lib/emendate/examples/testable_example.rb', line 44 def report_error(err) puts err.map { |line| " #{line}" } end |
#report_failure ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/emendate/examples/testable_example.rb', line 48 def report_failure puts "string: #{test_string} -- opts: #{}" errors.each do |test, err| puts " test: #{test}" report_error(err) end end |
#run_tests(tests: nil, fail_fast: false, mode: :normal) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/emendate/examples/testable_example.rb', line 56 def run_tests(tests: nil, fail_fast: false, mode: :normal) reset_test_data unless test_results.empty? puts "Testing: #{fingerprint}" if mode == :verbose return unless testable? to_run = tests ? tests.intersection(runnable_tests) : runnable_tests testers = to_run.map do |test| Examples::Tester.build(test: test, example: self) end testers.each do |test| test.call break if fail_fast && !errors[test.name.to_sym].nil? end end |
#runnable_tests ⇒ Object
71 72 73 |
# File 'lib/emendate/examples/testable_example.rb', line 71 def runnable_tests @runnable_tests ||= determine_runnable_tests end |
#tags(type) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/emendate/examples/testable_example.rb', line 76 def (type) meth = :"tags_#{type}" rows.map { |row| row.send(meth) } .compact .map { || .split(";") } .flatten .uniq .sort .reject { |val| val.blank? } .map { |val| "#{val} (#{meth})" } end |
#test_status ⇒ Object
88 89 90 91 92 |
# File 'lib/emendate/examples/testable_example.rb', line 88 def test_status return :no_tests_run if test_results.empty? test_results.values.any?(:failure) ? :failure : :success end |
#testable? ⇒ Boolean
94 95 96 |
# File 'lib/emendate/examples/testable_example.rb', line 94 def testable? @processed ? true : check_testable end |
#to_s ⇒ Object Also known as: inspect
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/emendate/examples/testable_example.rb', line 98 def to_s <<~OBJ #<#{self.class.name}:#{object_id} @fingerprint: "#{fingerprint}", @rows: #{rows.length}, @runnable_tests: #{runnable_tests.inspect}, @processed: #{processed.class.name}, @test_results: #{test_results.inspect}, @errors: #{errors.inspect}> OBJ end |
#type_pattern(date_only: false, stage: :tokens) ⇒ Object
111 112 113 114 115 116 |
# File 'lib/emendate/examples/testable_example.rb', line 111 def type_pattern(date_only: false, stage: :tokens) return [:date_string_not_processed] unless testable? return processed.send(stage).date_part_types if date_only processed.send(stage).types end |