Module: Assert::ViewHelpers::InstanceMethods
- Defined in:
- lib/assert/view_helpers.rb
Instance Method Summary collapse
-
#all_pass_result_summary_msg ⇒ Object
generate an appropriate result summary msg for all tests passing.
-
#captured_output(output) ⇒ Object
show any captured output.
-
#re_run_test_cmd(test_id) ⇒ Object
show any captured output.
- #result_count_statement ⇒ Object
-
#result_summary_msg(result_type) ⇒ Object
print a result summary message for a given result type.
-
#results_summary_sentence ⇒ Object
generate a sentence fragment describing the breakdown of test results if a block is given, yield each msg in the breakdown for custom formatting.
- #test_count_statement ⇒ Object
-
#test_result_rate(test, format = '%.6f') ⇒ Object
get the formatted result rate for an individual test.
-
#test_run_time(test, format = '%.6f') ⇒ Object
get the formatted run time for an idividual test.
-
#to_sentence(items) ⇒ Object
generate a comma-seperated sentence fragment given a list of items.
Instance Method Details
#all_pass_result_summary_msg ⇒ Object
generate an appropriate result summary msg for all tests passing
71 72 73 74 75 76 77 78 79 |
# File 'lib/assert/view_helpers.rb', line 71 def all_pass_result_summary_msg if self.count(:results) < 1 "uhh..." elsif self.count(:results) == 1 "pass" else "all pass" end end |
#captured_output(output) ⇒ Object
show any captured output
42 43 44 45 46 |
# File 'lib/assert/view_helpers.rb', line 42 def captured_output(output) "--- stdout ---\n"\ "#{output}"\ "--------------" end |
#re_run_test_cmd(test_id) ⇒ Object
show any captured output
49 50 51 |
# File 'lib/assert/view_helpers.rb', line 49 def re_run_test_cmd(test_id) "assert -t #{test_id.gsub(Dir.pwd, '.')}" end |
#result_count_statement ⇒ Object
57 58 59 |
# File 'lib/assert/view_helpers.rb', line 57 def result_count_statement "#{self.count(:results)} result#{'s' if self.count(:results) != 1}" end |
#result_summary_msg(result_type) ⇒ Object
print a result summary message for a given result type
82 83 84 85 86 87 88 |
# File 'lib/assert/view_helpers.rb', line 82 def result_summary_msg(result_type) if result_type == :pass && self.all_pass? self.all_pass_result_summary_msg else "#{self.count(result_type)} #{result_type.to_s}" end end |
#results_summary_sentence ⇒ Object
generate a sentence fragment describing the breakdown of test results if a block is given, yield each msg in the breakdown for custom formatting
92 93 94 95 96 97 98 |
# File 'lib/assert/view_helpers.rb', line 92 def results_summary_sentence summaries = self.ocurring_result_types.map do |result_sym| summary_msg = self.result_summary_msg(result_sym) block_given? ? yield(summary_msg, result_sym) : summary_msg end self.to_sentence(summaries) end |
#test_count_statement ⇒ Object
53 54 55 |
# File 'lib/assert/view_helpers.rb', line 53 def test_count_statement "#{self.count(:tests)} test#{'s' if self.count(:tests) != 1}" end |
#test_result_rate(test, format = '%.6f') ⇒ Object
get the formatted result rate for an individual test
37 38 39 |
# File 'lib/assert/view_helpers.rb', line 37 def test_result_rate(test, format = '%.6f') format % test.result_rate end |
#test_run_time(test, format = '%.6f') ⇒ Object
get the formatted run time for an idividual test
32 33 34 |
# File 'lib/assert/view_helpers.rb', line 32 def test_run_time(test, format = '%.6f') format % test.run_time end |
#to_sentence(items) ⇒ Object
generate a comma-seperated sentence fragment given a list of items
62 63 64 65 66 67 68 |
# File 'lib/assert/view_helpers.rb', line 62 def to_sentence(items) if items.size <= 2 items.join(items.size == 2 ? ' and ' : '') else [items[0..-2].join(", "), items.last].join(", and ") end end |