Debian Codegraph @

test/unit/minitest/spec_reporter_test.rb

raw
1 require_relative "../../test_helper"
2
3 module MinitestReportersTest
4 class SpecReporterTest < Minitest::Test
5 def setup
6 @reporter = Minitest::Reporters::SpecReporter.new
7 @test = Minitest::Test.new("")
8 @test.time = 0
9 end
10
11 def test_removes_underscore_in_name_if_shoulda
12 @test.name = "test_: Should foo"
13 assert_output(/test:/) do
14 @reporter.io = $stdout
15 @reporter.record(@test)
16 end
17 end
18
19 def test_wont_modify_name_if_not_shoulda
20 @test.name = "test_foo"
21 assert_output(/test_foo/) do
22 @reporter.io = $stdout
23 @reporter.record(@test)
24 end
25 end
26
27 def test_responds_to_test_name_after_record
28 test_name = 'test_: Should foo'
29 the_test_class = Class.new(Minitest::Test) do
30 define_method test_name do
31 assert(false)
32 end
33 end
34 the_test = the_test_class.new('')
35 the_test.name = test_name
36 @reporter.io = StringIO.new
37 @reporter.record(the_test)
38 assert_respond_to the_test, the_test.name
39 end
40
41 def test_report_for_describe_not_using_const
42 klass = describe("whatever") { it("passes") { assert true } }
43 runnable = klass.runnable_methods.first
44 @reporter.io = StringIO.new
45
46 # Run the test
47 result = klass.new(runnable).run
48 @reporter.start
49 @reporter.record(result)
50
51 error_msg = nil
52 begin
53 @reporter.report
54 rescue => e
55 error_msg = "error executing @reporter.report, #{e}"
56 end
57
58 refute error_msg, error_msg
59 end
60 end
61 end
62