test/unit/view_helpers_tests.rb in assert-2.15.0 vs test/unit/view_helpers_tests.rb in assert-2.15.1
- old
+ new
@@ -1,11 +1,13 @@
require 'assert'
require 'assert/view_helpers'
+require 'stringio'
require 'assert/config'
require 'assert/config_helpers'
require 'assert/result'
+require 'assert/view'
module Assert::ViewHelpers
class UnitTests < Assert::Context
desc "Assert::ViewHelpers"
@@ -17,11 +19,11 @@
option 'test_opt', test_opt_val
def config
# use the assert config since it has tests, contexts, etc
# also maybe use a fresh config that is empty
- @config ||= [Assert.config, Assert::Config.new].choice
+ @config ||= [Assert.config, Assert::Config.new].sample
end
end
end
subject{ @helpers_class }
@@ -52,12 +54,11 @@
@helpers = @helpers_class.new
end
subject{ @helpers }
should have_imeths :test_run_time, :test_result_rate
- should have_imeths :result_details_for, :matched_result_details_for
- should have_imeths :show_result_details?, :captured_output
+ should have_imeths :captured_output, :re_run_test_cmd
should have_imeths :test_count_statement, :result_count_statement
should have_imeths :to_sentence
should have_imeths :all_pass_result_summary_msg, :result_summary_msg
should have_imeths :results_summary_sentence
@@ -72,37 +73,24 @@
exp = format % test.result_rate
assert_equal exp, subject.test_result_rate(test, format)
assert_equal exp, subject.test_result_rate(test)
end
- # note: not formally testing the result details for methods as the views
- # will break if these are broken.
-
- should "know whether to show result details" do
- assert_false subject.show_result_details?(Factory.pass_result)
-
- assert_true subject.show_result_details?(Factory.fail_result)
- assert_true subject.show_result_details?(Factory.error_result)
-
- skip_res, ignore_res = Factory.skip_result, Factory.ignore_result
- assert_true subject.show_result_details?(skip_res)
- assert_true subject.show_result_details?(ignore_res)
-
- Assert.stub(skip_res, :message){ nil}
- Assert.stub(ignore_res, :message){ nil}
- assert_false subject.show_result_details?(skip_res)
- assert_false subject.show_result_details?(ignore_res)
- end
-
should "know how to build captured output" do
output = Factory.string
exp = "--- stdout ---\n"\
"#{output}"\
"--------------"
assert_equal exp, subject.captured_output(output)
end
+ should "know how to build the re-run test cmd" do
+ test_id = "#{Dir.pwd}/#{Factory.string}_tests.rb:#{Factory.integer}"
+ exp = "assert -t #{test_id.gsub(Dir.pwd, '.')}"
+ assert_equal exp, subject.re_run_test_cmd(test_id)
+ end
+
should "know its test count and result count statements" do
exp = "#{subject.count(:tests)} test#{'s' if subject.count(:tests) != 1}"
assert_equal exp, subject.test_count_statement
exp = "#{subject.count(:results)} result#{'s' if subject.count(:results) != 1}"
@@ -137,11 +125,11 @@
Assert.stub(subject, :all_pass?){ true }
exp = subject.all_pass_result_summary_msg
assert_equal exp, subject.result_summary_msg(res_type)
Assert.stub(subject, :all_pass?){ false }
- res_type = [:pass, :ignore, :fail, :skip, :error].choice
+ res_type = [:pass, :ignore, :fail, :skip, :error].sample
exp = "#{subject.count(res_type)} #{res_type.to_s}"
assert_equal exp, subject.result_summary_msg(res_type)
end
should "know its results summary sentence" do
@@ -170,11 +158,11 @@
should "know its codes" do
assert_not_empty subject::CODES
end
should "map its code style names to ansi code strings" do
- styles = Factory.integer(3).times.map{ subject::CODES.keys.choice }
+ styles = Factory.integer(3).times.map{ subject::CODES.keys.sample }
exp = styles.map{ |n| "\e[#{subject::CODES[n]}m" }.join('')
assert_equal exp, subject.code_for(*styles)
styles = Factory.integer(3).times.map{ Factory.string }
assert_equal '', subject.code_for(*styles)
@@ -183,27 +171,45 @@
assert_equal '', subject.code_for(*styles)
end
end
- class ResultDetailsTests < UnitTests
- desc "ResultDetails"
+ class AnsiInitTests < UnitTests
+ desc "when mixed in on a view"
setup do
- @result = Factory.string
- @test = Factory.test
- @index = Factory.integer
-
- @details = ResultDetails.new(@result, @test, @index)
+ view_class = Class.new(Assert::View){ include Ansi }
+ @view = view_class.new(Factory.modes_off_config, StringIO.new("", "w+"))
end
- subject{ @details }
+ subject{ @view }
- should have_readers :result, :test_index, :test, :output
+ should have_imeths :ansi_styled_msg
- should "know its attrs" do
- assert_equal @result, subject.result
- assert_equal @test, subject.test
- assert_equal @index, subject.test_index
- assert_equal @test.output, subject.output
+ should "know how to build ansi styled messages" do
+ msg = Factory.string
+ result = [:pass, :fail, :error, :skip, :ignore].sample
+
+ Assert.stub(subject, :is_tty?){ false }
+ Assert.stub(subject, :styled){ false }
+ assert_equal msg, subject.ansi_styled_msg(msg, result)
+
+ Assert.stub(subject, :is_tty?){ false }
+ Assert.stub(subject, :styled){ true }
+ assert_equal msg, subject.ansi_styled_msg(msg, result)
+
+ Assert.stub(subject, :is_tty?){ true }
+ Assert.stub(subject, :styled){ false }
+ assert_equal msg, subject.ansi_styled_msg(msg, result)
+
+ Assert.stub(subject, :is_tty?){ true }
+ Assert.stub(subject, :styled){ true }
+ Assert.stub(subject, "#{result}_styles"){ [] }
+ assert_equal msg, subject.ansi_styled_msg(msg, result)
+
+ styles = Factory.integer(3).times.map{ Assert::ViewHelpers::Ansi::CODES.keys.sample }
+ Assert.stub(subject, "#{result}_styles"){ styles }
+ exp_code = Assert::ViewHelpers::Ansi.code_for(*styles)
+ exp = exp_code + msg + Assert::ViewHelpers::Ansi.code_for(:reset)
+ assert_equal exp, subject.ansi_styled_msg(msg, result)
end
end
end