Module: Assert::View::Helpers::Common
- Included in:
- Base
- Defined in:
- lib/assert/view/helpers/common.rb
Defined Under Namespace
Modules: ClassMethods Classes: ResultDetails
Class Method Summary collapse
Instance Method Summary collapse
- #all_pass? ⇒ Boolean
-
#all_pass_result_summary_msg ⇒ Object
generate an appropriate result summary msg for all tests passing.
-
#captured_output(output) ⇒ Object
show any captured output.
- #count(type) ⇒ Object
-
#matched_result_details_for(match, tests, result_order = :normal) ⇒ Object
get all the result details for a set of tests matching a file or context.
-
#ocurring_result_types ⇒ Object
return a list of result symbols that have actually occurred.
- #ordered_profile_tests ⇒ Object
- #ordered_suite_contexts ⇒ Object
- #ordered_suite_files ⇒ Object
- #result_count_statement ⇒ Object
-
#result_details_for(tests, result_order = :normal) ⇒ Object
get all the result details for a set of tests.
-
#result_rate(format = '%.6f') ⇒ Object
get the formatted suite result rate.
-
#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.
-
#run_time(format = '%.6f') ⇒ Object
get the formatted suite run time.
- #runner_seed ⇒ Object
-
#show_result_details?(result) ⇒ Boolean
only show result details for failed or errored results show result details if a skip or passed result was issues w/ a message.
- #show_test_profile_info? ⇒ Boolean
- #show_test_verbose_info? ⇒ Boolean
-
#suite_contexts ⇒ Object
get a uniq list of contexts for the test suite.
-
#suite_files ⇒ Object
get a uniq list of files containing contexts for the test suite.
- #test_count_statement ⇒ Object
-
#test_rate(format = '%.6f') ⇒ Object
get the formatted suite test rate.
-
#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.
- #tests? ⇒ Boolean
-
#to_sentence(things) ⇒ Object
generate a comma-seperated sentence fragment given a list of things.
Class Method Details
.included(receiver) ⇒ Object
5 6 7 |
# File 'lib/assert/view/helpers/common.rb', line 5 def self.included(receiver) receiver.class_eval{ extend ClassMethods } end |
Instance Method Details
#all_pass? ⇒ Boolean
21 22 23 |
# File 'lib/assert/view/helpers/common.rb', line 21 def all_pass? self.count(:pass) == self.count(:results) end |
#all_pass_result_summary_msg ⇒ Object
generate an appropriate result summary msg for all tests passing
145 146 147 148 149 150 151 152 153 |
# File 'lib/assert/view/helpers/common.rb', line 145 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
122 123 124 125 126 |
# File 'lib/assert/view/helpers/common.rb', line 122 def captured_output(output) "--- stdout ---\n"\ "#{output}"\ "--------------" end |
#count(type) ⇒ Object
13 14 15 |
# File 'lib/assert/view/helpers/common.rb', line 13 def count(type) self.suite.count(type) end |
#matched_result_details_for(match, tests, result_order = :normal) ⇒ Object
get all the result details for a set of tests matching a file or context
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/assert/view/helpers/common.rb', line 99 def matched_result_details_for(match, tests, result_order = :normal) context_match = match.kind_of?(Class) && match.ancestors.include?(Assert::Context) file_match = match.kind_of?(String) matching_tests = if context_match tests.select {|test| test.context_info.klass == match} elsif file_match tests.select {|test| test.context_info.file == match} else tests end result_details_for(matching_tests, result_order) end |
#ocurring_result_types ⇒ Object
return a list of result symbols that have actually occurred
129 130 131 132 133 |
# File 'lib/assert/view/helpers/common.rb', line 129 def ocurring_result_types @result_types ||= [ :pass, :fail, :ignore, :skip, :error ].select { |result_sym| self.count(result_sym) > 0 } end |
#ordered_profile_tests ⇒ Object
72 73 74 |
# File 'lib/assert/view/helpers/common.rb', line 72 def ordered_profile_tests suite.ordered_tests.sort{ |a, b| a.run_time <=> b.run_time } end |
#ordered_suite_contexts ⇒ Object
57 58 59 |
# File 'lib/assert/view/helpers/common.rb', line 57 def ordered_suite_contexts self.suite_contexts.sort{|a,b| a.to_s <=> b.to_s} end |
#ordered_suite_files ⇒ Object
68 69 70 |
# File 'lib/assert/view/helpers/common.rb', line 68 def ordered_suite_files self.suite_files.sort{|a,b| a.to_s <=> b.to_s} end |
#result_count_statement ⇒ Object
169 170 171 |
# File 'lib/assert/view/helpers/common.rb', line 169 def result_count_statement "#{self.count(:results)} result#{'s' if self.count(:results) != 1}" end |
#result_details_for(tests, result_order = :normal) ⇒ Object
get all the result details for a set of tests
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/assert/view/helpers/common.rb', line 85 def result_details_for(tests, result_order = :normal) test_index = 0 tests.collect do |test| test_index += 1 details = test.results.collect do |result| ResultDetails.new(result, test, test_index) end details.reverse! if result_order == :reversed details end.compact.flatten end |
#result_rate(format = '%.6f') ⇒ Object
get the formatted suite result rate
36 37 38 |
# File 'lib/assert/view/helpers/common.rb', line 36 def result_rate(format = '%.6f') format % self.suite.result_rate end |
#result_summary_msg(result_type) ⇒ Object
print a result summary message for a given result type
136 137 138 139 140 141 142 |
# File 'lib/assert/view/helpers/common.rb', line 136 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
157 158 159 160 161 162 163 |
# File 'lib/assert/view/helpers/common.rb', line 157 def results_summary_sentence summaries = self.ocurring_result_types.collect 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 |
#run_time(format = '%.6f') ⇒ Object
get the formatted suite run time
26 27 28 |
# File 'lib/assert/view/helpers/common.rb', line 26 def run_time(format = '%.6f') format % self.suite.run_time end |
#runner_seed ⇒ Object
9 10 11 |
# File 'lib/assert/view/helpers/common.rb', line 9 def runner_seed self.config.runner_seed end |
#show_result_details?(result) ⇒ Boolean
only show result details for failed or errored results show result details if a skip or passed result was issues w/ a message
116 117 118 119 |
# File 'lib/assert/view/helpers/common.rb', line 116 def show_result_details?(result) ([:fail, :error].include?(result.to_sym)) || ([:skip, :ignore].include?(result.to_sym) && result.) end |
#show_test_profile_info? ⇒ Boolean
76 77 78 |
# File 'lib/assert/view/helpers/common.rb', line 76 def show_test_profile_info? !!config.profile end |
#show_test_verbose_info? ⇒ Boolean
80 81 82 |
# File 'lib/assert/view/helpers/common.rb', line 80 def show_test_verbose_info? !!config.verbose end |
#suite_contexts ⇒ Object
get a uniq list of contexts for the test suite
51 52 53 54 55 |
# File 'lib/assert/view/helpers/common.rb', line 51 def suite_contexts @suite_contexts ||= self.suite.tests.inject([]) do |contexts, test| contexts << test.context_info.klass end.uniq end |
#suite_files ⇒ Object
get a uniq list of files containing contexts for the test suite
62 63 64 65 66 |
# File 'lib/assert/view/helpers/common.rb', line 62 def suite_files @suite_files ||= self.suite.tests.inject([]) do |files, test| files << test.context_info.file end.uniq end |
#test_count_statement ⇒ Object
165 166 167 |
# File 'lib/assert/view/helpers/common.rb', line 165 def test_count_statement "#{self.count(:tests)} test#{'s' if self.count(:tests) != 1}" end |
#test_rate(format = '%.6f') ⇒ Object
get the formatted suite test rate
31 32 33 |
# File 'lib/assert/view/helpers/common.rb', line 31 def test_rate(format = '%.6f') format % self.suite.test_rate end |
#test_result_rate(test, format = '%.6f') ⇒ Object
get the formatted result rate for an individual test
46 47 48 |
# File 'lib/assert/view/helpers/common.rb', line 46 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
41 42 43 |
# File 'lib/assert/view/helpers/common.rb', line 41 def test_run_time(test, format = '%.6f') format % test.run_time end |
#tests? ⇒ Boolean
17 18 19 |
# File 'lib/assert/view/helpers/common.rb', line 17 def tests? self.count(:tests) > 0 end |
#to_sentence(things) ⇒ Object
generate a comma-seperated sentence fragment given a list of things
174 175 176 177 178 179 180 |
# File 'lib/assert/view/helpers/common.rb', line 174 def to_sentence(things) if things.size <= 2 things.join(things.size == 2 ? ' and ' : '') else [things[0..-2].join(", "), things.last].join(", and ") end end |