Module: Assert::ViewHelpers::InstanceMethods

Defined in:
lib/assert/view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#all_pass_result_summary_msgObject

generate an appropriate result summary msg for all tests passing



103
104
105
106
107
108
109
110
111
# File 'lib/assert/view_helpers.rb', line 103

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



79
80
81
82
83
# File 'lib/assert/view_helpers.rb', line 79

def captured_output(output)
  "--- stdout ---\n"\
  "#{output}"\
  "--------------"
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



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/assert/view_helpers.rb', line 56

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

#result_count_statementObject



89
90
91
# File 'lib/assert/view_helpers.rb', line 89

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



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/assert/view_helpers.rb', line 42

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_summary_msg(result_type) ⇒ Object

print a result summary message for a given result type



114
115
116
117
118
119
120
# File 'lib/assert/view_helpers.rb', line 114

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_sentenceObject

generate a sentence fragment describing the breakdown of test results if a block is given, yield each msg in the breakdown for custom formatting



124
125
126
127
128
129
130
# File 'lib/assert/view_helpers.rb', line 124

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

#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

Returns:

  • (Boolean)


73
74
75
76
# File 'lib/assert/view_helpers.rb', line 73

def show_result_details?(result)
  [:fail, :error].include?(result.to_sym) ||
  !!([:skip, :ignore].include?(result.to_sym) && result.message)
end

#test_count_statementObject



85
86
87
# File 'lib/assert/view_helpers.rb', line 85

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



94
95
96
97
98
99
100
# File 'lib/assert/view_helpers.rb', line 94

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