Add test for the reporter

Test that the output generated by the reporter contains the
expected failed examples, flaky tests etc and in the right format.
This commit is contained in:
John Fragoulis 2021-03-19 12:53:57 +02:00
parent efbf5dc899
commit b6a46222c5
2 changed files with 54 additions and 2 deletions

View File

@ -20,9 +20,16 @@ module TestHelpers
w
end
def exec_build(path, args = "")
# Executes an rspecq worker.
# @param [String] path The name of the test suite
# @param [String] args Extra rspeq arguments
# @param [String] :build_id By default build_id is generated by the method.
# Alternatively you can pass the build_id in case you need to share it
# with the reporter.
# @return [RSpecQ::Queue]
def exec_build(path, args = "", build_id: nil)
worker_id = rand_id
build_id = rand_id
build_id ||= rand_id
Dir.chdir(suite_path(path)) do
out = `#{EXEC_CMD} --worker #{worker_id} --build #{build_id} #{args}`
@ -37,6 +44,15 @@ module TestHelpers
queue
end
# Executes an rspecq reporter.
# @param [String] :build_id By default build_id is generated by the method.
# @return [String] The reporter's output.
def exec_reporter(build_id:)
out = `#{EXEC_CMD} --report --build #{build_id}`
puts out if ENV["RSPECQ_DEBUG"]
out
end
def suite_path(path)
File.join("test", "sample_suites", path)
end

36
test/test_reporter.rb Normal file
View File

@ -0,0 +1,36 @@
require "test_helpers"
class TestReporter < RSpecQTest
def test_passing_suite
build_id = rand_id
exec_build("passing_suite", "", build_id: build_id)
output = exec_reporter(build_id: build_id)
assert_match "Total results", output
assert_match "1 examples (1 jobs)", output
assert_match "0 failures", output
assert_match "execution time", output
refute_match "Failed examples", output
refute_match "Flaky", output
end
def test_failing_suite
build_id = rand_id
exec_build("failing_suite", "", build_id: build_id)
output = exec_reporter(build_id: build_id)
assert_match "Failed examples", output
assert_match "bin/rspec ./spec/fail_1_spec.rb:3", output
refute_match "Flaky", output
end
def test_flakey_suite
build_id = rand_id
exec_build("flakey_suite", "", build_id: build_id)
output = exec_reporter(build_id: build_id)
assert_match "Flaky jobs detected", output
assert_match "./spec/foo_spec.rb[1:1]", output
refute_match "Failed examples", output
end
end