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



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

def all_pass_result_summary_msg
  if result_count < 1
    "uhh..."
  elsif result_count == 1
    "pass"
  else
    "all pass"
  end
end

#captured_output(output) ⇒ Object

show any captured output



29
30
31
32
33
# File 'lib/assert/view_helpers.rb', line 29

def captured_output(output)
  "--- stdout ---\n"\
  "#{output}"\
  "--------------"
end

#re_run_test_cmd(test_id) ⇒ Object

show any captured output



36
37
38
# File 'lib/assert/view_helpers.rb', line 36

def re_run_test_cmd(test_id)
  "assert -t #{test_id.gsub(Dir.pwd, ".")}"
end

#result_count_statementObject



44
45
46
# File 'lib/assert/view_helpers.rb', line 44

def result_count_statement
  "#{result_count} result#{"s" if result_count != 1}"
end

#result_summary_msg(result_type) ⇒ Object

print a result summary message for a given result type



69
70
71
72
73
74
75
# File 'lib/assert/view_helpers.rb', line 69

def result_summary_msg(result_type)
  if result_type == :pass && all_pass?
    all_pass_result_summary_msg
  else
    "#{send("#{result_type}_result_count")} #{result_type}"
  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.



80
81
82
83
84
85
86
87
# File 'lib/assert/view_helpers.rb', line 80

def results_summary_sentence
  summaries =
    ocurring_result_types.map do |result_type|
      summary_msg = result_summary_msg(result_type)
      block_given? ? yield(summary_msg, result_type) : summary_msg
    end
  to_sentence(summaries)
end

#tests_to_run_count_statementObject



40
41
42
# File 'lib/assert/view_helpers.rb', line 40

def tests_to_run_count_statement
  "#{tests_to_run_count} test#{"s" if tests_to_run_count != 1}"
end

#to_sentence(items) ⇒ Object

generate a comma-seperated sentence fragment given a list of items



49
50
51
52
53
54
55
# File 'lib/assert/view_helpers.rb', line 49

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