Permalink
Browse files

Merge pull request #6 from kelredd/result_stmt

cleanups to views, Closes #5
  • Loading branch information...
2 parents 651eb71 + 0961c46 commit 201bb9b2921ac5f62a5cd98acdee87cb97579ccc @kellyredding committed Sep 19, 2011
View
@@ -51,11 +51,11 @@ class Base
include Assert::Options
options do
- default_passed_abbrev '.'
- default_failed_abbrev 'F'
- default_ignored_abbrev 'I'
- default_skipped_abbrev 'S'
- default_errored_abbrev 'E'
+ default_pass_abbrev '.'
+ default_fail_abbrev 'F'
+ default_ignore_abbrev 'I'
+ default_skip_abbrev 'S'
+ default_error_abbrev 'E'
end
# the Renderer defines the hooks and callbacks needed for the runner to
@@ -116,7 +116,7 @@ def tests?
end
def all_passed?
- self.count(:passed) == self.count(:results)
+ self.count(:pass) == self.count(:results)
end
# get all the results that have details to show
@@ -136,8 +136,8 @@ def detailed_results(test=nil)
# only show result details for failed or errored results
# show result details if a skip or passed result was issues w/ a message
def show_result_details?(result)
- ([:failed, :errored].include?(result.to_sym)) ||
- ([:skipped, :ignored].include?(result.to_sym) && result.message)
+ ([:fail, :error].include?(result.to_sym)) ||
+ ([:skip, :ignore].include?(result.to_sym) && result.message)
end
def capture_output_start_msg
@@ -150,13 +150,13 @@ def capture_output_end_msg
# return a list of result symbols that have actually occurred
def ocurring_result_types
@result_types ||= [
- :passed, :failed, :ignored, :skipped, :errored
+ :pass, :fail, :ignore, :skip, :error
].select { |result_sym| self.count(result_sym) > 0 }
end
# print a result summary message for a given result type
def result_summary_msg(result_type)
- if result_type == :passed && self.all_passed?
+ if result_type == :pass && self.all_passed?
self.all_passed_result_summary_msg
else
"#{self.count(result_type)} #{result_type.to_s}"
@@ -12,26 +12,24 @@ class DefaultView < Base
helper Helpers::AnsiStyles
options do
- styled true
- passed_styles :green
- failed_styles :red, :bold
- errored_styles :yellow, :bold
- skipped_styles :cyan
- ignored_styles :magenta
+ styled true
+ pass_styles :green
+ fail_styles :red, :bold
+ error_styles :yellow, :bold
+ skip_styles :cyan
+ ignore_styles :magenta
end
template do
- __
__ view.loaded_tests_statement
if view.tests?
__ view.running_tests_statement
- view.run_tests(runner) do |each_result|
- result_sym = each_result.to_sym
- result_abbrev = view.options.send("#{result_sym}_abbrev")
- __ ansi_styled_msg(result_abbrev, result_ansi_styles(result_sym)), false
+ view.run_tests(runner) do |result|
+ result_abbrev = view.options.send("#{result.to_sym}_abbrev")
+ __ ansi_styled_msg(result_abbrev, result_ansi_styles(result)), false
end
__ "\n" # add a newline after streamed runner output
@@ -43,34 +41,37 @@ class DefaultView < Base
end
- # build a summary sentence w/ styled results breakdown
- styled_results_breakdown_statement = view.results_breakdown_statement do |msg, result_type|
- ansi_styled_msg(msg, result_ansi_styles(result_type))
- end
-
- __ [ view.result_count_statement, ": ", styled_results_breakdown_statement ].join('')
+ __ [ view.result_count_statement, ": ",
+ (view.results_breakdown_statement do |msg, result_sym|
+ ansi_styled_msg(msg, result_ansi_styles(result_sym))
+ end)
+ ].join('')
__
__ view.run_time_statement
end
def loaded_tests_statement
- "Loaded suite (#{view.count(:tests)} test#{'s' if view.count(:tests) != 1})"
+ "Loaded suite (#{self.test_count_statement})"
+ end
+
+ def test_count_statement
+ "#{self.count(:tests)} test#{'s' if self.count(:tests) != 1}"
end
def running_tests_statement
- "Running tests in random order, seeded with: \"#{self.runner_seed}\""
+ "Running tests in random order, seeded with \"#{self.runner_seed}\""
end
# generate a sentence fragment describing the breakdown of test results
# if a block is given, yield each msg in the breakdown for custom template formatting
def results_breakdown_statement
- self.to_sentence(self.ocurring_result_types.collect do |result_type|
- yield(self.result_summary_msg(result_type), result_type) if block_given?
+ self.to_sentence(self.ocurring_result_types.collect do |result_sym|
+ yield(self.result_summary_msg(result_sym), result_sym) if block_given?
end)
end
def result_count_statement
- "#{self.count(:results)} test result#{'s' if self.count(:results) != 1}"
+ "#{self.count(:results)} result#{'s' if self.count(:results) != 1}"
end
def run_time_statement
@@ -7,7 +7,6 @@ module Assert::View
class RedgreenView < TestUnitView
helper Helpers::CaptureOutput
- helper Helpers::TestUnit
helper Helpers::AnsiStyles
options do
@@ -1,14 +1,12 @@
require 'assert/view/base'
require 'assert/view/helpers/capture_output'
-require 'assert/view/helpers/test_unit'
module Assert::View
# this view renders in test/unit style
class TestUnitView < Base
helper Helpers::CaptureOutput
- helper Helpers::TestUnit
template do
__ view.loaded_suite_statement
View
@@ -44,11 +44,11 @@ class BaseOptionsTest < Assert::Context
end
should "default its result abbreviations" do
- assert_equal '.', subject.default_passed_abbrev
- assert_equal 'F', subject.default_failed_abbrev
- assert_equal 'I', subject.default_ignored_abbrev
- assert_equal 'S', subject.default_skipped_abbrev
- assert_equal 'E', subject.default_errored_abbrev
+ assert_equal '.', subject.default_pass_abbrev
+ assert_equal 'F', subject.default_fail_abbrev
+ assert_equal 'I', subject.default_ignore_abbrev
+ assert_equal 'S', subject.default_skip_abbrev
+ assert_equal 'E', subject.default_error_abbrev
end
end

0 comments on commit 201bb9b

Please sign in to comment.